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????

ob7dev
 
ob7dev replied on at Permalink Reply
ob7dev
I found theres the validate_composer method.

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.
ob7dev replied on at Permalink Best Answer Reply
ob7dev
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:
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;
    }
Gondwana replied on at Permalink Reply
Gondwana
I think CoreConversationMessage\Controller cheats a bit. It defines an overloaded validate_composer($data), whereas the standard BlockController doesn't have the parameter.
ob7dev replied on at Permalink Reply
ob7dev
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.