/** * Forgery constructor * * @param string $entity */ public function __forge($entity) { $this->entity = $entity; $this->scaffold = \Magelight\Admin\Models\Scaffold\Scaffold::forge(); $this->scaffold->loadEntities(); $this->setConfigs('scaffold-' . $entity, $this->url(self::URL_PATTERN, ['entity' => $entity])); $this->setHorizontal(); $fieldSet = \Magelight\Webform\Blocks\Fieldset::forge(); $this->model = $this->scaffold->getEntityModel($this->entity); foreach ($this->scaffold->getEntityFields($this->entity) as $field) { $fieldConfig = $this->scaffold->getEntityFieldConfig($this->entity, $field); $row = \Magelight\Webform\Blocks\Row::forge(); /** @var $fieldInput \Magelight\Webform\Blocks\Elements\Input */ $fields = []; $fieldInput = self::callStaticLate([(string) $fieldConfig->class, 'forge']); $fieldInput->setName($field); $label = !empty($fieldConfig->label) ? (string) $fieldConfig->label : $field; $hint = !empty($fieldConfig->hint) ? (string) $fieldConfig->hint : ''; $fields[] = $fieldInput; if ((bool) (string) $fieldConfig->allow_null) { $checkboxNull = \Magelight\Webform\Blocks\Elements\LabeledCheckbox::forge(); $checkboxNull->setName("set-null[{$field}]"); $checkboxNull->setContent('Set NULL'); $fields[] = $checkboxNull; } $row->addField($fields, $label, $hint); $fieldSet->addRow($row); } $this->addFieldset($fieldSet); $this->createResultRow(true); $this->addButtonsRow([\Magelight\Webform\Blocks\Elements\Button::forge()->setType('submit')->setContent('Save')]); }
/** * Get login form * * @return \Magelight\Webform\Blocks\Form */ public function getLoginForm() { $form = Form::forge()->setHorizontal()->setConfigs('remindpass-form', $this->url(\Magelight\Config::getInstance()->getConfigString('global/auth/urls/login_url'))); $fieldset = Fieldset::forge(); $fieldset->addRowField(Elements\Input::forge()->setName('email'), __('E-Mail')); $fieldset->addRowField(Elements\PasswordInput::forge()->setName('password'), __('Password')); return $form->addFieldset($fieldset)->createResultRow(true)->addButtonsRow([Elements\Button::forge()->setContent(__('Enter'))->addClass('btn-primary'), Elements\Abstraction\Element::forge()->setTag('a')->setAttribute('href', $this->url('auth/remindpass'))->setContent(__('Remind password'))->setClass('btn')])->loadFromRequest(\Magelight\Http\Request::getInstance())->setValidator($this->getLoginFormValidator()); }
/** * Get for for password recovery page * * @return \Magelight\Webform\Blocks\Form */ public function getForgotPasswordForm() { $form = Form::forge()->setHorizontal()->setConfigs('remindpass-form', $this->url(\Magelight\Config::getInstance()->getConfigString('global/auth/urls/forgot_password_url'))); $fieldset = Fieldset::forge(); $fieldset->addRowField(Elements\Input::forge()->setName('email'), __('E-Mail', [], 1, 'default')); $validator = \Magelight\Webform\Models\Validator::forge(); $validator->fieldRules('email')->required()->setCustomError(__("Please enter a valid e-mail!", 1))->chainRule()->email()->setCustomError(__("Please enter a valid e-mail!", 1)); return $form->addFieldset($fieldset)->createResultRow(true)->addButtonsRow([Elements\Button::forge()->setContent(__('Send new password'))->addClass('btn-primary')])->loadFromRequest()->setValidator($validator)->validateOnFront(); }
/** * Get sample form * * @return Form */ public function getSampleForm() { $form = Form::forge()->setHorizontal()->setConfigs('sample', $this->url('sample/form')); $fieldset = Fieldset::forge(); $fieldset->setLegend('Register new user'); $fieldset->addRowField(Elements\Input::forge()->setName('name'), __('Name')); $fieldset->addRowField(Elements\Input::forge()->setName('email'), __('E-Mail')); $fieldset->addRowField(Elements\PasswordInput::forge()->setName('password'), __('Password')); $fieldset->addRowField(Elements\Captcha::forge($this->url(\Magelight\Config::getInstance()->getConfigString('global/auth/urls/render_captcha_url')))->setName('captcha')->addClass('col-md-6'), __('Enter protection code')); return $form->addFieldset($fieldset)->createResultRow(true)->addButtonsRow(Elements\Button::forge()->setContent(__('Register'))->addClass('btn-primary'))->loadFromRequest()->setValidator($this->getSampleFormValidator())->validateOnFront(); }