/** * 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); } } }
/** * 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 DefaultValueInterface && $field->hasDefault()) { $this->setContent($field->getDefault()); } if ($field->getDataType() instanceof LengthBoundariesInterface) { if ($field->getDataType()->hasMaxLength()) { $this->setAttribute('maxlength', $field->getDataType()->getMaxLength()); } if ($field->getDataType()->hasMinLength()) { $this->setAttribute('minlength', $field->getDataType()->getMinLength()); } } }
/** * 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()); } if ($field instanceof DefaultValueInterface && $field->hasDefault()) { $this->setAttribute('value', $field->getDefault()); } }
/** * 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()); } } }
/** * 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() && !in_array($this->attributes['type'], array('hidden', 'image', 'submit', 'reset', 'button'))) { $this->setAttribute('required', 'required'); } if ($field instanceof DefaultValueInterface && $field->hasDefault()) { $this->setAttribute('value', $field->getDefault()); } if ($field->getDataType() instanceof LengthBoundariesInterface && in_array($this->attributes['type'], array('text', 'email', 'search', 'password', 'tel', 'url'))) { if ($field->getDataType()->hasMaxLength()) { $this->setAttribute('maxlength', $field->getDataType()->getMaxLength()); } if ($field->getDataType()->hasMinLength() && ($field->getDataType()->getMinLength() > 0 || !$field instanceof RequiredInterface || !$field->isRequired())) { $this->setAttribute('minlength', $field->getDataType()->getMinLength()); } } if ($field->getDataType() instanceof NumericBoundariesInterface && in_array($this->attributes['type'], array('number', 'range', 'date', 'datetime', 'datetime-local', 'month', 'time', 'week'))) { if ($field->getDataType()->hasMax()) { $this->setAttribute('max', $field->getDataType()->getMax()); } if ($field->getDataType()->hasMin()) { $this->setAttribute('min', $field->getDataType()->getMin()); } if ($field->getDataType()->hasStep()) { $this->setAttribute('step', $field->getDataType()->getStep()); } } }