Composer View does not validate
Permalink
The block controller function of validate does not seem to run when composer view is saved.
How can we then validate a blocks data when saved from composer view????
How can we then validate a blocks data when saved from composer view????
Since validate_composer does not take any parameters, you must get the data needing to be verified another way:
So I have a function that returns all of the data current in the form, then I loop over it for errors:
So I have a function that returns all of the data current in the form, then I loop over it for errors:
public function validate_composer() { $e = Core::make("helper/validation/error"); $items = $this->getEntries(); foreach ($items as $item) { $count = $i + 1; if(!$item['title']) { $e->add(t('You must add something to item %s',$count)); } } return $e; }
I think CoreConversationMessage\Controller cheats a bit. It defines an overloaded validate_composer($data), whereas the standard BlockController doesn't have the parameter.
I know, but how in the world does it do that? When I try to pass an argument it throws an error....
I ended up finding a workaround I explain above. I guess a block FIRST saves itself, then it validates itself, and won't close if the data didn't validate.
So you can get the data saved to the database in the validate_composer view and loop over them for errors.
I ended up finding a workaround I explain above. I guess a block FIRST saves itself, then it validates itself, and won't close if the data didn't validate.
So you can get the data saved to the database in the validate_composer view and loop over them for errors.
But it doesn't recognize data being posted like validate does. What I mean is I can't pass $data to it like I can with validate($data)
It seems the core_conversation_message block passes $data to the validate_composer method, but I when I do so it says $data is empty.