/** * Fields config for backend. * * @access public * @return MConfig * @since 1.0.0 * @version 2.1.0-dev */ protected static function generateConfig() { # get all permissions list $aRoles = []; $aResult = DB::queryList('\\Model\\User\\Role')->execute(); foreach ($aResult as $oRole) { /* @var $oRole User\Role */ $aRoles[] = ['value' => $oRole->getId(), 'label' => $oRole->getName()]; } # get config from parent $config = parent::generateConfig(); # create fields $config->addField(FormField\Hidden::singleton('id')->setLabel(__('ID'))->setDisabled()); $config->addField(FormFieldPassword::singleton('password')->setLabel(__('Password'))->addRulesSet(RulesSetBuilder\String::factory()->containNumbers(':value')->containText(':value')->containUppercase(':value')->containCustomCharacters(':value'))); $config->addField(FormField\Text::singleton('login')->setLabel('Login')->addTipParagraph(__('This value can contain only letters, numbers and "-" or "_" characters.'))->setDisabled()->addRulesSet(RulesSetBuilder\String::factory()->onlyLettersNumsAndChars(':value', '\\-_', __('This value can contain only letters, numbers and "-" or "_" characters.')))->addRulesSet(RulesSetBuilder\Database::factory()->unique(':value', ':valuefrom:id', '\\Model\\User', 'login'))); $config->addField(FormField\Text::singleton('email')->setLabel('E-mail')->setDisabled()->addRulesSet(RulesSetBuilder\String::factory()->email(':value'))->addRulesSet(RulesSetBuilder\Database::factory()->unique(':value', ':valuefrom:id', '\\Model\\User', 'email'))); $config->addField(FormField\Text::singleton('firstname')->setLabel(__('Firstname'))->addRulesSet(RulesSetBuilder\String::factory()->onlyLetters(':value'))); $config->addField(FormField\Text::singleton('lastname')->setLabel(__('Lastname'))->addRulesSet(RulesSetBuilder\String::factory()->onlyLetters(':value'))); $config->addField(FormField\Text::singleton('nickname')->setLabel(__('Nickname'))); $config->addField(FormField\ImageModel::singleton('image')->setBrokerModel('\\Model\\User\\Image')->setUploadPath('uploads/users/image')->setLabel(__('Image'))->addRulesSet(RulesSetBuilder\FileModel::factory()->allowedExt(':value', ['jpg', 'png', 'gif'])->maxSize(':value', 1024))); $config->addField(FormField\Text::singleton('city')->setLabel(__('City'))->addRulesSet(RulesSetBuilder\String::factory()->onlyLetters(':value'))); $config->addField(FormField\Textarea::singleton('description')->setLabel(__('Description'))); if (\UserPermissions::hasPerm('users_edit')) { $config->addField(CheckboxRelationFormField::singleton('roles')->setRelatedModelName('\\Model\\User\\Role')->setOptions($aRoles)->setLabel(__('Roles'))); } $config->addFieldFormatter('registration_date', FieldFormatterDate::factory()); $config->addFieldFormatter('login_date', FieldFormatterDate::factory()); # return config return $config; }
/** * Add validation rules on the basis of ORM annotation mappings. * * @access private * @param Form\Field $oField * @param array $aMappings * @return bool * @since 1.0.0-alpha * @version 1.0.0-alpha */ private function addValidationByMapping(Form\Field &$oField, array $aMappings) { $iLength = Arrays::get($aMappings, 'length'); $sType = Arrays::get($aMappings, 'type'); // if there are no field mappings if (empty($aMappings) || $oField instanceof Form\Field\Hidden) { return FALSE; } // 'required' validation rule if (Arrays::get($aMappings, 'nullable', FALSE) === FALSE) { $oField->setRequired(); } // validation rules by type switch ($sType) { case 'string': if ($iLength !== NULL) { $oField->addRulesSet(RulesSetBuilder\String::factory()->max(':value', $iLength)); } break; case 'integer': if ($iLength !== NULL) { $oField->addRulesSet(RulesSetBuilder\Number::factory()->max(':value', $iLength)); } break; } return TRUE; }
/** * Fields config for backend. * * @static * @access protected * @return ModelCore\MConfig * @since 1.1.0-dev * @version 1.3.0-dev */ protected static function generateConfig() { // get config from parent $config = parent::generateConfig(); // get list of all routes $routesList = array_keys(Router::getRoutes()); $routesOptions = []; foreach ($routesList as $value) { $routesOptions[$value] = ['value' => $value, 'label' => $value]; } // BACKEND $config->addField(Form\Field\Hidden::singleton('id')->setDisabled()); $config->addField(Form\Field\Select::singleton('route')->setOptions(array_combine($routesList, $routesList))->setLabel(__('Route'))->setRequired()); $config->addField(Form\Field\Text::singleton('route_parameters')->setLabel(__('Route parameters'))->setQuantity(0)); $config->addField(Form\Field\Text::singleton('url')->setLabel('URL')); $config->addField(Form\Field\Checkbox::singleton('active_routes')->setColumnsAmount(3)->setOptions($routesOptions)->setLabel(__('Active routes'))->setTip(__('List of routes for which the actual route will be active'))); $config->addField(Form\Field\Text::singleton('classes')->setLabel(__('HTML classes'))->addRulesSet(Validator\RulesSetBuilder\String::factory()->regex(':value', '[0-9a-z_-]*'))); // return config return $config; }
/** * Fields config for backend. * * @access public * @return ModelCore\MConfig * @since 1.1.0-dev * @version 1.3.0-dev */ protected static function generateConfig() { $config = parent::generateConfig(); // BACKEND $config->addField(Form\Field\Hidden::singleton('id')->setDisabled()); $config->addField(Form\Field\Text::singleton('working_name')->setLabel(__('Working name'))->addRulesSet(Validator\RulesSetBuilder\String::factory()->regex(':value', '^[a-z_]*$', __('The working name must contain only lowercase letters and underscores.')))); // return config return $config; }