Example #1
0
 /**
  * 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());
         }
     }
 }
Example #2
0
 /**
  * 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());
         }
     }
 }