/** * Takes information from the Field and uses it in this display * * @param DisplayDataSourceInterface $field */ public function informAboutStructure(DisplayDataSourceInterface $field) { /** * Use the Field identifier (if given) as default id-attribute for * this HTML element */ if ($field instanceof IdentifierInterface && $field->hasId()) { $this->setAttribute('id', $field->getId()); $this->setAttribute('name', $field->getId()); } if ($field instanceof RequiredInterface && $field->isRequired()) { $this->setAttribute('required', 'required'); } if ($field instanceof MultipleChoiceInterface && $field->isMultipleChoice()) { $this->setAttribute('multiple', 'multiple'); } if ($field instanceof OptionsInterface) { foreach ($field->getOptions() as $value => $label) { $newOption = new Option($label, $value); if ($field instanceof DefaultValueInterface && $field->hasDefault() && $field->getDefault() === $value) { $newOption->setDefault(); } $this->appendChild($newOption); } } }
/** * Informs the display about the structure of a Field. * * Each time the Field structure changes for some reason, this method shall * be called. * * The display changes its hint (string between square brackets []) * accordingly * * @param DisplayDataSourceInterface $field */ public function informAboutStructure(DisplayDataSourceInterface $field) { if ($field instanceof DefaultValueInterface && $field->hasDefault()) { $this->hint = $field->getDefault(); } if ($field instanceof OptionsInterface) { if ($field instanceof DefaultValueInterface && $field->hasDefault()) { $tmpOptions = array(); foreach ($field->getOptions() as $option) { if ($field->getDefault() === $option) { $tmpOptions[] = strtoupper($option); } else { $tmpOptions[] = strtolower($option); } } $this->hint = implode('/', $tmpOptions); } else { $this->hint = implode('/', $field->getOptions()); } } }