Description
The method isEmpty
checks the input form data. It checks for simple nullable elements, empty strings, empty arrays and empty traversables. Am i wrong? If i have an object, which consist only of empty collections, nullable fields etc., shouldn't it check such an 'empty' object and return true aswell?
Following use case: I have an embedded collection in an entity form. It's attributes have some asserts (notnull, empty, etc.). Adding and Removing with prototype works perfectly, but if i just add a new entry and enter nothing, it should delete the entry on submit with the flag delete_empty
. Actually, it does not, because modelData
is an object, therefore not empty and the standard validation errors occur.
Current isEmpty
method:
public function isEmpty()
{
foreach ($this->children as $child) {
if (!$child->isEmpty()) {
return false;
}
}
return FormUtil::isEmpty($this->modelData) ||
// arrays, countables
0 === count($this->modelData) ||
// traversables that are not countable
($this->modelData instanceof \Traversable && 0 === iterator_count($this->modelData));
}
My idea would be, to additionally check if modelData
is an object and if the object has a self made isEmpty
method. (A generic version is also possible - all getter)
(is_object($this->modelData) && method_exists($this->modelData, 'isEmpty') && call_user_func(array($this->modelData, 'isEmpty')))
Best regards,
Nino