Remove templating.yaml, add interfaces.

This commit is contained in:
Pol Dellaiera 2021-05-06 21:23:19 +02:00
parent 5146419e9a
commit c019da9bcf
10 changed files with 105 additions and 74 deletions

View File

@ -29,7 +29,7 @@ use Symfony\Component\Translation\Translator;
* @author Julien Fastré <julien.fastre@champs-libres.coop>
*
*/
class TranslatableStringHelper
class TranslatableStringHelper implements TranslatableStringHelperInterface
{
/**
*

View File

@ -0,0 +1,19 @@
<?php
namespace Chill\MainBundle\Templating;
interface TranslatableStringHelperInterface
{
/**
* return the string in current locale if it exists.
*
* If it does not exists; return the name in the first language available.
*
* Return a blank string if any strings are available.
* Return NULL if $translatableString is NULL
*
* @param array $translatableStrings
* @return string
*/
public function localize(array $translatableStrings);
}

View File

@ -10,6 +10,7 @@ services:
- "@translator.default"
Chill\MainBundle\Templating\TranslatableStringHelper: '@chill.main.helper.translatable_string'
Chill\MainBundle\Templating\TranslatableStringHelperInterface: Chill\MainBundle\Templating\TranslatableStringHelper
chill.main.twig.translatable_string:
class: Chill\MainBundle\Templating\TranslatableStringTwig

View File

@ -46,6 +46,11 @@ services:
tags:
- { name: kernel.event_subscriber }
Chill\PersonBundle\Templating\Entity\:
resource: '../src/Templating/Entity/'
tags:
- { name: chill.render_entity }
chill.person.security.authorization.person:
class: Chill\PersonBundle\Security\Authorization\PersonVoter
arguments:

View File

@ -1,12 +0,0 @@
services:
Chill\PersonBundle\Templating\Entity\PersonRender:
arguments:
$configAltNamesHelper: '@Chill\PersonBundle\Config\ConfigPersonAltNamesHelper'
tags:
- 'chill.render_entity'
Chill\PersonBundle\Templating\Entity\ClosingMotiveRender:
arguments:
$translatableStringHelper: '@Chill\MainBundle\Templating\TranslatableStringHelper'
tags:
- 'chill.render_entity'

View File

@ -8,7 +8,7 @@ namespace Chill\PersonBundle\Config;
*
*
*/
class ConfigPersonAltNamesHelper
class ConfigPersonAltNamesHelper implements ConfigPersonAltNamesHelperInterface
{
/**
* the raw config, directly from the container parameter

View File

@ -0,0 +1,20 @@
<?php
namespace Chill\PersonBundle\Config;
interface ConfigPersonAltNamesHelperInterface
{
/**
* Return true if at least one alt name is configured
*
* @return bool
*/
public function hasAltNames(): bool;
/**
* get the choices as key => values
*
* @return array
*/
public function getChoices(): array;
}

View File

@ -68,7 +68,6 @@ class ChillPersonExtension extends Extension implements PrependExtensionInterfac
$loader->load('services/search.yaml');
$loader->load('services/command.yaml');
$loader->load('services/form.yaml');
$loader->load('services/templating.yaml');
$loader->load('services/alt_names.yaml');
$loader->load('services/serializer.yaml');

View File

@ -4,7 +4,7 @@ namespace Chill\PersonBundle\Templating\Entity;
use Chill\MainBundle\Templating\Entity\AbstractChillEntityRender;
use Chill\PersonBundle\Entity\AccompanyingPeriod\ClosingMotive;
use Chill\MainBundle\Templating\TranslatableStringHelper;
use Chill\MainBundle\Templating\TranslatableStringHelperInterface;
/**
* Render closing motive
@ -15,12 +15,11 @@ class ClosingMotiveRender extends AbstractChillEntityRender
private CONST SEPARATOR = ' > ';
/**
*
* @var TranslatableStringHelper
* @var TranslatableStringHelperInterface
*/
private $translatableStringHelper;
public function __construct(TranslatableStringHelper $translatableStringHelper)
public function __construct(TranslatableStringHelperInterface $translatableStringHelper)
{
$this->translatableStringHelper = $translatableStringHelper;
}

View File

@ -22,7 +22,7 @@ namespace Chill\PersonBundle\Templating\Entity;
use Chill\MainBundle\Templating\Entity\AbstractChillEntityRender;
use Chill\PersonBundle\Entity\Person;
use Chill\PersonBundle\Config\ConfigPersonAltNamesHelper;
use Chill\PersonBundle\Config\ConfigPersonAltNamesHelperInterface;
/**
* Render a Person
@ -32,11 +32,11 @@ class PersonRender extends AbstractChillEntityRender
{
/**
*
* @var ConfigPersonAltNamesHelper
* @var ConfigPersonAltNamesHelperInterface
*/
protected $configAltNamesHelper;
public function __construct(ConfigPersonAltNamesHelper $configAltNamesHelper)
public function __construct(ConfigPersonAltNamesHelperInterface $configAltNamesHelper)
{
$this->configAltNamesHelper = $configAltNamesHelper;
}