From 57a8b49f49fb7b430f89a44462accff71c2f20c6 Mon Sep 17 00:00:00 2001 From: Mathieu Jaumotte Date: Wed, 28 Jul 2021 11:39:27 +0200 Subject: [PATCH] entity render: options, html classes, corrections note: span.chill-entity tag is replaced by section.chill-entity tag. because some cases are not valid html : * span.chill-entity > div * span.badge > div.chill-entity --- .../Entity/AbstractChillEntityRender.php | 4 +- .../public/chill/scss/render_box.scss | 21 ++++--- .../views/AccompanyingCourse/index.html.twig | 32 ++++++---- .../Resources/views/Entity/person.html.twig | 63 +++++++++---------- .../views/Person/list_with_period.html.twig | 2 +- .../Templating/Entity/PersonRender.php | 24 ++++--- .../Resources/public/chill/thirdparty.scss | 22 ++++--- .../views/Entity/thirdparty.html.twig | 50 ++++++++------- .../Templating/Entity/ThirdPartyRender.php | 35 ++++++----- 9 files changed, 141 insertions(+), 112 deletions(-) diff --git a/src/Bundle/ChillMainBundle/Templating/Entity/AbstractChillEntityRender.php b/src/Bundle/ChillMainBundle/Templating/Entity/AbstractChillEntityRender.php index d88c4b86f..c9b06a883 100644 --- a/src/Bundle/ChillMainBundle/Templating/Entity/AbstractChillEntityRender.php +++ b/src/Bundle/ChillMainBundle/Templating/Entity/AbstractChillEntityRender.php @@ -28,11 +28,11 @@ abstract class AbstractChillEntityRender implements ChillEntityRenderInterface { protected function getDefaultOpeningBox($classSuffix): string { - return ''; + return '
'; } protected function getDefaultClosingBox(): string { - return ''; + return '
'; } } diff --git a/src/Bundle/ChillPersonBundle/Resources/public/chill/scss/render_box.scss b/src/Bundle/ChillPersonBundle/Resources/public/chill/scss/render_box.scss index 7f1773710..078f96253 100644 --- a/src/Bundle/ChillPersonBundle/Resources/public/chill/scss/render_box.scss +++ b/src/Bundle/ChillPersonBundle/Resources/public/chill/scss/render_box.scss @@ -1,9 +1,14 @@ -div.chill-entity { - &.person { - &.label { - h3.denomination { - font-size: 1.3em; - font-weight: 700; +section.chill-entity { + // have no effect for render label, row, bloc + display: inline; + + &.entity-person { + div.entity-label { + div.denomination { + &.h3 { + font-size: 1.3em; + font-weight: 700; + } a { text-decoration: none; } @@ -14,7 +19,7 @@ div.chill-entity { } p.moreinfo {} } - &.row {} - &.bloc {} + div.entity-row {} + div.entity-bloc {} } } diff --git a/src/Bundle/ChillPersonBundle/Resources/views/AccompanyingCourse/index.html.twig b/src/Bundle/ChillPersonBundle/Resources/views/AccompanyingCourse/index.html.twig index 03f5bb379..ce1dbe56d 100644 --- a/src/Bundle/ChillPersonBundle/Resources/views/AccompanyingCourse/index.html.twig +++ b/src/Bundle/ChillPersonBundle/Resources/views/AccompanyingCourse/index.html.twig @@ -226,22 +226,30 @@ {% else %}
{% for r in accompanyingCourse.resources %} -
- {% if r.person %} - {{ r.person|chill_entity_render_box({ - 'display': 'bloc', 'addLink': true, 'addEntity': true, 'addInfo': true - }) }} + {# TEST + {{ r.person|chill_entity_render_box({ + 'render': 'label', 'addLink': true, 'addInfo': true, 'hLevel': '1' + }) }} - {% endif %} - {% if r.thirdParty %} + + {{ r.person|chill_entity_render_box({'render': 'raw'}) }} + + #} - {{ r.thirdParty|chill_entity_render_box({ - 'display': 'bloc', 'addLink': true, 'addEntity': true, 'addInfo': true - }) }} +
+ {% if r.person %} + {{ r.person|chill_entity_render_box({ + 'render': 'bloc', 'addLink': true, 'addEntity': true, 'addInfo': true + }) }} + {% endif %} + {% if r.thirdParty %} + {{ r.thirdParty|chill_entity_render_box({ + 'render': 'bloc', 'addLink': true, 'addEntity': true, 'addInfo': true + }) }} + {% endif %} +
- {% endif %} -
{% endfor %}
{% endif %} diff --git a/src/Bundle/ChillPersonBundle/Resources/views/Entity/person.html.twig b/src/Bundle/ChillPersonBundle/Resources/views/Entity/person.html.twig index a7ffc1775..3368d91af 100644 --- a/src/Bundle/ChillPersonBundle/Resources/views/Entity/person.html.twig +++ b/src/Bundle/ChillPersonBundle/Resources/views/Entity/person.html.twig @@ -1,56 +1,53 @@ {# Template to render a person + * render [raw|label|row|bloc] OPTIONS - * display [raw|label|row|bloc] * addAltNames bool * addLink bool * addEntity bool * addInfo bool + * hLevel integer #} -{% macro raw(person, addAltNames) %} +{% macro raw(person, options) %} {{ person.firstName }} {{ person.lastName }} - {%- if addAltNames -%} + {%- if options['addAltNames'] -%} {%- for n in person.altNames -%} {%- if loop.first -%}({% else %} {%- endif -%} - - {{- n.label -}} - + + {{- n.label -}} + {%- if loop.last -%}){%- endif -%} {%- endfor -%} {%- endif -%} {% endmacro raw %} -{% macro label(person, addLink, addAltNames, addEntity, addInfo) %} -
-

- {%- if addLink and is_granted('CHILL_PERSON_SEE', person) -%} +{% macro label(person, options) %} +
+ +
+ {%- if options['addLink'] and is_granted('CHILL_PERSON_SEE', person) -%} - {{ _self.raw(person, addAltNames) }} + {{ _self.raw(person, options) }} {%- else -%} - {{ _self.raw(person, addAltNames) }} + {{ _self.raw(person, options) }} {%- endif -%} - {%- if addEntity -%} + {%- if options['addEntity'] -%} {{ 'Person'|trans }} {%- endif -%} -

- {%- if addInfo -%} - {% set born = (person.gender == 'woman') ? 'née le ': 'né le ' %} +
+ {%- if options['addInfo'] -%} {% set gender = (person.gender == 'woman') ? 'fa-venus' : (person.gender == 'man') ? 'fa-mars' : 'fa-neuter' %} {% set genderTitle = (person.gender == 'woman') ? 'woman' : (person.gender == 'man') ? 'man' : 'neuter' %}

- {{ born|trans }} -

{%- endif -%} {#- tricks to remove easily whitespace after template -#} @@ -58,25 +55,25 @@ {% endmacro label %} -{%- if display == 'raw' -%} - {{ _self.raw(person, addAltNames) }} +{%- if render == 'raw' -%} + {{ _self.raw(person, options) }} {%- endif -%} -{%- if display == 'label' -%} - {{ _self.label(person, addLink, addAltNames, addEntity, addInfo) }} +{%- if render == 'label' -%} + {{ _self.label(person, options) }} {%- endif -%} -{%- if display == 'row' -%} -
- {{ _self.label(person, addLink, addAltNames, addEntity, addInfo) }} +{%- if render == 'row' -%} +
+ {{ _self.label(person, options) }}
{%- endif -%} -{%- if display == 'bloc' -%} -
+{%- if render == 'bloc' -%} +
- {{ _self.label(person, addLink, addAltNames, addEntity, addInfo) }} + {{ _self.label(person, options) }}
    diff --git a/src/Bundle/ChillPersonBundle/Resources/views/Person/list_with_period.html.twig b/src/Bundle/ChillPersonBundle/Resources/views/Person/list_with_period.html.twig index 91a905cc1..5c0d7da78 100644 --- a/src/Bundle/ChillPersonBundle/Resources/views/Person/list_with_period.html.twig +++ b/src/Bundle/ChillPersonBundle/Resources/views/Person/list_with_period.html.twig @@ -46,7 +46,7 @@
    {{ person|chill_entity_render_box({ - 'display': 'label', 'addLink': true, 'addInfo': true + 'render': 'label', 'addLink': true, 'addInfo': true }) }}
    diff --git a/src/Bundle/ChillPersonBundle/Templating/Entity/PersonRender.php b/src/Bundle/ChillPersonBundle/Templating/Entity/PersonRender.php index 353d05ecf..1eea36cdf 100644 --- a/src/Bundle/ChillPersonBundle/Templating/Entity/PersonRender.php +++ b/src/Bundle/ChillPersonBundle/Templating/Entity/PersonRender.php @@ -52,16 +52,22 @@ class PersonRender extends AbstractChillEntityRender */ public function renderBox($person, array $options): string { - return $this->engine->render('@ChillPerson/Entity/person.html.twig', - [ + $params = [ + 'addAltNames' => $this->configAltNamesHelper->hasAltNames(), + 'addLink' => $options['addLink'] ?? false, + 'addEntity' => $options['addEntity'] ?? false, + 'addInfo' => $options['addInfo'] ?? false, + 'hLevel' => $options['hLevel'] ?? 3, + ]; + dump($params); + return + $this->getDefaultOpeningBox('person') . + $this->engine->render('@ChillPerson/Entity/person.html.twig', [ 'person' => $person, - 'addAltNames' => $this->configAltNamesHelper->hasAltNames(), - 'addLink' => $options['addLink'] ?? false, - 'addEntity' => $options['addEntity'] ?? false, - 'addInfo' => $options['addInfo'] ?? false, - 'display' => $options['display'] ?? 'raw' - ] - ); + 'render' => $options['render'] ?? 'raw', + 'options' => $params + ]) . + $this->getDefaultClosingBox(); } /** diff --git a/src/Bundle/ChillThirdPartyBundle/Resources/public/chill/thirdparty.scss b/src/Bundle/ChillThirdPartyBundle/Resources/public/chill/thirdparty.scss index 2efe06c5e..454a5b106 100644 --- a/src/Bundle/ChillThirdPartyBundle/Resources/public/chill/thirdparty.scss +++ b/src/Bundle/ChillThirdPartyBundle/Resources/public/chill/thirdparty.scss @@ -1,9 +1,11 @@ -div.chill-entity { - &.thirdparty { - &.label { - h3.denomination { - font-size: 1.3em; - font-weight: 700; +section.chill-entity { + &.entity-thirdparty { + div.entity-label { + div.denomination { + &.h3 { + font-size: 1.3em; + font-weight: 700; + } a { text-decoration: none; } @@ -12,10 +14,12 @@ div.chill-entity { margin-left: 0.3em; } } - p.moreinfo {} + p.moreinfo { + span.company, span.acronym {} + } } - &.row {} - &.bloc {} + div.entity-row {} + div.entity-bloc {} /* diff --git a/src/Bundle/ChillThirdPartyBundle/Resources/views/Entity/thirdparty.html.twig b/src/Bundle/ChillThirdPartyBundle/Resources/views/Entity/thirdparty.html.twig index 3f665aa26..cdcf53a0b 100644 --- a/src/Bundle/ChillThirdPartyBundle/Resources/views/Entity/thirdparty.html.twig +++ b/src/Bundle/ChillThirdPartyBundle/Resources/views/Entity/thirdparty.html.twig @@ -1,36 +1,44 @@ {# Template to render a thirdparty + * render [raw|label|row|bloc] OPTIONS - * display [raw|label|row|bloc] * with_valid_from bool * addAltNames bool * addLink bool * addEntity bool * addInfo bool + * hLevel integer #} -{% macro raw(thirdparty) %} +{% macro raw(thirdparty, options) %} {{ thirdparty.name }} {% endmacro raw %} -{% macro label(thirdparty, addLink, addEntity, addInfo, options) %} -
    +{% macro label(thirdparty, options) %} +
    -

    - {%- if addLink and is_granted('CHILL_3PARTY_3PARTY_SHOW', thirdparty) -%} +
    + {%- if options['addLink'] and is_granted('CHILL_3PARTY_3PARTY_SHOW', thirdparty) -%} - {{ _self.raw(thirdparty) }} + {{ _self.raw(thirdparty, options) }} {%- else -%} - {{ _self.raw(thirdparty) }} + {{ _self.raw(thirdparty, options) }} {%- endif -%} - {%- if addEntity -%} + {%- if options['addEntity'] -%} {{ 'Third party'|trans }} {%- endif -%} -

    +
    + {%- if options['addInfo'] -%} +

    {# + {{ thirdparty.nameCompany }} + {{ thirdparty.acronym }} + #} plus d'infos +

    + {%- endif -%} {# AVANT
    - {{ _self.raw(thirdparty) }} + {{ _self.raw(thirdparty, options) }}
    {% for type in thirdparty.type %} @@ -77,25 +85,25 @@ {%- if true -%}
    {%- endif -%} {% endmacro label %} -{%- if display == 'raw' -%} - {{ _self.raw(thirdparty) }} +{%- if render == 'raw' -%} + {{ _self.raw(thirdparty, options) }} {%- endif -%} -{%- if display == 'label' -%} - {{ _self.label(thirdparty, addLink, addEntity, addInfo, options) }} +{%- if render == 'label' -%} + {{ _self.label(thirdparty, options) }} {%- endif -%} -{%- if display == 'row' -%} -
    - {{ _self.label(thirdparty, addLink, addEntity, addInfo, options) }} +{%- if render == 'row' -%} +
    + {{ _self.label(thirdparty, options) }}
    {%- endif -%} -{%- if display == 'bloc' -%} -
    +{%- if render == 'bloc' -%} +
    - {{ _self.label(thirdparty, addLink, addEntity, addInfo, options) }} + {{ _self.label(thirdparty, options) }}
      diff --git a/src/Bundle/ChillThirdPartyBundle/Templating/Entity/ThirdPartyRender.php b/src/Bundle/ChillThirdPartyBundle/Templating/Entity/ThirdPartyRender.php index aea8cd45a..00f7effd3 100644 --- a/src/Bundle/ChillThirdPartyBundle/Templating/Entity/ThirdPartyRender.php +++ b/src/Bundle/ChillThirdPartyBundle/Templating/Entity/ThirdPartyRender.php @@ -22,7 +22,7 @@ namespace Chill\ThirdPartyBundle\Templating\Entity; use Chill\MainBundle\Templating\Entity\AbstractChillEntityRender; use Chill\ThirdPartyBundle\Entity\ThirdParty; -use Symfony\Bridge\Twig\TwigEngine; +use Symfony\Component\Templating\EngineInterface; /** * @@ -30,15 +30,12 @@ use Symfony\Bridge\Twig\TwigEngine; */ class ThirdPartyRender extends AbstractChillEntityRender { - /** - * - * @var TwigEngine - */ - protected $templating; - public function __construct(TwigEngine $templating) + protected EngineInterface $engine; + + public function __construct(EngineInterface $engine) { - $this->templating = $templating; + $this->engine = $engine; } /** @@ -49,17 +46,21 @@ class ThirdPartyRender extends AbstractChillEntityRender */ public function renderBox($entity, array $options): string { + $params = [ + 'with_valid_from' => $options['with_valid_from'] ?? true, + 'addLink' => $options['addLink'] ?? false, + 'addEntity' => $options['addEntity'] ?? false, + 'addInfo' => $options['addInfo'] ?? false, + 'hLevel' => $options['hLevel'] ?? 3, + ]; + return - $this->getDefaultOpeningBox('_3party'). - $this->templating->render('@ChillThirdParty/Entity/thirdparty.html.twig', [ + $this->getDefaultOpeningBox('thirdparty') . + $this->engine->render('@ChillThirdParty/Entity/thirdparty.html.twig', [ 'thirdparty' => $entity, - 'with_valid_from' => $options['with_valid_from'] ?? true, - 'addLink' => $options['addLink'] ?? false, - 'addEntity' => $options['addEntity'] ?? false, - 'addInfo' => $options['addInfo'] ?? false, - 'display' => $options['display'] ?? 'raw', - 'options' => $options - ]). + 'render' => $options['render'] ?? 'raw', + 'options' => $params + ]) . $this->getDefaultClosingBox(); }