public function checkMandatoryFields() { foreach ($this->getModule()->getFields() as $field) { $value = $this->getValue($field->getName()); $is_mandatory = $field->getOption('mandatory') == true; if ($is_mandatory && (empty($value) || $value instanceof Countable && $value->count() === 0)) { $error = new MandatoryValueMissingException(); $error->setFieldName($field->getName()); $error->setModuleName($this->module->getName()); throw $error; } if ($field instanceof AggregateField) { foreach ($this->getValue($field->getName()) as $aggregate) { $aggregate->checkMandatoryFields(); } } } }