/**
  * Instantiate an Input object for the supplied field call setAllowEmpty()
  * depending upon whether the field is required.
  *
  * @param Field $field
  * @return Input
  */
 protected function instantiateInput(Field $field)
 {
     $input = new Input($field->getControlName());
     if ($field->isRequired() && !$field->isType('boolean')) {
         $input->setAllowEmpty(false);
     } else {
         $input->setAllowEmpty(true);
     }
     return $input;
 }
 public function __invoke(Field $field)
 {
     if (!$field->isType('reference')) {
         throw new Exception('The FilterReferenceAsText template can only be used on DB reference fields.');
     }
     $reference = $field->getOptionPairsReference();
     $titleColumn = $field->getOptionPairs()->detectTitleColumn();
     $field->assignHelperCallback('SelectFilter.FilterType', function () {
         return ['type' => 'text', 'options' => []];
     })->assignHelperCallback('SelectFilter.SelectModifier', function ($helper, Select $select, $conditionSetName, $queryVars) use($reference, $titleColumn) {
         $filter = new TextFilter($reference['table'], $titleColumn);
         return $filter->apply($select, $conditionSetName, $queryVars);
     });
 }
示例#3
0
 /**
  * Open the edit row using a \Dewdrop\Db\Field object to determine the
  * label text and the value of the "for" attribute on the label tag.
  *
  * @param Field $field
  * @return string
  */
 protected function openField(Field $field)
 {
     return $this->openArray(array('label' => $field->getLabel(), 'labelFor' => $field->getHtmlId(), 'hideLabel' => $field->isType('boolean')));
 }