/** * Configure an element based on the provided specification * * Specification can contain any of the following: * - type: the Element class to use; defaults to \Zend\Form\Element * - name: what name to provide the element, if any * - options: an array, Traversable, or ArrayAccess object of element options * - attributes: an array, Traversable, or ArrayAccess object of element * attributes to assign * * @param ElementInterface $element * @param array|Traversable|ArrayAccess $spec * @throws Exception\DomainException * @return ElementInterface */ public function configureElement(ElementInterface $element, $spec) { $spec = $this->validateSpecification($spec, __METHOD__); $name = isset($spec['name']) ? $spec['name'] : null; $options = isset($spec['options']) ? $spec['options'] : null; $attributes = isset($spec['attributes']) ? $spec['attributes'] : null; if ($name !== null && $name !== '') { $element->setName($name); } if (is_array($options) || $options instanceof Traversable || $options instanceof ArrayAccess) { $element->setOptions($options); } if (is_array($attributes) || $attributes instanceof Traversable || $attributes instanceof ArrayAccess) { $element->setAttributes($attributes); } return $element; }