diff --git a/CHANGELOG.md b/CHANGELOG.md index 96703acad..38c4e1703 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,4 +3,4 @@ branch master ============= * initial commit - +* add a render template for entity ThirdParty ; diff --git a/Entity/ThirdParty.php b/Entity/ThirdParty.php index 9c3a52ab5..2d01ff442 100644 --- a/Entity/ThirdParty.php +++ b/Entity/ThirdParty.php @@ -72,7 +72,7 @@ class ThirdParty * @var string|null * * @ORM\Column(name="email", type="string", length=255, nullable=true) - * @Assert\Email(checkMX=true) + * @Assert\Email(checkMX=false) */ private $email; diff --git a/Resources/config/services.yml b/Resources/config/services.yml index d66403324..c1c8fa77d 100644 --- a/Resources/config/services.yml +++ b/Resources/config/services.yml @@ -4,4 +4,5 @@ imports: - { resource: './services/security.yml' } - { resource: './services/3partytype.yml' } - { resource: './services/search.yml' } + - { resource: './services/templating.yml' } - { resource: './services/menu.yml' } diff --git a/Resources/config/services/templating.yml b/Resources/config/services/templating.yml new file mode 100644 index 000000000..690f6008d --- /dev/null +++ b/Resources/config/services/templating.yml @@ -0,0 +1,6 @@ +services: + Chill\ThirdPartyBundle\Templating\Entity\ThirdPartyRender: + arguments: + $templating: '@templating.engine.twig' + tags: + - 'chill.render_entity' \ No newline at end of file diff --git a/Resources/views/Contact/macro.html.twig b/Resources/views/Contact/macro.html.twig index 9a7cb9343..6bcc6f553 100644 --- a/Resources/views/Contact/macro.html.twig +++ b/Resources/views/Contact/macro.html.twig @@ -1,49 +1,5 @@ {%- macro _render(contact, options) -%} - {%- set options = { 'with_valid_from' : true }|merge(options|default({})) -%} -
- -
- {{ contact.name }} -
-
- {% for type in contact.type %} - - {{ ('chill_3party.key_label.'~type)|trans }} - - {% endfor %} -
- {% if contact.comment is not empty %} -
- {{ contact.comment }} -
- {% endif %} - {% if contact.address %} -
-
- - {% if contact.address.streetAddress1 %}

{{ contact.address.streetAddress1 }}

{% endif %} - {% if contact.address.streetAddress2 is not empty %}

{{ contact.address.streetAddress2 }}

{% endif %} - {% if contact.address.postCode is not empty %} -

{{ contact.address.postCode.code }} {{ contact.address.postCode.name }}

-

{{ contact.address.postCode.country.name|localize_translatable_string }}

- {% endif %} -
- {%- if options['with_valid_from'] == true -%} - {{ 'Since %date%'|trans( { '%date%' : contact.address.validFrom|localizeddate('long', 'none') } ) }} - {%- endif -%} -
- {% endif %} - {% if contact.email or contact.telephone is not empty %} -
- - - {{ contact.telephone }} - -
- {% endif %} -
+ {{ contact|chill_entity_render_box(options|default({})) }} {%- endmacro -%} diff --git a/Resources/views/ThirdParty/_render.html.twig b/Resources/views/ThirdParty/_render.html.twig new file mode 100644 index 000000000..e05fd2031 --- /dev/null +++ b/Resources/views/ThirdParty/_render.html.twig @@ -0,0 +1,45 @@ +{# template to render a person #} +
+ +
+ {{ contact.name }} +
+
+ {% for type in contact.type %} + + {{ ('chill_3party.key_label.'~type)|trans }} + + {% endfor %} +
+ {% if contact.comment is not empty %} +
+ {{ contact.comment }} +
+ {% endif %} + {% if contact.address %} +
+
+ + {% if contact.address.streetAddress1 %}

{{ contact.address.streetAddress1 }}

{% endif %} + {% if contact.address.streetAddress2 is not empty %}

{{ contact.address.streetAddress2 }}

{% endif %} + {% if contact.address.postCode is not empty %} +

{{ contact.address.postCode.code }} {{ contact.address.postCode.name }}

+

{{ contact.address.postCode.country.name|localize_translatable_string }}

+ {% endif %} +
+ {%- if options['with_valid_from'] == true -%} + {{ 'Since %date%'|trans( { '%date%' : contact.address.validFrom|localizeddate('long', 'none') } ) }} + {%- endif -%} +
+ {% endif %} + {% if contact.email or contact.telephone is not empty %} +
+ + + {{ contact.telephone|chill_format_phonenumber }} + +
+ {% endif %} +
diff --git a/Templating/Entity/ThirdPartyRender.php b/Templating/Entity/ThirdPartyRender.php new file mode 100644 index 000000000..be2f82cb5 --- /dev/null +++ b/Templating/Entity/ThirdPartyRender.php @@ -0,0 +1,82 @@ + + * + * 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 . + */ +namespace Chill\ThirdPartyBundle\Templating\Entity; + +use Chill\MainBundle\Templating\Entity\AbstractChillEntityRender; +use Chill\ThirdPartyBundle\Entity\ThirdParty; +use Symfony\Bridge\Twig\TwigEngine; + +/** + * + * + */ +class ThirdPartyRender extends AbstractChillEntityRender +{ + /** + * + * @var TwigEngine + */ + protected $templating; + + public function __construct(TwigEngine $templating) + { + $this->templating = $templating; + } + + /** + * + * @param ThirdParty $entity + * @param array $options + * @return string + */ + public function renderBox($entity, array $options): string + { + $params = \array_merge( + [ 'with_valid_from' => true ], + $options + ); + + return + $this->getDefaultOpeningBox('_3party'). + $this->templating->render('@ChillThirdParty/ThirdParty/_render.html.twig', [ + 'contact' => $entity, + 'options' => $params + ]). + $this->getDefaultClosingBox(); + + } + + /** + * + * @param ThirdParty $entity + * @param array $options + * @return string + */ + public function renderString($entity, array $options): string + { + return $entity->getName(); + } + + public function supports($entity, array $options): bool + { + return $entity instanceof ThirdParty; + } +}