diff --git a/src/Ajax/Ex/AjaxControllerEx.php b/src/Ajax/Ex/AjaxControllerEx.php index 7aa8965..448c036 100755 --- a/src/Ajax/Ex/AjaxControllerEx.php +++ b/src/Ajax/Ex/AjaxControllerEx.php @@ -4,6 +4,7 @@ namespace A2nt\CMSNiceties\Ajax\Ex; use SilverStripe\Control\Controller; use SilverStripe\Control\Director; +use SilverStripe\Core\Config\Config; use SilverStripe\Core\Extension; use SilverStripe\Core\Injector\Injector; use SilverStripe\Forms\Form; @@ -13,25 +14,52 @@ use SilverStripe\Security\Security; use SilverStripe\View\SSViewer; /** - * Class \App\Service\Ex\ServiceAreaController + * Class \A2nt\CMSNiceties\Ajax\Ex\AjaxControllerEx * - * @property \A2nt\CMSNiceties\Ajax\Ex\AjaxLoginFormControllerEx $owner + * @property \A2nt\CMSNiceties\Ajax\Ex\AjaxControllerEx $owner */ class AjaxControllerEx extends Extension { + private static $no_placeholders = false; + private static $show_labels = false; + private static $allowed_actions = [ 'LoginFormEx', 'LostPasswordForm', 'passwordsent', ]; - private static function _makeAllFieldsRequired(Form $form) + private static function _processFields(Form $form) { + $cfg = Config::inst()->get(__CLASS__); + $fields = $form->Fields(); - foreach ($fields as $f) { - $f + foreach ($fields as $field) { + $name = $field->getName(); + if ($name === 'Remember') { + continue; + } + + $field ->setAttribute('required', 'required') ->addExtraClass('required'); + + /* + * A2nt\CMSNiceties\Ajax\Ex\AjaxControllerEx: + * show_labels: false + * no_placeholders: false + */ + if (!$cfg['no_placeholders']) { + $placeholder = $field->Title(); + $field->setAttribute( + 'placeholder', + $placeholder + ); + } + + if (!$cfg['show_labels']) { + $field->setTitle(''); + } } } @@ -41,10 +69,10 @@ class AjaxControllerEx extends Extension /* @var Form $form */ $form = $ctrl->LoginForm(); - self::_makeAllFieldsRequired($form); + self::_processFields($form); //$form->addExtraClass('ajax-form'); - $form->setLegend('Sign in to your service account'); + $form->setLegend('Log in to your service account'); if ($form->get_protector()) { $form->enableSpamProtection(); @@ -64,7 +92,7 @@ class AjaxControllerEx extends Extension ->getLostPasswordHandler($ctrl->Link()) ->lostPasswordForm(); - self::_makeAllFieldsRequired($form); + self::_processFields($form); $form->addExtraClass('ajax-form'); $form->setLegend('Restore your password'); diff --git a/src/Extensions/PlaceholderFormExtension.php b/src/Extensions/PlaceholderFormExtension.php index dc0c00f..606512a 100755 --- a/src/Extensions/PlaceholderFormExtension.php +++ b/src/Extensions/PlaceholderFormExtension.php @@ -29,8 +29,9 @@ class PlaceholderFormExtension extends Extension if (is_a($field, TextField::class) || is_a($field, TextareaField::class)) { if (!$field->getAttribute('placeholder')) { $placeholder = $field->Title(); + $cfg = Config::inst()->get(\get_class($this->owner)); - if (!Config::inst()->get(\get_class($this->owner), 'no_placeholders')) { + if (!$cfg['no_placeholders']) { $field->setAttribute( 'placeholder', $placeholder @@ -41,7 +42,7 @@ class PlaceholderFormExtension extends Extension * SilverStripe\UserForms\Form\UserForm: * show_labels: false */ - if (!Config::inst()->get(\get_class($this->owner), 'show_labels')) { + if (!$cfg['show_labels']) { $field->setTitle(''); } }