/** * Add a field or a field group to the factory. * * @param FieldInterface $field The field or group to add * * @return FieldInterface The field or group that was added * * @throws \InvalidArgumentException If a field with the identifier returned * from `getName()` on the field already exists */ public function add(FieldInterface $field) { // Check if a field with this name already exists if (isset($this->_fields[$field->getName()])) { throw new \InvalidArgumentException(sprintf('A field with the name `%s` already exists on the field factory', $field->getName())); } $this->_fields[$field->getName()] = $field; return $field; }
/** * Add a field to this group. * * If the field has one of the following names and an "identifier field" * has not yet been set on this group, the field will be used as the * identifier: * * - id * - identifier * - title * - heading * * @param Field $field The field to add * * @return Group Returns $this for chainability */ public function add(FieldInterface $field) { $field->setTranslationKey($this->_translationKey . '.fields'); $this->_fields[$field->getName()] = $field; // If no identifier field is set yet and this field is a good candidate, set it if (!$this->getIdentifierField() && in_array($field->getName(), array('id', 'identifier', 'title', 'heading', 'name'))) { $this->setIdentifierField($field->getName()); } return $this; }