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
This commit is contained in:
Mathieu Jaumotte 2021-07-28 11:39:27 +02:00
parent df3d32c653
commit 57a8b49f49
9 changed files with 141 additions and 112 deletions

View File

@ -28,11 +28,11 @@ abstract class AbstractChillEntityRender implements ChillEntityRenderInterface
{ {
protected function getDefaultOpeningBox($classSuffix): string protected function getDefaultOpeningBox($classSuffix): string
{ {
return '<span class="chill-entity chill-entity__'.$classSuffix.'">'; return '<section class="chill-entity entity-'.$classSuffix.'">';
} }
protected function getDefaultClosingBox(): string protected function getDefaultClosingBox(): string
{ {
return '</span>'; return '</section>';
} }
} }

View File

@ -1,9 +1,14 @@
div.chill-entity { section.chill-entity {
&.person { // have no effect for render label, row, bloc
&.label { display: inline;
h3.denomination {
font-size: 1.3em; &.entity-person {
font-weight: 700; div.entity-label {
div.denomination {
&.h3 {
font-size: 1.3em;
font-weight: 700;
}
a { a {
text-decoration: none; text-decoration: none;
} }
@ -14,7 +19,7 @@ div.chill-entity {
} }
p.moreinfo {} p.moreinfo {}
} }
&.row {} div.entity-row {}
&.bloc {} div.entity-bloc {}
} }
} }

View File

@ -226,22 +226,30 @@
{% else %} {% else %}
<div class="flex-bloc"> <div class="flex-bloc">
{% for r in accompanyingCourse.resources %} {% for r in accompanyingCourse.resources %}
<div class="item-bloc">
{% if r.person %}
{{ r.person|chill_entity_render_box({ {# TEST
'display': 'bloc', 'addLink': true, 'addEntity': true, 'addInfo': true {{ r.person|chill_entity_render_box({
}) }} 'render': 'label', 'addLink': true, 'addInfo': true, 'hLevel': '1'
}) }}
{% endif %} <span class="badge bg-primary">
{% if r.thirdParty %} {{ r.person|chill_entity_render_box({'render': 'raw'}) }}
</span>
#}
{{ r.thirdParty|chill_entity_render_box({ <div class="item-bloc">
'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 %}
</div>
{% endif %}
</div>
{% endfor %} {% endfor %}
</div> </div>
{% endif %} {% endif %}

View File

@ -1,56 +1,53 @@
{# {#
Template to render a person Template to render a person
* render [raw|label|row|bloc]
OPTIONS OPTIONS
* display [raw|label|row|bloc]
* addAltNames bool * addAltNames bool
* addLink bool * addLink bool
* addEntity bool * addEntity bool
* addInfo bool * addInfo bool
* hLevel integer
#} #}
{% macro raw(person, addAltNames) %} {% macro raw(person, options) %}
<span class="firstname">{{ person.firstName }}</span> <span class="firstname">{{ person.firstName }}</span>
<span class="lastname">{{ person.lastName }}</span> <span class="lastname">{{ person.lastName }}</span>
{%- if addAltNames -%} {%- if options['addAltNames'] -%}
{%- for n in person.altNames -%} {%- for n in person.altNames -%}
{%- if loop.first -%}({% else %} {%- endif -%} {%- if loop.first -%}({% else %} {%- endif -%}
<span class="altname altname-{{ n.key }}"> <span class="altname altname-{{ n.key }}">
{{- n.label -}} {{- n.label -}}
</span> </span>
{%- if loop.last -%}){%- endif -%} {%- if loop.last -%}){%- endif -%}
{%- endfor -%} {%- endfor -%}
{%- endif -%} {%- endif -%}
{% endmacro raw %} {% endmacro raw %}
{% macro label(person, addLink, addAltNames, addEntity, addInfo) %} {% macro label(person, options) %}
<div class="chill-entity person label"> <div class="entity-label">
<h3 class="denomination">
{%- if addLink and is_granted('CHILL_PERSON_SEE', person) -%} <div class="denomination {{ 'h' ~ options['hLevel'] }}">
{%- if options['addLink'] and is_granted('CHILL_PERSON_SEE', person) -%}
<a href="{{ chill_path_add_return_path('chill_person_view', { 'person_id': person.id }) }}"> <a href="{{ chill_path_add_return_path('chill_person_view', { 'person_id': person.id }) }}">
{{ _self.raw(person, addAltNames) }} {{ _self.raw(person, options) }}
</a> </a>
{%- else -%} {%- else -%}
{{ _self.raw(person, addAltNames) }} {{ _self.raw(person, options) }}
{%- endif -%} {%- endif -%}
{%- if addEntity -%} {%- if options['addEntity'] -%}
<span class="badge rounded-pill bg-secondary">{{ 'Person'|trans }}</span> <span class="badge rounded-pill bg-secondary">{{ 'Person'|trans }}</span>
{%- endif -%} {%- endif -%}
</h3> </div>
{%- if addInfo -%} {%- if options['addInfo'] -%}
{% set born = (person.gender == 'woman') ? 'née le ': 'né le ' %}
{% set gender = (person.gender == 'woman') ? 'fa-venus' : {% set gender = (person.gender == 'woman') ? 'fa-venus' :
(person.gender == 'man') ? 'fa-mars' : 'fa-neuter' %} (person.gender == 'man') ? 'fa-mars' : 'fa-neuter' %}
{% set genderTitle = (person.gender == 'woman') ? 'woman' : {% set genderTitle = (person.gender == 'woman') ? 'woman' :
(person.gender == 'man') ? 'man' : 'neuter' %} (person.gender == 'man') ? 'man' : 'neuter' %}
<p class="moreinfo"> <p class="moreinfo">
<i class="fa fa-fw {{ gender }}" title="{{ genderTitle|trans }}"></i> <i class="fa fa-fw {{ gender }}" title="{{ genderTitle|trans }}"></i>
{{ born|trans }} <time datetime="{{ person.birthdate|date('Y-m-d') }}" title="{{ 'Birthdate'|trans }}">
<time datetime="{{ person.birthdate|date('Y-m-d') }}"> {{ 'Born the date'|trans({'gender': person.gender,
{{ person.birthdate|format_date('medium') }} 'birthdate': person.birthdate|format_date("medium") }) }}
</time> </time>
{# TODO
{{ 'Born the %date%'|transchoice(person.genderNumeric, {
'%date%': person.birthdate|format_date("medium") }) }}
#}
</p> </p>
{%- endif -%} {%- endif -%}
{#- tricks to remove easily whitespace after template -#} {#- tricks to remove easily whitespace after template -#}
@ -58,25 +55,25 @@
{% endmacro label %} {% endmacro label %}
{%- if display == 'raw' -%} {%- if render == 'raw' -%}
{{ _self.raw(person, addAltNames) }} {{ _self.raw(person, options) }}
{%- endif -%} {%- endif -%}
{%- if display == 'label' -%} {%- if render == 'label' -%}
{{ _self.label(person, addLink, addAltNames, addEntity, addInfo) }} {{ _self.label(person, options) }}
{%- endif -%} {%- endif -%}
{%- if display == 'row' -%} {%- if render == 'row' -%}
<div class="chill-entity person row"> <div class="entity-row">
{{ _self.label(person, addLink, addAltNames, addEntity, addInfo) }} {{ _self.label(person, options) }}
</div> </div>
{%- endif -%} {%- endif -%}
{%- if display == 'bloc' -%} {%- if render == 'bloc' -%}
<div class="chill-entity person bloc"> <div class="entity-bloc">
<div class="item-row"> <div class="item-row">
<div class="item-col"> <div class="item-col">
{{ _self.label(person, addLink, addAltNames, addEntity, addInfo) }} {{ _self.label(person, options) }}
</div> </div>
<div class="item-col"> <div class="item-col">
<ul class="list-content fa-ul"> <ul class="list-content fa-ul">

View File

@ -46,7 +46,7 @@
<div class="item-col box-person"> <div class="item-col box-person">
<div> <div>
{{ person|chill_entity_render_box({ {{ person|chill_entity_render_box({
'display': 'label', 'addLink': true, 'addInfo': true 'render': 'label', 'addLink': true, 'addInfo': true
}) }} }) }}
</div> </div>
</div> </div>

View File

@ -52,16 +52,22 @@ class PersonRender extends AbstractChillEntityRender
*/ */
public function renderBox($person, array $options): string 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, 'person' => $person,
'addAltNames' => $this->configAltNamesHelper->hasAltNames(), 'render' => $options['render'] ?? 'raw',
'addLink' => $options['addLink'] ?? false, 'options' => $params
'addEntity' => $options['addEntity'] ?? false, ]) .
'addInfo' => $options['addInfo'] ?? false, $this->getDefaultClosingBox();
'display' => $options['display'] ?? 'raw'
]
);
} }
/** /**

View File

@ -1,9 +1,11 @@
div.chill-entity { section.chill-entity {
&.thirdparty { &.entity-thirdparty {
&.label { div.entity-label {
h3.denomination { div.denomination {
font-size: 1.3em; &.h3 {
font-weight: 700; font-size: 1.3em;
font-weight: 700;
}
a { a {
text-decoration: none; text-decoration: none;
} }
@ -12,10 +14,12 @@ div.chill-entity {
margin-left: 0.3em; margin-left: 0.3em;
} }
} }
p.moreinfo {} p.moreinfo {
span.company, span.acronym {}
}
} }
&.row {} div.entity-row {}
&.bloc {} div.entity-bloc {}
/* /*

View File

@ -1,36 +1,44 @@
{# {#
Template to render a thirdparty Template to render a thirdparty
* render [raw|label|row|bloc]
OPTIONS OPTIONS
* display [raw|label|row|bloc]
* with_valid_from bool * with_valid_from bool
* addAltNames bool * addAltNames bool
* addLink bool * addLink bool
* addEntity bool * addEntity bool
* addInfo bool * addInfo bool
* hLevel integer
#} #}
{% macro raw(thirdparty) %} {% macro raw(thirdparty, options) %}
<span class="name">{{ thirdparty.name }}</span> <span class="name">{{ thirdparty.name }}</span>
{% endmacro raw %} {% endmacro raw %}
{% macro label(thirdparty, addLink, addEntity, addInfo, options) %} {% macro label(thirdparty, options) %}
<div class="chill-entity thirdparty label"> <div class="entity-label">
<h3 class="denomination"> <div class="denomination {{ 'h' ~ options['hLevel'] }}">
{%- if addLink and is_granted('CHILL_3PARTY_3PARTY_SHOW', thirdparty) -%} {%- if options['addLink'] and is_granted('CHILL_3PARTY_3PARTY_SHOW', thirdparty) -%}
<a href="{{ chill_path_add_return_path('chill_3party_3party_show', { 'thirdparty_id': thirdparty.id }) }}"> <a href="{{ chill_path_add_return_path('chill_3party_3party_show', { 'thirdparty_id': thirdparty.id }) }}">
{{ _self.raw(thirdparty) }} {{ _self.raw(thirdparty, options) }}
</a> </a>
{%- else -%} {%- else -%}
{{ _self.raw(thirdparty) }} {{ _self.raw(thirdparty, options) }}
{%- endif -%} {%- endif -%}
{%- if addEntity -%} {%- if options['addEntity'] -%}
<span class="badge rounded-pill bg-secondary">{{ 'Third party'|trans }}</span> <span class="badge rounded-pill bg-secondary">{{ 'Third party'|trans }}</span>
{%- endif -%} {%- endif -%}
</h3> </div>
{%- if options['addInfo'] -%}
<p class="moreinfo">{#
<span class="company">{{ thirdparty.nameCompany }}</span>
<span class="acronym">{{ thirdparty.acronym }}</span>
#} plus d'infos
</p>
{%- endif -%}
{# AVANT {# AVANT
<div class="name"> <div class="name">
{{ _self.raw(thirdparty) }} {{ _self.raw(thirdparty, options) }}
</div> </div>
<div class="category"> <div class="category">
{% for type in thirdparty.type %} {% for type in thirdparty.type %}
@ -77,25 +85,25 @@
{%- if true -%}</div>{%- endif -%} {%- if true -%}</div>{%- endif -%}
{% endmacro label %} {% endmacro label %}
{%- if display == 'raw' -%} {%- if render == 'raw' -%}
{{ _self.raw(thirdparty) }} {{ _self.raw(thirdparty, options) }}
{%- endif -%} {%- endif -%}
{%- if display == 'label' -%} {%- if render == 'label' -%}
{{ _self.label(thirdparty, addLink, addEntity, addInfo, options) }} {{ _self.label(thirdparty, options) }}
{%- endif -%} {%- endif -%}
{%- if display == 'row' -%} {%- if render == 'row' -%}
<div class="chill-entity thirdparty row"> <div class="entity-row">
{{ _self.label(thirdparty, addLink, addEntity, addInfo, options) }} {{ _self.label(thirdparty, options) }}
</div> </div>
{%- endif -%} {%- endif -%}
{%- if display == 'bloc' -%} {%- if render == 'bloc' -%}
<div class="chill-entity thirdparty bloc"> <div class="entity-bloc">
<div class="item-row"> <div class="item-row">
<div class="item-col"> <div class="item-col">
{{ _self.label(thirdparty, addLink, addEntity, addInfo, options) }} {{ _self.label(thirdparty, options) }}
</div> </div>
<div class="item-col"> <div class="item-col">
<ul class="list-content fa-ul"> <ul class="list-content fa-ul">

View File

@ -22,7 +22,7 @@ namespace Chill\ThirdPartyBundle\Templating\Entity;
use Chill\MainBundle\Templating\Entity\AbstractChillEntityRender; use Chill\MainBundle\Templating\Entity\AbstractChillEntityRender;
use Chill\ThirdPartyBundle\Entity\ThirdParty; 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 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 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 return
$this->getDefaultOpeningBox('_3party'). $this->getDefaultOpeningBox('thirdparty') .
$this->templating->render('@ChillThirdParty/Entity/thirdparty.html.twig', [ $this->engine->render('@ChillThirdParty/Entity/thirdparty.html.twig', [
'thirdparty' => $entity, 'thirdparty' => $entity,
'with_valid_from' => $options['with_valid_from'] ?? true, 'render' => $options['render'] ?? 'raw',
'addLink' => $options['addLink'] ?? false, 'options' => $params
'addEntity' => $options['addEntity'] ?? false, ]) .
'addInfo' => $options['addInfo'] ?? false,
'display' => $options['display'] ?? 'raw',
'options' => $options
]).
$this->getDefaultClosingBox(); $this->getDefaultClosingBox();
} }