From 11ccdc08b7de3d6dcb6ab934349a931b468ed260 Mon Sep 17 00:00:00 2001 From: Anthonius Munthi Date: Sun, 2 Jul 2017 21:35:01 +0800 Subject: [PATCH] [ZF3][Behat,Settings] fixed all errors in /en/settings page --- behat.yml.dist | 3 +- composer.lock | 14 +- features/settings.feature | 33 +++ .../Applications/Form/SettingsFieldset.php | 17 +- module/Behat/src/CommonContextTrait.php | 54 ++++ module/Behat/src/CoreContext.php | 53 ++++ module/Behat/src/SettingsContext.php | 34 +++ module/Behat/src/UserContext.php | 15 +- module/Core/config/module.config.php | 6 +- .../Core/src/Core/Form/Element/Checkbox.php | 2 +- .../src/Core/Form/View/Helper/FormElement.php | 1 - .../CoreTest/Form/Element/CheckboxTest.php | 2 +- module/Settings/Module.php | 2 +- module/Settings/config/module.config.php | 262 +++++++++--------- .../Settings/Controller/IndexController.php | 69 +++-- .../Settings/Form/AbstractSettingsForm.php | 59 ++-- ...bleElementsCapableFormSettingsFieldset.php | 19 +- .../DisableElementsCapableFormSettings.php | 2 +- .../Form/Factory/SettingsFieldsetFactory.php | 20 +- .../src/Settings/Form/SettingsFieldset.php | 10 +- ...FormDisableElementsCapableFormSettings.php | 2 +- .../Listener/InjectSubNavigationListener.php | 2 +- 22 files changed, 451 insertions(+), 230 deletions(-) create mode 100644 features/settings.feature create mode 100644 module/Behat/src/CommonContextTrait.php create mode 100644 module/Behat/src/SettingsContext.php diff --git a/behat.yml.dist b/behat.yml.dist index f2986535e..cb39d57b7 100644 --- a/behat.yml.dist +++ b/behat.yml.dist @@ -44,4 +44,5 @@ default: - Behat\MinkExtension\Context\MinkContext - Yawik\Behat\CoreContext - Yawik\Behat\OrganizationContext - - Yawik\Behat\UserContext \ No newline at end of file + - Yawik\Behat\UserContext + - Yawik\Behat\SettingsContext \ No newline at end of file diff --git a/composer.lock b/composer.lock index 8db3d21c5..7007de347 100644 --- a/composer.lock +++ b/composer.lock @@ -2315,27 +2315,27 @@ }, { "name": "zendframework/zend-form", - "version": "2.10.0", + "version": "2.10.2", "source": { "type": "git", "url": "https://github.com/zendframework/zend-form.git", - "reference": "ca2b2f9e1bdc5511d06967d755cbb793708a2d7b" + "reference": "252db729887844025772bb8045f8df605850ed9c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/zendframework/zend-form/zipball/ca2b2f9e1bdc5511d06967d755cbb793708a2d7b", - "reference": "ca2b2f9e1bdc5511d06967d755cbb793708a2d7b", + "url": "https://api.github.com/repos/zendframework/zend-form/zipball/252db729887844025772bb8045f8df605850ed9c", + "reference": "252db729887844025772bb8045f8df605850ed9c", "shasum": "" }, "require": { - "php": "^5.5 || ^7.0", + "php": "^7.0 || ^5.6", "zendframework/zend-hydrator": "^1.1 || ^2.1", "zendframework/zend-inputfilter": "^2.6", "zendframework/zend-stdlib": "^2.7 || ^3.0" }, "require-dev": { "doctrine/annotations": "~1.0", - "phpunit/phpunit": "^4.8", + "phpunit/phpunit": "^6.0.8 || ^5.7.15", "zendframework/zend-cache": "^2.6.1", "zendframework/zend-captcha": "^2.7.1", "zendframework/zend-code": "^2.6 || ^3.0", @@ -2388,7 +2388,7 @@ "form", "zf2" ], - "time": "2017-02-23T16:03:25+00:00" + "time": "2017-05-18T14:59:53+00:00" }, { "name": "zendframework/zend-http", diff --git a/features/settings.feature b/features/settings.feature new file mode 100644 index 000000000..c13979082 --- /dev/null +++ b/features/settings.feature @@ -0,0 +1,33 @@ +Feature: Update application settings + In order to use Yawik + As an administrator + I should able to update yawik settings + + Background: + Given I am logged in as an administrator + + @javascript @settings + Scenario: Successfully change settings + Given I go to settings page + When I select "German" from "choose your language" + And I select "Europe/Berlin" from "choose your timzone" + And I press "Save" + And I wait for the ajax response + Then I should see "Changes successfully saved" + + @javascript @settings-email + Scenario: Successfully change E-Mail Notifications Settings + Given I go to email template settings page + When I check "receive E-Mail alert" + And I check "confirm application immidiatly after submit" + And I check "get blind carbon copy of all own mails" + And I wait for the ajax response + And I fill in the following: + | Mailtext | Some Mailtext | + | Confirmation mail text | Confirmation Mail | + | Invitation mail text | Invitation mail | + | Accept mail text | Accept mail text | + | Rejection mail text | Rejection mail text | + And I press "Save" + And I wait for the ajax response + Then I should see "Changes successfully saved" \ No newline at end of file diff --git a/module/Applications/src/Applications/Form/SettingsFieldset.php b/module/Applications/src/Applications/Form/SettingsFieldset.php index 363705a5e..dc5171799 100644 --- a/module/Applications/src/Applications/Form/SettingsFieldset.php +++ b/module/Applications/src/Applications/Form/SettingsFieldset.php @@ -10,7 +10,9 @@ namespace Applications\Form; use Settings\Entity\Hydrator\SettingsEntityHydrator; +use Zend\Form\Element\Checkbox; use Zend\Form\Fieldset; +use Zend\Stdlib\InitializableInterface; //use Zend\InputFilter\InputFilterProviderInterface; @@ -41,10 +43,11 @@ public function init() { $this->setName('emails') ->setLabel(/* @translate */ 'E-Mail Notifications'); - + $this->add( - array('type' => 'Zend\Form\Element\Checkbox', + array('type' => Checkbox::class, 'name' => 'mailAccess', + 'label' => 'foo', 'options' => array('label' => /* @translate */ 'receive E-Mail alert', 'long_label' => /* @translate */ 'if checked, you\'ll be informed by mail about new applications.'), ) @@ -114,11 +117,11 @@ public function init() $this->add( array( - 'type' => 'Settings/DisableElementsCapableFormSettingsFieldset', - 'name' => 'applyFormSettings', - 'options' => array( - - ) + 'type' => 'Settings/DisableElementsCapableFormSettingsFieldset', + 'name' => 'applyFormSettings', + 'options' => array( + + ) ) ); } diff --git a/module/Behat/src/CommonContextTrait.php b/module/Behat/src/CommonContextTrait.php new file mode 100644 index 000000000..312b4d94a --- /dev/null +++ b/module/Behat/src/CommonContextTrait.php @@ -0,0 +1,54 @@ + + */ + +namespace Yawik\Behat; + + +use Behat\Behat\Hook\Scope\BeforeScenarioScope; +use Behat\MinkExtension\Context\MinkContext; + +trait CommonContextTrait +{ + /** + * @var MinkContext + */ + protected $minkContext; + + /** + * @var CoreContext + */ + protected $coreContext; + + /** + * @var UserContext + */ + protected $userContext; + + /** + * @BeforeScenario + * + * @param BeforeScenarioScope $scope + */ + public function gatherContexts(BeforeScenarioScope $scope) + { + $this->minkContext = $scope->getEnvironment()->getContext(MinkContext::class); + $this->coreContext = $scope->getEnvironment()->getContext(CoreContext::class); + $this->userContext = $scope->getEnvironment()->getContext(UserContext::class); + } + + public function generateUrl($url) + { + return $this->coreContext->generateUrl($url); + } + + public function visit($url) + { + $this->coreContext->iVisit($this->generateUrl($url)); + } +} \ No newline at end of file diff --git a/module/Behat/src/CoreContext.php b/module/Behat/src/CoreContext.php index 00e9fa0e4..3bf9da80a 100644 --- a/module/Behat/src/CoreContext.php +++ b/module/Behat/src/CoreContext.php @@ -167,4 +167,57 @@ public function iVisit($url) { $this->minkContext->getSession()->visit($url); } + + /** + * @When I scroll :selector into view + * + * @param string $selector Allowed selectors: #id, .className, //xpath + * + * @throws \Exception + */ + public function scrollIntoView($selector) + { + $locator = substr($selector, 0, 1); + + switch ($locator) { + case '/' : // XPath selector + $function = <<getSession()->executeScript($function); + } catch (Exception $e) { + throw new \Exception(__METHOD__ . ' failed'); + } + } } \ No newline at end of file diff --git a/module/Behat/src/SettingsContext.php b/module/Behat/src/SettingsContext.php new file mode 100644 index 000000000..902b6b937 --- /dev/null +++ b/module/Behat/src/SettingsContext.php @@ -0,0 +1,34 @@ + + */ + +namespace Yawik\Behat; + + +use Behat\Behat\Context\Context; + +class SettingsContext implements Context +{ + use CommonContextTrait; + + /** + * @Given I go to settings page + */ + public function iGoToSettingsPage() + { + $this->visit('/en/settings'); + } + + /** + * @Given I go to email template settings page + */ + public function iGoToEmailTemplatePage() + { + $this->visit('/en/settings/Applications'); + } +} \ No newline at end of file diff --git a/module/Behat/src/UserContext.php b/module/Behat/src/UserContext.php index 6a11a2219..d52ad6410 100644 --- a/module/Behat/src/UserContext.php +++ b/module/Behat/src/UserContext.php @@ -121,6 +121,19 @@ public function iAmLoggedInAsARecruiter() $this->iSpecifyThePasswordAs('test'); $this->iLogIn(); } + + /** + * @Given I am logged in as an administrator + */ + public function iAmLoggedInAsAnAdmin() + { + $this->thereIsAUserIdentifiedBy('test@admin.com','test',User::ROLE_ADMIN); + $this->iWantToLogIn(); + $this->iSpecifyTheUsernameAs('test@admin.com'); + $this->iSpecifyThePasswordAs('test'); + $this->iLogIn(); + } + /** * @return UserRepository */ @@ -132,7 +145,7 @@ public function getUserRepository() /** * @Given there is a user :email identified by :password */ - public function thereIsAUserIdentifiedBy($email, $password) + public function thereIsAUserIdentifiedBy($email, $password,$role=User::ROLE_RECRUITER) { $repo = $this->getUserRepository(); if(!is_object($user=$repo->findByEmail($email))){ diff --git a/module/Core/config/module.config.php b/module/Core/config/module.config.php index 9c762d50d..ddd9ce1fa 100644 --- a/module/Core/config/module.config.php +++ b/module/Core/config/module.config.php @@ -355,7 +355,7 @@ ), 'view_helpers' => array( 'invokables' => array( - 'formElement' => 'Core\Form\View\Helper\FormElement', + 'form_element' => 'Core\Form\View\Helper\FormElement', 'formLabel' => 'Core\Form\View\Helper\RequiredMarkInFormLabel', 'form' => 'Core\Form\View\Helper\Form', 'formSimple' => 'Core\Form\View\Helper\FormSimple', @@ -372,7 +372,11 @@ 'formRowCombined' => 'Core\Form\View\Helper\FormRowCombined', 'formFileUpload' => 'Core\Form\View\Helper\FormFileUpload', 'formImageUpload' => 'Core\Form\View\Helper\FormImageUpload', + + /* @TODO: [ZF3] make this setting to be camel cased */ 'formCheckBox' => 'Core\Form\View\Helper\FormCheckbox', + 'formcheckbox' => 'Core\Form\View\Helper\FormCheckbox', + 'formDatePicker' => 'Core\Form\View\Helper\FormDatePicker', 'formInfoCheckBox' => 'Core\Form\View\Helper\FormInfoCheckbox', 'formSelect' => 'Core\Form\View\Helper\FormSelect', diff --git a/module/Core/src/Core/Form/Element/Checkbox.php b/module/Core/src/Core/Form/Element/Checkbox.php index 56316b8c7..08f70cec7 100644 --- a/module/Core/src/Core/Form/Element/Checkbox.php +++ b/module/Core/src/Core/Form/Element/Checkbox.php @@ -22,7 +22,7 @@ class Checkbox extends ZfCheckbox implements ViewHelperProviderInterface /** * @var string */ - protected $helper = 'formcheckbox'; + protected $helper = 'formCheckBox'; /** * @param string|\Zend\View\Helper\HelperInterface $helper diff --git a/module/Core/src/Core/Form/View/Helper/FormElement.php b/module/Core/src/Core/Form/View/Helper/FormElement.php index c0b679537..531046416 100644 --- a/module/Core/src/Core/Form/View/Helper/FormElement.php +++ b/module/Core/src/Core/Form/View/Helper/FormElement.php @@ -7,7 +7,6 @@ use Core\Form\ViewPartialProviderInterface; use Zend\Form\View\Helper\FormElement as ZendFormElement; -use Zend\Form\Element; use Zend\Form\ElementInterface; use Core\Form\Element\ViewHelperProviderInterface as CoreElementInterface; use Zend\View\Helper\HelperInterface; diff --git a/module/Core/test/CoreTest/Form/Element/CheckboxTest.php b/module/Core/test/CoreTest/Form/Element/CheckboxTest.php index dcfed4026..3f8b5ac04 100644 --- a/module/Core/test/CoreTest/Form/Element/CheckboxTest.php +++ b/module/Core/test/CoreTest/Form/Element/CheckboxTest.php @@ -30,7 +30,7 @@ public function testConstructor() { $this->assertInstanceOf('Core\Form\Element\Checkbox', $this->target); $this->assertInstanceOf('Zend\Form\Element', $this->target); - $this->assertAttributeSame('formcheckbox','helper',$this->target); + $this->assertAttributeSame('formCheckBox','helper',$this->target); } public function testSetGetViewHelper() diff --git a/module/Settings/Module.php b/module/Settings/Module.php index f383ad2dd..8134ea03e 100644 --- a/module/Settings/Module.php +++ b/module/Settings/Module.php @@ -32,7 +32,7 @@ public function onBootstrap(MvcEvent $e) // we attach with wildcard events name $events = $e->getApplication()->getEventManager(); $events->attach( - 'render*', + MvcEvent::EVENT_RENDER, new InjectSubNavigationListener(), 10 ); diff --git a/module/Settings/config/module.config.php b/module/Settings/config/module.config.php index 6161842ea..53b20bb92 100644 --- a/module/Settings/config/module.config.php +++ b/module/Settings/config/module.config.php @@ -13,138 +13,134 @@ */ return [ - - 'doctrine' => [ - 'driver' => [ - 'odm_default' => [ - 'drivers' => [ - 'Settings\Entity' => 'annotation', - ], - ], - ], - 'eventmanager' => [ - 'odm_default' => [ - 'subscribers' => [ - 'Settings/InjectEntityResolverListener', - ], - ], - ], - ], - - - // Translations - 'translator' => [ - 'translation_file_patterns' => [ - [ - 'type' => 'gettext', - 'base_dir' => __DIR__ . '/../language', - 'pattern' => '%s.mo', - ], - ], - ], - // Routes - 'router' => [ - 'routes' => [ - 'lang' => [ - 'child_routes' => [ - 'settings' => [ - 'type' => 'Segment', - 'options' => [ - 'route' => '/settings[/:module]', - 'defaults' => [ - 'controller' => 'Settings\Controller\Index', - 'action' => 'index', - 'module' => 'Core', - ], - ], - 'may_terminate' => true, - ], - ], - ], - ], - ], - - 'acl' => ['rules' => [ - 'user' => [ - 'allow' => [ - 'route/lang/settings', - 'Settings\Controller\Index', - ], - ], - ]], - 'navigation' => [ - 'default' => [ - 'settings' => [ - 'label' => /*@translate*/ 'Settings', - 'route' => 'lang/settings', - 'resource' => 'route/lang/settings', - 'order' => 100, - 'params' => ['module' => null], - ], - ], - ], - - // Configuration of the controller service manager (Which loads controllers) - 'controllers' => [ - 'invokables' => [ - 'Settings\Controller\Index' => 'Settings\Controller\IndexController' - ], - ], - - // Configure the view service manager - 'view_manager' => [ - // Map template to files. Speeds up the lookup through the template stack. - 'template_map' => [ - ], - - // Where to look for view templates not mapped above - 'template_path_stack' => [ - __DIR__ . '/../view', - ], - ], - - 'view_helpers' => [ - 'invokables' => [ - 'Settings/FormDisableElementsCapableFormSettings' => 'Settings\Form\View\Helper\FormDisableElementsCapableFormSettings', - ], - 'factories' => [ - ], - ], - - 'service_manager' => [ - 'factories' => [ - 'Settings' => '\Settings\Settings\SettingsFactory', - 'Settings/EntityResolver' => '\Settings\Repository\SettingsEntityResolverFactory', - 'Settings/InjectEntityResolverListener' => function($sm){ - //'Settings\Repository\Event\InjectSettingsEntityResolverListener::factory' - return \Settings\Repository\Event\InjectSettingsEntityResolverListener::factory($sm); - }, - ], - 'initializers' => [], - 'shared' => [], - 'aliases' => [], - ], - - 'controller_plugins' => [ - 'factories' => ['settings' => '\Settings\Controller\Plugin\SettingsFactory'], - ], - - 'form_elements' => [ - 'factories' => [ - \Settings\Form\SettingsFieldset::class => \Settings\Form\Factory\SettingsFieldsetFactory::class, - 'Settings/Form' => '\Settings\Form\AbstractSettingsForm::factory', - 'Settings/DisableElementsCapableFormSettingsFieldset' => '\Settings\Form\DisableElementsCapableFormSettingsFieldset::factory', - ], - 'aliases' => [ - 'Settings/Fieldset' => \Settings\Form\SettingsFieldset::class, - ], - ], + + 'doctrine' => [ + 'driver' => [ + 'odm_default' => [ + 'drivers' => [ + 'Settings\Entity' => 'annotation', + ], + ], + ], + 'eventmanager' => [ + 'odm_default' => [ + 'subscribers' => [ + 'Settings/InjectEntityResolverListener', + ], + ], + ], + ], + + + // Translations + 'translator' => [ + 'translation_file_patterns' => [ + [ + 'type' => 'gettext', + 'base_dir' => __DIR__ . '/../language', + 'pattern' => '%s.mo', + ], + ], + ], + // Routes + 'router' => [ + 'routes' => [ + 'lang' => [ + 'child_routes' => [ + 'settings' => [ + 'type' => 'Segment', + 'options' => [ + 'route' => '/settings[/:module]', + 'defaults' => [ + 'controller' => 'Settings\Controller\Index', + 'action' => 'index', + 'module' => 'Core', + ], + ], + 'may_terminate' => true, + ], + ], + ], + ], + ], + + 'acl' => ['rules' => [ + 'user' => [ + 'allow' => [ + 'route/lang/settings', + 'Settings\Controller\Index', + ], + ], + ]], + 'navigation' => [ + 'default' => [ + 'settings' => [ + 'label' => /*@translate*/ 'Settings', + 'route' => 'lang/settings', + 'resource' => 'route/lang/settings', + 'order' => 100, + 'params' => ['module' => null], + ], + ], + ], + + // Configuration of the controller service manager (Which loads controllers) + 'controllers' => [ + 'factories' => [ + 'Settings\Controller\Index' => [\Settings\Controller\IndexController::class,'factory'] + ], + ], + + // Configure the view service manager + 'view_manager' => [ + // Map template to files. Speeds up the lookup through the template stack. + 'template_map' => [ + ], + + // Where to look for view templates not mapped above + 'template_path_stack' => [ + __DIR__ . '/../view', + ], + ], + + 'view_helpers' => [ + 'invokables' => [ + 'Settings/FormDisableElementsCapableFormSettings' => 'Settings\Form\View\Helper\FormDisableElementsCapableFormSettings', + ], + 'factories' => [ + ], + ], + + 'service_manager' => [ + 'factories' => [ + 'Settings' => '\Settings\Settings\SettingsFactory', + 'Settings/EntityResolver' => '\Settings\Repository\SettingsEntityResolverFactory', + 'Settings/InjectEntityResolverListener' => [\Settings\Repository\Event\InjectSettingsEntityResolverListener::class,'factory'], + ], + 'initializers' => [], + 'shared' => [], + 'aliases' => [], + ], + + 'controller_plugins' => [ + 'factories' => ['settings' => '\Settings\Controller\Plugin\SettingsFactory'], + ], + + 'form_elements' => [ + 'factories' => [ + 'Settings/Form' => [\Settings\Form\AbstractSettingsForm::class,'factory'], + 'Settings/DisableElementsCapableFormSettingsFieldset' => [\Settings\Form\DisableElementsCapableFormSettingsFieldset::class,'factory'], + 'Settings/Fieldset' => \Settings\Form\Factory\SettingsFieldsetFactory::class, + ], + 'aliases' => [ + ], + ], + + 'filters' => [ + 'invokables' => [ + 'Settings/Filter/DisableElementsCapableFormSettings' => \Settings\Form\Filter\DisableElementsCapableFormSettings::class, + ] + ] + - 'filters' => [ - 'invokables' => [ - 'Settings/DisableElementsCapableFormSettings' => '\Settings\Form\Filter\DisableElementsCapableFormSettings', - ] - ] - - ]; diff --git a/module/Settings/src/Settings/Controller/IndexController.php b/module/Settings/src/Settings/Controller/IndexController.php index 345ebe637..4269e1eb4 100644 --- a/module/Settings/src/Settings/Controller/IndexController.php +++ b/module/Settings/src/Settings/Controller/IndexController.php @@ -14,10 +14,13 @@ /** Settings controller */ namespace Settings\Controller; +use Interop\Container\ContainerInterface; +use Zend\I18n\Translator\TranslatorInterface; use Zend\Mvc\Controller\AbstractActionController; use Zend\View\Model\JsonModel; use Zend\EventManager\Event; use Zend\Http\PhpEnvironment\Response; +use Zend\Form\FormElementManager\FormElementManagerV3Polyfill as FormElementManager; /** * Main Action Controller for Settings module @@ -25,25 +28,42 @@ */ class IndexController extends AbstractActionController { - /** - * attaches further Listeners for generating / processing the output - * - * @return $this - */ - public function attachDefaultListeners() - { - parent::attachDefaultListeners(); - $serviceLocator = $this->serviceLocator; - $defaultServices = $serviceLocator->get('DefaultListeners'); - $events = $this->getEventManager(); - $events->attach($defaultServices); - return $this; - } - + /** + * @var TranslatorInterface + */ + private $translator; + + /** + * @var FormElementManager + */ + private $formManager; + + private $viewHelper; + + public function __construct( + TranslatorInterface $translator, + FormElementManager $formManager, + $viewHelper + ) + { + $this->translator = $translator; + $this->formManager = $formManager; + $this->viewHelper = $viewHelper; + } + + static public function factory(ContainerInterface $container) + { + $translator = $container->get('translator'); + return new self( + $translator, + $container->get('FormElementManager'), + $container->get('ViewHelperManager') + ); + } + public function indexAction() { - $services = $this->serviceLocator; - $translator = $services->get('translator'); + $translator = $this->translator; $moduleName = $this->params('module', 'Core'); @@ -65,7 +85,7 @@ public function indexAction() $mvcEvent = $this->getEvent(); $mvcEvent->setParam('__settings_active_module', $moduleName); - $formManager = $this->serviceLocator->get('FormElementManager'); + $formManager = $this->formManager; $formName = $moduleName . '/SettingsForm'; if (!$formManager->has($formName)) { $formName = "Settings/Form"; @@ -79,19 +99,18 @@ public function indexAction() $form = $formManager->get($formName); + $vars = array(); + $vars['form'] = $form; // Binding the Entity to the Formular $form->bind($settings); $data = $this->getRequest()->getPost(); if (0 < count($data)) { $form->setData($data); - $valid = $form->isValid(); - $partial = $services->get('viewhelpermanager')->get('partial'); + $partial = $this->viewHelper->get('partial'); $text = $valid ? /*@translate*/'Changes successfully saved' : /*@translate*/'Changes could not be saved'; - - $vars = array(); $this->notification()->success($translator->translate($text)); if ($valid) { @@ -100,15 +119,15 @@ public function indexAction() $this, array('settings' => $settings) ); - $this->getEventManager()->trigger($event); + $this->getEventManager()->trigger($event->getName(),$event); + $vars['valid'] = true; } else { $vars['error'] = $form->getMessages(); } - return new JsonModel($vars); } - $vars['form']=$form; + return $vars; } } diff --git a/module/Settings/src/Settings/Form/AbstractSettingsForm.php b/module/Settings/src/Settings/Form/AbstractSettingsForm.php index 5c5636611..859fd469b 100644 --- a/module/Settings/src/Settings/Form/AbstractSettingsForm.php +++ b/module/Settings/src/Settings/Form/AbstractSettingsForm.php @@ -11,10 +11,13 @@ namespace Settings\Form; use Core\Form\Form; +use Interop\Container\ContainerInterface; use Settings\Entity\ModuleSettingsContainerInterface; +use Zend\Form\FormElementManager\FormElementManagerV3Polyfill as FormElementManager; use Zend\ServiceManager\ServiceLocatorInterface; use Zend\Form\FormInterface; use Settings\Entity\Hydrator\SettingsEntityHydrator; +use Zend\View\HelperPluginManager; class AbstractSettingsForm extends Form { @@ -22,19 +25,31 @@ class AbstractSettingsForm extends Form * @var bool */ protected $isBuild = false; - - /** - * @var ServiceLocatorInterface - */ + + /** + * @var FormElementManager + */ protected $formManager; - - /** - * @param ServiceLocatorInterface $formManager - */ - public function __construct(ServiceLocatorInterface $formManager) + + /** + * @var array|HelperPluginManager + */ + protected $viewHelper; + + /** + * AbstractSettingsForm constructor. + * + * @param FormElementManager $formManager + * @param HelperPluginManager $viewHelper + */ + public function __construct( + FormElementManager $formManager, + HelperPluginManager $viewHelper + ) { parent::__construct(); $this->formManager = $formManager; + $this->viewHelper = $viewHelper; } /** @@ -71,7 +86,9 @@ public function build() $fieldset->setObject($object); $this->add($fieldset); - $this->add($this->formManager->get('DefaultButtonsFieldset')); + $this->add([ + 'type' => 'DefaultButtonsFieldset' + ]); $this->isBuild=true; } @@ -91,9 +108,7 @@ public function setObject($object) public function setName($name) { parent::setName(strtolower($name) . '-settings'); - $urlHelper = $this->formManager->getServiceLocator() - ->get('ViewHelperManager') - ->get('url'); + $urlHelper = $this->viewHelper->get('url'); $url = $urlHelper('lang/settings', array('module' => $name), true); $this->setAttribute('action', $url); @@ -116,13 +131,17 @@ protected function getModuleName() return strtolower($moduleName); } - - /** - * @param ServiceLocatorInterface $formManager - * @return AbstractSettingsForm - */ - public static function factory(ServiceLocatorInterface $formManager) + + /** + * @param ContainerInterface $container + * + * @return AbstractSettingsForm + */ + public static function factory(ContainerInterface $container) { - return new static($formManager); + return new static( + $container->get('FormElementManager'), + $container->get('ViewHelperManager') + ); } } diff --git a/module/Settings/src/Settings/Form/DisableElementsCapableFormSettingsFieldset.php b/module/Settings/src/Settings/Form/DisableElementsCapableFormSettingsFieldset.php index ec8a8e04a..7dfc8b1a3 100644 --- a/module/Settings/src/Settings/Form/DisableElementsCapableFormSettingsFieldset.php +++ b/module/Settings/src/Settings/Form/DisableElementsCapableFormSettingsFieldset.php @@ -10,7 +10,9 @@ /** */ namespace Settings\Form; +use Interop\Container\ContainerInterface; use Zend\Form\Fieldset; +use Settings\Form\Element\DisableElementsCapableFormSettings; use Settings\Entity\Hydrator\SettingsEntityHydrator; use Settings\Entity\Hydrator\Strategy\DisableElementsCapableFormSettings as DisableElementsStrategy; use Zend\ServiceManager\ServiceLocatorInterface; @@ -100,19 +102,20 @@ public function build() ), ) ); - $element = new \Settings\Form\Element\DisableElementsCapableFormSettings('disableElements'); + $element = new DisableElementsCapableFormSettings('disableElements'); $element->setForm($form); $this->add($element); $this->isBuild = true; } - - /** - * @param ServiceLocatorInterface $formManager - * @return AbstractSettingsForm - */ - public static function factory(ServiceLocatorInterface $formManager) + + /** + * @param ContainerInterface $container + * + * @return DisableElementsCapableFormSettingsFieldset + */ + public static function factory(ContainerInterface $container) { - return new static($formManager); + return new static($container->get('FormElementManager')); } } diff --git a/module/Settings/src/Settings/Form/Element/DisableElementsCapableFormSettings.php b/module/Settings/src/Settings/Form/Element/DisableElementsCapableFormSettings.php index aa4a4cfb0..5ef6ec8a1 100644 --- a/module/Settings/src/Settings/Form/Element/DisableElementsCapableFormSettings.php +++ b/module/Settings/src/Settings/Form/Element/DisableElementsCapableFormSettings.php @@ -167,7 +167,7 @@ public function getInputSpecification() 'required' => true, 'filters' => array( array( - 'name' => 'Settings/DisableElementsCapableFormSettings', + 'name' => \Settings\Form\Filter\DisableElementsCapableFormSettings::class, ), ), ); diff --git a/module/Settings/src/Settings/Form/Factory/SettingsFieldsetFactory.php b/module/Settings/src/Settings/Form/Factory/SettingsFieldsetFactory.php index c47f1e752..47b575be2 100644 --- a/module/Settings/src/Settings/Form/Factory/SettingsFieldsetFactory.php +++ b/module/Settings/src/Settings/Form/Factory/SettingsFieldsetFactory.php @@ -10,11 +10,9 @@ /** */ namespace Settings\Form\Factory; -use Settings\Form\SettingsFieldset; use Interop\Container\ContainerInterface; -use Zend\Form\FormElementManager\FormElementManagerV2Polyfill; -use Zend\ServiceManager\FactoryInterface; -use Zend\ServiceManager\ServiceLocatorInterface; +use Settings\Form\SettingsFieldset; +use Zend\ServiceManager\Factory\FactoryInterface; /** * Factory for \Settings\Form\SettingsFieldset @@ -25,18 +23,10 @@ */ class SettingsFieldsetFactory implements FactoryInterface { - public function __invoke(ContainerInterface $container, $requestedName, array $options = null) { - if (!$container instanceOf FormElementManagerV2Polyfill) { - $container = $container->get('FormElementManager'); - } - - return new $requestedName($container); - } - - public function createService(ServiceLocatorInterface $serviceLocator, $name=null, $requestedName=SettingsFieldset::class) - { - return $this($serviceLocator, $requestedName); + $ob = new SettingsFieldset($container->get('FormElementManager')); + $ob->setName($requestedName); + return $ob; } } diff --git a/module/Settings/src/Settings/Form/SettingsFieldset.php b/module/Settings/src/Settings/Form/SettingsFieldset.php index 7384e117c..fd87cbd3d 100644 --- a/module/Settings/src/Settings/Form/SettingsFieldset.php +++ b/module/Settings/src/Settings/Form/SettingsFieldset.php @@ -6,12 +6,12 @@ use Settings\Entity\SettingsContainerInterface; use Settings\Entity\ModuleSettingsContainerInterface; use Settings\Entity\Hydrator\SettingsEntityHydrator; -use Zend\ServiceManager\ServiceLocatorInterface; +use Zend\Form\FormElementManager\FormElementManagerV3Polyfill as FormElementManager; class SettingsFieldset extends Fieldset { /** - * @var ServiceLocatorInterface + * @var FormElementManager */ protected $formManager; @@ -19,9 +19,9 @@ class SettingsFieldset extends Fieldset protected $labelMap = []; /** - * @param ServiceLocatorInterface $formManager + * @param FormElementManager $formManager */ - public function __construct(ServiceLocatorInterface $formManager) + public function __construct(FormElementManager $formManager) { parent::__construct(); $this->formManager = $formManager; @@ -109,7 +109,7 @@ public function build() $fieldset->setHydrator($this->getHydrator()); } } else { - $fieldset = new self(); + $fieldset = new self($this->formManager); $label = preg_replace('~([A-Z])~', ' $1', $name); $fieldset->setLabel(ucfirst($label)); } diff --git a/module/Settings/src/Settings/Form/View/Helper/FormDisableElementsCapableFormSettings.php b/module/Settings/src/Settings/Form/View/Helper/FormDisableElementsCapableFormSettings.php index 3605827ee..7de1eea79 100644 --- a/module/Settings/src/Settings/Form/View/Helper/FormDisableElementsCapableFormSettings.php +++ b/module/Settings/src/Settings/Form/View/Helper/FormDisableElementsCapableFormSettings.php @@ -84,7 +84,7 @@ protected function renderCheckbox($box, $class = null) if (null !== $class) { $box->setAttribute('class', $box->getAttribute('class') . ' ' . $class); } - $markup = $renderer->formCheckbox($box); + $markup = $renderer->formCheckBox($box); if ($desc = $box->getOption('description')) { $desc = $this->getTranslator()->translate($desc, $this->getTranslatorTextDomain()); $markup .= '

' . $desc . '

'; diff --git a/module/Settings/src/Settings/Listener/InjectSubNavigationListener.php b/module/Settings/src/Settings/Listener/InjectSubNavigationListener.php index d97af71eb..a8d5d4bdf 100644 --- a/module/Settings/src/Settings/Listener/InjectSubNavigationListener.php +++ b/module/Settings/src/Settings/Listener/InjectSubNavigationListener.php @@ -10,7 +10,7 @@ /** InjectSubNavigationConfigListener.php */ namespace Settings\Listener; -use Zend\Mvc\Router\RouteMatch; +use Zend\Router\RouteMatch; use Zend\Mvc\MvcEvent; /**