Ejemplo n.º 1
0
 /**
  * Detect which view helper should be used to edit the supplied
  * \Dewdrop\Db\Field.  THis is basic logic used to determine a suitable
  * helper:
  *
  * <ol>
  *     <li>
  *         If a custom helper was assigned by calling customizeField(),
  *         use that.
  *     </li>
  *     <li>
  *         If it is an EAV field, use whatever helper is assigned in the
  *         EAV definition.
  *     </li>
  *     <li>
  *         Otherwise, look at the field's type to determine which helper
  *         would be appropriate.
  *     </li>
  *     <li>
  *         If a suitable helper cannot be determined, throw an exception.
  *     </li>
  * </ol>
  *
  * @throws \Dewdrop\Exception
  * @param Field $field
  * @return string
  */
 public function detect(FieldInterface $field)
 {
     if (array_key_exists($field->getControlName(), $this->customHelpers)) {
         return $this->customHelpers[$field->getControlName()];
     } elseif ($field instanceof EavField) {
         return $field->getEditHelperName();
     } elseif ($field->isType('boolean', 'boolean')) {
         return 'inputCheckbox';
     } elseif ($field->isType('manytomany')) {
         return 'checkboxList';
     } elseif ($field->isType('reference')) {
         return 'select';
     } elseif ($field->isType('clob')) {
         return 'textarea';
     } elseif ($field->isType('text', 'integer', 'float')) {
         return 'inputText';
     } elseif ($field->isType('date')) {
         return 'inputDate';
     } elseif ($field->isType('timestamp')) {
         return 'inputTimestamp';
     }
     throw new Exception('Fields\\EditHelperDetector: Could not find a suitable view helper for field ' . $field->getControlName() . '.');
 }