コード例 #1
0
ファイル: Select.php プロジェクト: broeser/feeld
 /**
  * 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);
         }
     }
 }
コード例 #2
0
ファイル: Textarea.php プロジェクト: broeser/feeld
 /**
  * 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());
         }
     }
 }
コード例 #3
0
ファイル: Input.php プロジェクト: broeser/feeld
 /**
  * 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());
         }
     }
 }