Example #1
0
 /**
  * Takes information from the Field and uses it in this display
  * 
  * @param \Feeld\Display\DisplayDataSourceInterface $field
  * @throws \Wellid\Exception\NotFound
  */
 public function informAboutStructure(\Feeld\Display\DisplayDataSourceInterface $field)
 {
     if (!$field instanceof \Feeld\Field\CommonProperties\IdentifierInterface || !$field->hasId()) {
         throw new \Wellid\Exception\NotFound('id', 'fieldDisplayElement');
     }
     $this->setAttribute('for', $field->getId());
 }
Example #2
0
 /**
  * Informs the display about the structure of a Field.
  * 
  * Each time the Field structure changes for some reason, this method shall
  * be called.
  *
  * @param \Feeld\Display\DisplayDataSourceInterface $field
  * @throws Exception
  */
 public function informAboutStructure(\Feeld\Display\DisplayDataSourceInterface $field)
 {
     parent::informAboutStructure($field);
     $this->field = $field;
     if ($field instanceof \Feeld\Field\Entry) {
         $this->symfonyQuestion = new SymfonyQuestion((string) $this, $field instanceof DefaultValueInterface && $field->hasDefault() ? $field->getDefault() : null);
     } elseif ($field instanceof \Feeld\Field\Select) {
         $this->symfonyQuestion = new \Symfony\Component\Console\Question\ChoiceQuestion((string) $this, array_keys($field->getOptions()), $field instanceof DefaultValueInterface && $field->hasDefault() ? $field->getDefault() : null);
         if ($field instanceof \Feeld\Field\CommonProperties\MultipleChoiceInterface && $field->isMultipleChoice()) {
             $field->symfonyQuestion->setMultiselect(true);
         }
     } elseif ($field instanceof \Feeld\Field\CloakedEntry) {
         $this->symfonyQuestion = new SymfonyQuestion((string) $this, $field instanceof DefaultValueInterface && $field->hasDefault() ? $field->getDefault() : null);
         $this->symfonyQuestion->setHidden(true);
     } elseif ($field instanceof \Feeld\Field\Constant) {
         throw new Exception('Constants are currently not supported in SymfonyConsoleDisplay');
     } elseif ($field instanceof \Feeld\Field\Checkbox) {
         $this->symfonyQuestion = new \Symfony\Component\Console\Question\ConfirmationQuestion((string) $this, $field instanceof DefaultValueInterface && $field->hasDefault() ? $field->getDefault() : true, '/^' . strtolower(substr($this->getTrueOption(), 0, 1)) . '/i');
     }
     $this->symfonyQuestion->setNormalizer(function ($value) {
         return $this->field->getSanitizer()->filter($value);
     });
     $this->symfonyQuestion->setValidator(function ($value) {
         $validationResultSet = $this->field->validateValue($value);
         if ($validationResultSet->hasErrors()) {
             $this->field->clearValidationResult();
             throw new \Exception(implode(PHP_EOL, $validationResultSet->getErrorMessages()));
         }
         return $this->field->getFilteredValue();
     });
     $this->symfonyQuestion->setMaxAttempts(null);
 }
Example #3
0
 /**
  * Takes information from the FieldCollection and uses it in this display
  * 
  * @param \Feeld\FieldCollection\FieldCollectionInterface $field
  * @throws \Wellid\Exception\DataType
  */
 public function informAboutStructure(DisplayDataSourceInterface $field)
 {
     if (!$field instanceof \Feeld\FieldCollection\FieldCollectionInterface) {
         throw new \Wellid\Exception\DataType('field', 'FieldCollectionInterface', $field);
     }
     $this->dataSource = $field;
     if (count($field->getFieldsByDataType('Feeld\\DataType\\File')) > 0) {
         $this->setAttribute('enctype', 'multipart/form-data');
     }
 }
Example #4
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 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);
         }
     }
 }
Example #5
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());
     }
     if ($field instanceof DefaultValueInterface && $field->hasDefault()) {
         $this->setAttribute('value', $field->getDefault());
     }
 }
Example #6
0
 /**
  * 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());
         }
     }
 }
Example #7
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());
         }
     }
 }
Example #8
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());
         }
     }
 }