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));
 }
 public function getFields()
 {
     $fields = ['username' => ['class' => CharField::className(), 'label' => UserModule::t('Username'), 'required' => true, 'validators' => [function ($value) {
         if (User::objects()->filter(['username' => $value])->count() > 0) {
             return UserModule::t("Username must be a unique");
         }
         return true;
     }]], 'email' => ['class' => EmailField::className(), 'label' => UserModule::t('Email'), 'required' => true, 'validators' => [function ($value) {
         if (User::objects()->filter(['email' => $value])->count() > 0) {
             return UserModule::t("Email must be a unique");
         }
         return true;
     }]], 'password' => ['class' => PasswordField::className(), 'validators' => [new MinLengthValidator(6)], 'label' => UserModule::t('Password')], 'password_repeat' => ['class' => PasswordField::className(), 'validators' => [new MinLengthValidator(6)], 'label' => UserModule::t('Password repeat')]];
     $module = Mindy::app()->getModule('User');
     if ($module->enableRecaptcha) {
         if (empty($module->recaptchaPublicKey) && empty($module->recaptchaSecretKey)) {
             Mindy::app()->logger->warning("publicKey and secretKey isn't set in UserModule");
         } else {
             $fields['captcha'] = ['class' => RecaptchaField::className(), 'label' => Translate::getInstance()->t('validation', 'Captcha'), 'publicKey' => $module->recaptchaPublicKey, 'secretKey' => $module->recaptchaSecretKey];
         }
     }
     return $fields;
 }
Beispiel #3
0
 public function getFields()
 {
     return ['username_or_email' => ['class' => CharField::className(), 'label' => UserModule::t('Email')]];
 }
Beispiel #4
0
 public function getFields()
 {
     return ['title' => ['class' => CharField::className(), 'label' => MetaModule::t('Title')], 'description' => ['class' => TextAreaField::className(), 'label' => MetaModule::t('Description')], 'keywords' => ['class' => TextAreaField::className(), 'label' => MetaModule::t('Keywords')], 'url' => ['class' => HiddenField::className()], 'site' => ['class' => HiddenField::className(), 'value' => $this->getIsMultiSite() ? $this->getSitePk() : null]];
 }
Beispiel #5
0
 public function getFields()
 {
     return ['username' => ['class' => CharField::className(), 'label' => UserModule::t('Email or username'), 'html' => ['placeholder' => UserModule::t('Email or username')]], 'password' => ['class' => PasswordField::className(), 'label' => UserModule::t('Password'), 'html' => ['placeholder' => UserModule::t('Password')]], 'rememberMe' => ['class' => CheckboxField::className(), 'label' => UserModule::t('Remember me'), 'value' => true]];
 }
Beispiel #6
0
 public function getFields()
 {
     return ['is_custom' => ['class' => CheckboxField::className(), 'label' => MetaModule::t('Is custom')], 'title' => ['class' => CharField::className(), 'label' => MetaModule::t('Title')], 'description' => ['class' => TextAreaField::className(), 'label' => MetaModule::t('Description')], 'keywords' => ['class' => TextAreaField::className(), 'label' => MetaModule::t('Keywords')]];
 }
Beispiel #7
0
 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));
 }