コード例 #1
0
 public function getFormField($form, $fieldClass = '\\Mindy\\Form\\Fields\\DropDownField', array $extra = [])
 {
     $model = $this->getModel();
     $choices = function () use($model) {
         $list = ['' => ''];
         $qs = $model->objects()->order(['root', 'lft']);
         $parents = $qs->all();
         foreach ($parents as $model) {
             $level = $model->level ? $model->level - 1 : $model->level;
             $list[$model->pk] = $level ? str_repeat("..", $level) . ' ' . $model->name : $model->name;
         }
         return $list;
     };
     if ($this->primary || $this->editable === false) {
         return null;
     }
     if ($fieldClass === null) {
         $fieldClass = $this->choices ? \Mindy\Form\Fields\DropDownField::className() : \Mindy\Form\Fields\CharField::className();
     } elseif ($fieldClass === false) {
         return null;
     }
     $validators = [];
     if ($form->hasField($this->name)) {
         $field = $form->getField($this->name);
         $validators = $field->validators;
     }
     if ($this->null === false && $this->autoFetch === false && $this instanceof BooleanField === false) {
         $validator = new RequiredValidator();
         $validator->setName($this->name);
         $validator->setModel($this);
         $validators[] = $validator;
     }
     return Creator::createObject(array_merge(['class' => $fieldClass, 'required' => $this->required || !$this->null, 'form' => $form, 'choices' => empty($this->choices) ? $choices : $this->choices, 'name' => $this->name, 'label' => $this->verboseName, 'hint' => $this->helpText, 'value' => $this->getValue(), 'validators' => array_merge($validators, $this->validators), 'disabled' => [$model->pk]], $extra));
 }
コード例 #2
0
ファイル: Field.php プロジェクト: AlexandrGordeev/Mindy_Orm
 public function getFormField($form, $fieldClass = null, array $extra = [])
 {
     if ($this->primary || $this->editable === false) {
         return null;
     }
     if ($fieldClass === null) {
         $fieldClass = $this->choices ? \Mindy\Form\Fields\DropDownField::className() : \Mindy\Form\Fields\CharField::className();
     } elseif ($fieldClass === false) {
         return null;
     }
     $validators = [];
     if ($form->hasField($this->name)) {
         $field = $form->getField($this->name);
         $validators = $field->validators;
     }
     if (($this->null === false || $this->required) && $this->autoFetch === false && $this instanceof BooleanField === false) {
         $validator = new RequiredValidator();
         $validator->setName($this->name);
         $validator->setModel($this);
         $validators[] = $validator;
     }
     if ($this->unique) {
         $validator = new UniqueValidator();
         $validator->setName($this->name);
         $validator->setModel($this);
         $validators[] = $validator;
     }
     return Creator::createObject(array_merge(['class' => $fieldClass, 'required' => !$this->canBeEmpty(), 'form' => $form, 'choices' => $this->choices, 'name' => $this->name, 'label' => $this->verboseName, 'hint' => $this->helpText, 'validators' => array_merge($validators, $this->validators), 'value' => $this->default ? $this->default : null], $extra));
 }