Skip to content

Commit

Permalink
fix: do not use FormManagerV3PolyFill class anymore
Browse files Browse the repository at this point in the history
  • Loading branch information
TiSiE committed Jul 29, 2021
1 parent 4ea5e81 commit 8c81cf6
Show file tree
Hide file tree
Showing 18 changed files with 86 additions and 91 deletions.
6 changes: 3 additions & 3 deletions module/Core/src/Factory/Controller/LazyControllerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
use Core\Repository\RepositoryService;
use Core\Service\FileManager;
use Interop\Container\ContainerInterface;
use Laminas\Form\FormElementManager\FormElementManagerV3Polyfill as FormElementManager;
use Laminas\Form\FormElementManager;
use Laminas\ModuleManager\ModuleManagerInterface;
use Laminas\Mvc\I18n\Translator;
use Laminas\ServiceManager\Exception\ServiceNotCreatedException;
Expand All @@ -37,7 +37,7 @@ class LazyControllerFactory implements AbstractFactoryInterface
RepositoryService::class => 'repositories',
FileManager::class => FileManager::class
];

public function canCreate(ContainerInterface $container, $requestedName)
{
return strstr($requestedName, '\Controller') !== false;
Expand Down Expand Up @@ -81,7 +81,7 @@ public function __invoke(ContainerInterface $container, $requestedName, array $o
return $class->newInstanceArgs($constructorArgs);
}
}

return new $className;
}

Expand Down
66 changes: 33 additions & 33 deletions module/Core/src/Form/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class Container extends Element implements
* @var array
*/
protected $forms = array();

/**
* Active formulars keys.
*
Expand All @@ -48,20 +48,20 @@ class Container extends Element implements
* @var array
*/
protected $activeForms = array();

/**
* The form element manager.
* @var \Laminas\Form\FormElementManager\FormElementManagerV3Polyfill
* @var \Laminas\Form\FormElementManager
*/
protected $formElementManager;

/**
* Entity to bind to the formulars.
*
* @var \Core\Entity\EntityInterface[]
*/
protected $entities;

/**
* Parameters to pass to the formulars.
*
Expand Down Expand Up @@ -101,7 +101,7 @@ public function getIterator()

return $iterator;
}

/**
* Gets the count of enabled formulars
*
Expand Down Expand Up @@ -206,7 +206,7 @@ public function setOptions($options)
public function setParams(array $params)
{
$this->params = array_merge($this->params, $params);

foreach ($this->forms as $form) {
if (isset($form['__instance__'])
&& is_object($form['__instance__'])
Expand All @@ -217,7 +217,7 @@ public function setParams(array $params)
}
return $this;
}

/**
* Gets the formular parameters.
*
Expand All @@ -227,7 +227,7 @@ public function getParams()
{
return $this->params;
}

/**
* Sets a formular parameter.
*
Expand All @@ -238,7 +238,7 @@ public function getParams()
public function setParam($key, $value)
{
$this->params[$key] = $value;

foreach ($this->forms as $form) {
if (isset($form['__instance__'])
&& is_object($form['__instance__'])
Expand All @@ -249,7 +249,7 @@ public function setParam($key, $value)
}
return $this;
}

/**
* Gets the value of a formular parameter.
*
Expand Down Expand Up @@ -284,11 +284,11 @@ public function getForm($key, $asInstance = true)
$container = $this->getForm($key);
return $container->getForm($childKey);
}

if (!isset($this->forms[$key])) {
return null;
}

$form = $this->forms[$key];

if (!$asInstance) {
Expand All @@ -309,12 +309,12 @@ public function getForm($key, $asInstance = true)
if (!isset($options['use_files_array'])) {
$options['use_files_array'] = false;
}

//@TODO: [ZF3] Passing options in $formElementManager->get is not working need to do manually set options
$formInstance = $this->formElementManager->get($form['type'], $options);
$formInstance->setOptions(array_merge($formInstance->getOptions(), $options));
$formInstance->setParent($this);

if (isset($form['attributes'])) {
$formInstance->setAttributes($form['attributes']);
}
Expand All @@ -333,7 +333,7 @@ public function getForm($key, $asInstance = true)
} elseif (isset($form['options']['label'])) {
$formLabel = $form['options']['label'];
}

if (isset($formLabel)) {
$formInstance->setLabel($formLabel);
}
Expand All @@ -356,7 +356,7 @@ public function getForm($key, $asInstance = true)
$this->forms[$key]['options'] = $options;
return $formInstance;
}

/**
* Execute an arbitrary action
*
Expand All @@ -369,11 +369,11 @@ public function executeAction($name, array $data = [])
if (false !== strpos($name, '.')) {
list($name, $childKey) = explode('.', $name, 2);
$container = $this->getForm($name);

// execute child container's action
return $container->executeAction($childKey, $data);
}

// this container defines no actions
return [];
}
Expand Down Expand Up @@ -408,7 +408,7 @@ public function setForm($key, $spec, $enabled = true)
if (!isset($spec['entity'])) {
$spec['entity'] = '*';
}

$this->forms[$key] = $spec;

if ($enabled) {
Expand All @@ -418,7 +418,7 @@ public function setForm($key, $spec, $enabled = true)
}
return $this;
}

/**
* Sets formulars or specifications.
*
Expand Down Expand Up @@ -448,7 +448,7 @@ public function setForms(array $forms, $enabled = true)
}
return $this;
}

/**
* Enables a formular.
*
Expand All @@ -465,11 +465,11 @@ public function enableForm($key = null)
$this->activeForms = array_keys($this->forms);
return $this;
}

if (!is_array($key)) {
$key = array($key);
}

foreach ($key as $k) {
if (false !== strpos($k, '.')) {
// this seems not to be childkey.childform but actualkey.childkey
Expand All @@ -482,7 +482,7 @@ public function enableForm($key = null)
}
}
}

return $this;
}

Expand All @@ -499,11 +499,11 @@ public function disableForm($key = null)
$this->activeForms = array();
return $this;
}

if (!is_array($key)) {
$key = array($key);
}

foreach ($key as $k) {
if (false !== strpos($k, '.')) {
list($childKey, $childForm) = explode('.', $k, 2);
Expand All @@ -519,10 +519,10 @@ function ($item) use ($key) {
return !in_array($item, $key);
}
);

return $this;
}

/**
* @param mixed $entity
* @param string $key
Expand All @@ -534,9 +534,9 @@ public function setEntity($entity, $key='*')
if (!$entity instanceof EntityInterface) {
throw new \InvalidArgumentException(sprintf('$entity must be instance of %s', EntityInterface::class));
}

$this->entities[$key] = $entity;

foreach ($this->forms as $formKey => $form) {
if (isset($form['__instance__']) && is_object($form['__instance__']) && $key == $form['entity']) {
$this->mapEntity($form['__instance__'], $entity, isset($form['property']) ? $form['property'] : $formKey);
Expand All @@ -555,7 +555,7 @@ public function getEntity($key='*')
{
return isset($this->entities[$key]) ? $this->entities[$key] : null;
}

/**
* Maps entity property to forms or child containers.
*
Expand Down Expand Up @@ -781,7 +781,7 @@ public function getActiveFormNext()
}
return $key;
}

/**
* Format an action name
*
Expand Down
18 changes: 9 additions & 9 deletions module/Core/src/Form/FileUploadFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,16 +80,16 @@ class FileUploadFactory implements FactoryInterface
* @var string|null
*/
protected $options;

public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
{
/* @var $formElementManager \Laminas\Form\FormElementManager\FormElementManagerV3Polyfill */
/* @var $formElementManager \Laminas\Form\FormElementManager\FormElement */
$formElementManager = $container->get('FormElementManager');
$options=null;
if ($this->options) {
$options = $container->get($this->options);
}

// Retrieve configuration.
if ($this->configKey) {
$config = $container->get('config');
Expand Down Expand Up @@ -117,9 +117,9 @@ public function __invoke(ContainerInterface $container, $requestedName, array $o
/* @var $element \Core\Form\Element\FileUpload */
$element = $form->get($this->fileName);
$element->setIsMultiple($this->multiple);

$user = $container->get('AuthenticationService')->getUser();

if (isset($this->config['hydrator']) && $this->config['hydrator']) {
/** @noinspection PhpUndefinedVariableInspection */
$hydrator = $container->get('HydratorManager')->get($this->config['hydrator']);
Expand Down Expand Up @@ -158,15 +158,15 @@ public function __invoke(ContainerInterface $container, $requestedName, array $o
$hydrator->addStrategy($this->fileName, $strategy);
}
}

$form->setHydrator($hydrator);
$form->setOptions(array('use_files_array' => true));

$this->configureForm($form, $options);
return $form;
}


/**
* The configuration from the FileUploadFactory configuration
*
Expand Down
18 changes: 9 additions & 9 deletions module/Core/src/Form/Service/InjectHeadscriptInitializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* @license MIT
* @copyright 2013 - 2016 Cross Solution <http://cross-solution.de>
*/

/** */
namespace Core\Form\Service;

Expand All @@ -26,29 +26,29 @@ class InjectHeadscriptInitializer implements InitializerInterface
{
public function __invoke(ContainerInterface $container, $instance)
{
/* @var $serviceLocator \Laminas\Form\FormElementManager\FormElementManagerV3Polyfill */
/* @var $serviceLocator \Laminas\Form\FormElementManager\FormElementManager */

if (!$instance instanceof HeadscriptProviderInterface) {
return;
}

$scripts = $instance->getHeadscripts();

if (!is_array($scripts) || empty($scripts)) {
return;
}

/* @var $basepath \Laminas\View\Helper\BasePath
* @var $headscript \Laminas\View\Helper\HeadScript */
$helpers = $container->get('ViewHelperManager');
$basepath = $helpers->get('basepath');
$headscript = $helpers->get('headscript');

foreach ($scripts as $script) {
$headscript->appendFile($basepath($script));
}
}

/**
* Injects scripts to the headscript view helper.
*
Expand All @@ -63,7 +63,7 @@ public function __invoke(ContainerInterface $container, $instance)
*/
public function initialize($instance, ServiceLocatorInterface $serviceLocator)
{
/* @var $serviceLocator \Laminas\Form\FormElementManager\FormElementManagerV3Polyfill */
/* @var $serviceLocator \Laminas\Form\FormElementManager\FormElementManager */

if (!$instance instanceof HeadscriptProviderInterface) {
return;
Expand Down
Loading

0 comments on commit 8c81cf6

Please sign in to comment.