I have a laminas form wich contains a fieldset. In this fieldset, I have a custom select Element wich is populate from database with a where clause depending on parameter passed to my fieldset. However, when I use my custom Select, I get this error message <<Argument 1 passed to Laminas\ServiceManager\ServiceManager::Laminas\ServiceManager{closure}() must be of the type string, object given, called in…>>.
I post my code below : My fieldset here :
<?php
/**
* @module Commun
* @subpackage Form\Admin
* @author Samuel NANGUI <nanguisamuel@gmail.com>
* @copyright Copyright (c) 2020 Nslabs
*/
namespace Commun\Form\Modules\Application\Fieldset;
use Commun\Model\Entity\RapportEffet;
use Laminas\InputFilter\InputFilterProviderInterface;
use Laminas\Hydrator\ReflectionHydrator;
use Laminas\Filter\StripTags;
use Laminas\Filter\StringTrim;
use Commun\Form\CommunFormFieldset;
use Commun\Form\SelectOptions\EffetsProjetSelect;
class EffetRapportFieldset extends CommunFormFieldset implements InputFilterProviderInterface
{
private $mapper;
private $inputFilter;
private $params;
public function __construct($mappers=[],$params=[], $options = [])
{
$this->mapper = $mappers;
$this->params = $params;
parent::__construct($this->mapper,'EffetRapportForm',$options);
$this->setHydrator(new ReflectionHydrator());
$this->setObject(new RapportEffet());
}
public function init() {
//parent::init();
//var_dump($this->params);
//$idProjet = $this->params;
//$optionsEffetCadreLogique = $this->mapper['effetProjet']->getOptions('idEffetProjet','libelleEffet','Selectionner',['idProjet' => $idProjet],['libelleEffet']);
//$this->addSelect('idEffetProjet', 'Intitule de l\'effet',[],['class' => 'form-control'],'champ-requis');
$mySelect = $this->getFormFactory()->getFormElementManager()->get(EffetsProjetSelect::class, ['params' => $this->params]);
//$this->addSelectFromTable('idEffetProjet','Intitule de l\'effet', $mySelect,['class' => 'form-control champ-affiche'],'champ-requis');
$this->add([
'name' => 'idEffetProjet',
'type' => $mySelect,
'options' => [
'label' => 'Intitule de l\'effet',
'label_attributes' => [
'class' => 'form-control champ-affiche'
],
],
'attributes' => 'champ-requis',
]);
$this->addText('valeurReference','Valeur de référence (a)',NULL,['class' => 'form-control champ_decimal champ-affiche champ_valeur_reference'],'champ-requis');
$this->addText('valeurRecente','Valeur la plus récente (b)',NULL,['class' => 'form-control champ_decimal champ_valeur_recente'],'champ-requis');
$this->addText('cibleFinale','Cible finale (c)',NULL,['class' => 'form-control champ_decimal champ-calcule champ_valeur_cible'],'champ-requis');
$this->addText('progresRealisation','Progrès vers la réalisation de la cible (% de réalisation) (d=b/c)',NULL,['class' => 'form-control champ_decimal champ-affiche champ_valeur_progres'],'champ-requis');
$this->addTextarea('evaluation', 'Évaluation', NULL, ['class' => 'form-control','rows' => 3]);
}
/**
* @return array
*/
public function getInputFilterSpecification()
{
return [
];
}
}
My custom Select here :
<?php
/**
* @module Commun
* @subpackage Form\Admin
* @author Samuel NANGUI <nanguisamuel@gmail.com>
* @copyright Copyright (c) 2021 Nslabs
*/
namespace Commun\Form\SelectOptions;
use Laminas\Form\Element\Select;
class EffetsProjetSelect extends Select
{
private $repository;
private $params;
public function __construct($repository,$params)
{
//parent::__construct($name, $options);
$this->repository = $repository;
$this->params = $params;
}
/**
* Initialize the element
*
* @return void
*/
public function init() {
$idProjet=$this->params;
//var_dump($idProjet);
$options = $this->repository->getOptions('idEffetProjet','libelleEffet','Sélectionner',['idProjet' => $idProjet],NULL);
//$options = $this->repository->getOptions('idEffetProjet','libelleEffet','Sélectionner',NULL,['libelleEffet']);
$this->setValueOptions($options);
}
}
The factory for my custom Select
<?php
/**
* @module Commun
* @subpackage Form
* @author Samuel NANGUI <nanguisamuel@gmail.com>
* @copyright Copyright (c) 2020 Nslabs
*/
namespace Commun\Factory\Form\SelectOptions;
use Interop\Container\ContainerInterface;
use Laminas\ServiceManager\Factory\FactoryInterface;
use Commun\Form\SelectOptions\EffetsProjetSelect;
class EffetsProjetSelectFactory implements FactoryInterface
{
public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
{
$params = $options['params'] ?? [];
unset($options['params']);
$mapper=$container->get('TEFFETPROJET');
return new EffetsProjetSelect($mapper,$params);
}
}