mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-12 13:24:25 +00:00
remove accompanying period if not used
This commit is contained in:
parent
c21b87b9c6
commit
b4801734d3
@ -5,6 +5,7 @@ namespace Chill\PersonBundle;
|
|||||||
use Symfony\Component\HttpKernel\Bundle\Bundle;
|
use Symfony\Component\HttpKernel\Bundle\Bundle;
|
||||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||||
use Chill\PersonBundle\Widget\PersonListWidgetFactory;
|
use Chill\PersonBundle\Widget\PersonListWidgetFactory;
|
||||||
|
use Chill\PersonBundle\DependencyInjection\CompilerPass\AccompanyingPeriodTimelineCompilerPass;
|
||||||
|
|
||||||
class ChillPersonBundle extends Bundle
|
class ChillPersonBundle extends Bundle
|
||||||
{
|
{
|
||||||
@ -14,5 +15,7 @@ class ChillPersonBundle extends Bundle
|
|||||||
|
|
||||||
$container->getExtension('chill_main')
|
$container->getExtension('chill_main')
|
||||||
->addWidgetFactory(new PersonListWidgetFactory());
|
->addWidgetFactory(new PersonListWidgetFactory());
|
||||||
|
|
||||||
|
$container->addCompilerPass(new AccompanyingPeriodTimelineCompilerPass());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -73,7 +73,14 @@ class ChillPersonExtension extends Extension implements PrependExtensionInterfac
|
|||||||
$container->setParameter('chill_person.person_fields', $config);
|
$container->setParameter('chill_person.person_fields', $config);
|
||||||
|
|
||||||
foreach ($config as $key => $value) {
|
foreach ($config as $key => $value) {
|
||||||
$container->setParameter('chill_person.person_fields.'.$key, $value);
|
switch($key) {
|
||||||
|
case 'accompanying_period':
|
||||||
|
$container->setParameter('chill_person.accompanying_period', $value);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
$container->setParameter('chill_person.person_fields.'.$key, $value);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -0,0 +1,66 @@
|
|||||||
|
<?php
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2018 Champs-Libres <info@champs-libres.coop>
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
namespace Chill\PersonBundle\DependencyInjection\CompilerPass;
|
||||||
|
|
||||||
|
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||||
|
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove services which add AccompanyingPeriod to timeline if
|
||||||
|
* accompanying_periods are set to `hidden`
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
class AccompanyingPeriodTimelineCompilerPass implements CompilerPassInterface
|
||||||
|
{
|
||||||
|
public function process(ContainerBuilder $container)
|
||||||
|
{
|
||||||
|
// remove services when accompanying period are hidden
|
||||||
|
if ($container->getParameter('chill_person.accompanying_period') !== 'hidden') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$definitions = [
|
||||||
|
'chill.person.timeline.accompanying_period_opening',
|
||||||
|
'chill.person.timeline.accompanying_period_closing'
|
||||||
|
];
|
||||||
|
|
||||||
|
foreach($definitions as $definition) {
|
||||||
|
$container
|
||||||
|
->removeDefinition($definition)
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
|
$definition = $container->getDefinition('chill.main.timeline_builder');
|
||||||
|
|
||||||
|
// we have to remove all methods call, and re-add them if not linked
|
||||||
|
// to this service
|
||||||
|
$calls = $definition->getMethodCalls();
|
||||||
|
|
||||||
|
foreach($calls as list($method, $arguments)) {
|
||||||
|
if ($method !== 'addProvider') {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$definition->removeMethodCall('addProvider');
|
||||||
|
|
||||||
|
if (FALSE === \in_array($arguments[1], $definitions)) {
|
||||||
|
$definition->addMethodCall($method, $arguments);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -74,6 +74,7 @@ class Configuration implements ConfigurationInterface
|
|||||||
->append($this->addFieldNode('marital_status'))
|
->append($this->addFieldNode('marital_status'))
|
||||||
->append($this->addFieldNode('spoken_languages'))
|
->append($this->addFieldNode('spoken_languages'))
|
||||||
->append($this->addFieldNode('address'))
|
->append($this->addFieldNode('address'))
|
||||||
|
->append($this->addFieldNode('accompanying_period'))
|
||||||
->end() //children for 'person_fields', parent = array 'person_fields'
|
->end() //children for 'person_fields', parent = array 'person_fields'
|
||||||
->end() // person_fields, parent = children of root
|
->end() // person_fields, parent = children of root
|
||||||
->end() // children of 'root', parent = root
|
->end() // children of 'root', parent = root
|
||||||
@ -87,11 +88,20 @@ class Configuration implements ConfigurationInterface
|
|||||||
{
|
{
|
||||||
$tree = new TreeBuilder();
|
$tree = new TreeBuilder();
|
||||||
$node = $tree->root($key, 'enum');
|
$node = $tree->root($key, 'enum');
|
||||||
|
|
||||||
|
switch($key) {
|
||||||
|
case 'accompanying_period':
|
||||||
|
$info = "If the accompanying periods are shown";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
$info = "If the field $key must be shown";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
$node
|
$node
|
||||||
->values(array('hidden', 'visible'))
|
->values(array('hidden', 'visible'))
|
||||||
->defaultValue('visible')
|
->defaultValue('visible')
|
||||||
->info("If the field $key must be shown")
|
->info($info)
|
||||||
->end();
|
->end();
|
||||||
|
|
||||||
return $node;
|
return $node;
|
||||||
|
84
Menu/PersonMenuBuilder.php
Normal file
84
Menu/PersonMenuBuilder.php
Normal file
@ -0,0 +1,84 @@
|
|||||||
|
<?php
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2018 Champs-Libres <info@champs-libres.coop>
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
namespace Chill\PersonBundle\Menu;
|
||||||
|
|
||||||
|
use Chill\MainBundle\Routing\LocalMenuBuilderInterface;
|
||||||
|
use Knp\Menu\MenuItem;
|
||||||
|
use Symfony\Component\Translation\TranslatorInterface;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add menu entrie to person menu.
|
||||||
|
*
|
||||||
|
* Menu entries added :
|
||||||
|
*
|
||||||
|
* - person details ;
|
||||||
|
* - accompanying period (if `visible`)
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
class PersonMenuBuilder implements LocalMenuBuilderInterface
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @var string 'visible' or 'hidden'
|
||||||
|
*/
|
||||||
|
protected $showAccompanyingPeriod;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @var TranslatorInterface
|
||||||
|
*/
|
||||||
|
protected $translator;
|
||||||
|
|
||||||
|
public function __construct(
|
||||||
|
$showAccompanyingPeriod,
|
||||||
|
TranslatorInterface $translator
|
||||||
|
) {
|
||||||
|
$this->showAccompanyingPeriod = $showAccompanyingPeriod;
|
||||||
|
$this->translator = $translator;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function buildMenu($menuId, MenuItem $menu, array $parameters)
|
||||||
|
{
|
||||||
|
$menu->addChild($this->translator->trans('Person details'), [
|
||||||
|
'route' => 'chill_person_view',
|
||||||
|
'routeParameters' => [
|
||||||
|
'person_id' => $parameters['person']->getId()
|
||||||
|
]
|
||||||
|
])
|
||||||
|
->setExtras([
|
||||||
|
'order' => 50
|
||||||
|
]);
|
||||||
|
|
||||||
|
if ($this->showAccompanyingPeriod === 'visible') {
|
||||||
|
$menu->addChild($this->translator->trans('Accompanying period list'), [
|
||||||
|
'route' => 'chill_person_accompanying_period_list',
|
||||||
|
'routeParameters' => [
|
||||||
|
'person_id' => $parameters['person']->getId()
|
||||||
|
]
|
||||||
|
])
|
||||||
|
->setExtras([
|
||||||
|
'order' => 100
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getMenuIds(): array
|
||||||
|
{
|
||||||
|
return [ 'person' ];
|
||||||
|
}
|
||||||
|
}
|
@ -1,11 +1,6 @@
|
|||||||
chill_person_view:
|
chill_person_view:
|
||||||
path: /{_locale}/person/{person_id}/general
|
path: /{_locale}/person/{person_id}/general
|
||||||
defaults: { _controller: ChillPersonBundle:Person:view }
|
defaults: { _controller: ChillPersonBundle:Person:view }
|
||||||
options:
|
|
||||||
menus:
|
|
||||||
person:
|
|
||||||
order: 50
|
|
||||||
label: Person details
|
|
||||||
|
|
||||||
chill_person_general_edit:
|
chill_person_general_edit:
|
||||||
path: /{_locale}/person/{person_id}/general/edit
|
path: /{_locale}/person/{person_id}/general/edit
|
||||||
@ -39,11 +34,6 @@ chill_person_search:
|
|||||||
chill_person_accompanying_period_list:
|
chill_person_accompanying_period_list:
|
||||||
path: /{_locale}/person/{person_id}/accompanying-period
|
path: /{_locale}/person/{person_id}/accompanying-period
|
||||||
defaults: { _controller: ChillPersonBundle:AccompanyingPeriod:list }
|
defaults: { _controller: ChillPersonBundle:AccompanyingPeriod:list }
|
||||||
options:
|
|
||||||
menus:
|
|
||||||
person:
|
|
||||||
order: 100
|
|
||||||
label: Accompanying period list
|
|
||||||
|
|
||||||
chill_person_accompanying_period_create:
|
chill_person_accompanying_period_create:
|
||||||
path: /{_locale}/person/{person_id}/accompanying-period/create
|
path: /{_locale}/person/{person_id}/accompanying-period/create
|
||||||
|
@ -4,3 +4,10 @@ services:
|
|||||||
$authorizationChecker: '@Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface'
|
$authorizationChecker: '@Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface'
|
||||||
tags:
|
tags:
|
||||||
- { name: 'chill.menu_builder' }
|
- { name: 'chill.menu_builder' }
|
||||||
|
|
||||||
|
Chill\PersonBundle\Menu\PersonMenuBuilder:
|
||||||
|
arguments:
|
||||||
|
$showAccompanyingPeriod: '%chill_person.accompanying_period%'
|
||||||
|
$translator: '@Symfony\Component\Translation\TranslatorInterface'
|
||||||
|
tags:
|
||||||
|
- { name: 'chill.menu_builder' }
|
||||||
|
@ -42,7 +42,7 @@ Chill\PersonBundle\Entity\Person:
|
|||||||
message: 'Invalid phone number: it should begin with the international prefix starting with "+", hold only digits and be smaller than 20 characters. Ex: +33123456789'
|
message: 'Invalid phone number: it should begin with the international prefix starting with "+", hold only digits and be smaller than 20 characters. Ex: +33123456789'
|
||||||
- Chill\MainBundle\Validation\Constraint\PhonenumberConstraint:
|
- Chill\MainBundle\Validation\Constraint\PhonenumberConstraint:
|
||||||
type: landline
|
type: landline
|
||||||
groups: [ general ]
|
groups: [ general, creation ]
|
||||||
mobilenumber:
|
mobilenumber:
|
||||||
- Regex:
|
- Regex:
|
||||||
pattern: '/^([\+{1}])([0-9\s*]{4,20})$/'
|
pattern: '/^([\+{1}])([0-9\s*]{4,20})$/'
|
||||||
@ -50,7 +50,7 @@ Chill\PersonBundle\Entity\Person:
|
|||||||
message: 'Invalid phone number: it should begin with the international prefix starting with "+", hold only digits and be smaller than 20 characters. Ex: +33623456789'
|
message: 'Invalid phone number: it should begin with the international prefix starting with "+", hold only digits and be smaller than 20 characters. Ex: +33623456789'
|
||||||
- Chill\MainBundle\Validation\Constraint\PhonenumberConstraint:
|
- Chill\MainBundle\Validation\Constraint\PhonenumberConstraint:
|
||||||
type: mobile
|
type: mobile
|
||||||
groups: [ general ]
|
groups: [ general, creation ]
|
||||||
|
|
||||||
|
|
||||||
constraints:
|
constraints:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user