Commit 6809c5cd authored by Jean-Philippe Metivier's avatar Jean-Philippe Metivier
Browse files

ViewHelper pour récupérer la valeur d'un parametre

parent 02ba7185
Loading
Loading
Loading
Loading
Loading
+11 −1
Original line number Diff line number Diff line
@@ -9,6 +9,8 @@ use UnicaenParametre\Form\Parametre\ParametreFormFactory;
use UnicaenParametre\Provider\Privilege\ParametrePrivileges;
use UnicaenParametre\Service\Parametre\ParametreService;
use UnicaenParametre\Service\Parametre\ParametreServiceFactory;
use UnicaenParametre\View\Helper\ParametreValueViewHelper;
use UnicaenParametre\View\Helper\ParametreValueViewHelperFactory;
use UnicaenPrivilege\Guard\PrivilegeController;
use Laminas\Router\Http\Literal;
use Laminas\Router\Http\Segment;
@@ -122,6 +124,14 @@ return [
        'factories' => [
            ParametreService::class => ParametreServiceFactory::class,
        ],
    ]
    ],

    'view_helpers' => [
        'factories' => [
            ParametreValueViewHelper::class => ParametreValueViewHelperFactory::class,
        ],
        'aliases' => [
            'parametreValue' => ParametreValueViewHelper::class,
        ],
    ],
];
 No newline at end of file
+16 −0
Original line number Diff line number Diff line
<?php

namespace UnicaenParametre\View\Helper;

use Laminas\View\Helper\AbstractHelper;
use UnicaenParametre\Service\Parametre\ParametreServiceAwareTrait;

class ParametreValueViewHelper extends AbstractHelper
{
    use ParametreServiceAwareTrait;

    public function __invoke(string $categorieCode, string $parametreCode, array $options = []) : string
    {
        return "".$this->getParametreService()->getValeurForParametre($categorieCode, $parametreCode);
    }
}
 No newline at end of file
+27 −0
Original line number Diff line number Diff line
<?php

namespace UnicaenParametre\View\Helper;

use Laminas\View\Helper\AbstractHelper;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\ContainerInterface;
use Psr\Container\NotFoundExceptionInterface;
use UnicaenParametre\Service\Parametre\ParametreService;
use UnicaenParametre\Service\Parametre\ParametreServiceAwareTrait;

class ParametreValueViewHelperFactory
{
    /**
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     */
    public function __invoke(ContainerInterface $container): ParametreValueViewHelper
    {
        /** @var ParametreService $parametreService */
        $parametreService = $container->get(ParametreService::class);

        $helper = new ParametreValueViewHelper();
        $helper->setParametreService($parametreService);
        return $helper;
    }
}
 No newline at end of file