diff --git a/CHANGELOG.md b/CHANGELOG.md index 6c6d848cf..42dc0b692 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -45,3 +45,8 @@ Branche de développement ======================== - insert the title of the export inside the "download" page ; +- add twig helper "print_or_message" ; +- add twig helper for routing ; +- add css layout for boxes ; +- collect supplementary query parameters in SearchController ; + diff --git a/DependencyInjection/ChillMainExtension.php b/DependencyInjection/ChillMainExtension.php index 8d7e1e202..7b4b0243a 100644 --- a/DependencyInjection/ChillMainExtension.php +++ b/DependencyInjection/ChillMainExtension.php @@ -116,6 +116,7 @@ class ChillMainExtension extends Extension implements PrependExtensionInterface, $loader->load('services/command.yml'); $loader->load('services/phonenumber.yml'); $loader->load('services/cache.yml'); + $loader->load('services/templating.yml'); } public function getConfiguration(array $config, ContainerBuilder $container) diff --git a/Resources/config/services/templating.yml b/Resources/config/services/templating.yml new file mode 100644 index 000000000..99dfbe574 --- /dev/null +++ b/Resources/config/services/templating.yml @@ -0,0 +1,11 @@ +services: + Chill\MainBundle\Templating\ChillTwigHelper: + tags: + - { name: twig.extension } + + Chill\MainBundle\Templating\ChillTwigRoutingHelper: + arguments: + $requestStack: '@Symfony\Component\HttpFoundation\RequestStack' + $originalExtension: '@twig.extension.routing' + tags: + - { name: twig.extension } \ No newline at end of file diff --git a/Resources/public/sass/_custom.scss b/Resources/public/sass/_custom.scss index 393d16e75..59617dafe 100644 --- a/Resources/public/sass/_custom.scss +++ b/Resources/public/sass/_custom.scss @@ -12,6 +12,7 @@ @import 'custom/address'; @import 'custom/record_actions'; @import 'custom/flash_messages'; +@import 'custom/box'; html,body { diff --git a/Resources/public/sass/custom/_box.scss b/Resources/public/sass/custom/_box.scss new file mode 100644 index 000000000..aa539f6a1 --- /dev/null +++ b/Resources/public/sass/custom/_box.scss @@ -0,0 +1,24 @@ +.chill__box { + font-variant: small-caps; + display: inline; + padding: .2em .6em .3em; + font-size: 0.88rem; + font-weight: bold; + line-height: 1; + text-align: center; + white-space: nowrap; + vertical-align: baseline; + border-radius: .25em; + color: white; + + &.green { + background-color: var(--chill-green); + color: white; + } + + &.red { + background-color: var(--chill-red); + color: white; + } +} + diff --git a/Resources/translations/messages.fr.yml b/Resources/translations/messages.fr.yml index 93cab97d0..545672126 100644 --- a/Resources/translations/messages.fr.yml +++ b/Resources/translations/messages.fr.yml @@ -39,6 +39,12 @@ Edit: Modifier Update: Mettre à jour Back to the list: Retour à la liste +#elements used in software +centers: centres +Centers: Centres +comment: commentaire +Comment: Commentaire + #pagination Previous: Précédent Next: Suivant diff --git a/Resources/views/Extensions/PrintOrMessage/blockquote.html.twig b/Resources/views/Extensions/PrintOrMessage/blockquote.html.twig new file mode 100644 index 000000000..3dc4529c5 --- /dev/null +++ b/Resources/views/Extensions/PrintOrMessage/blockquote.html.twig @@ -0,0 +1 @@ +{% if value is not empty %}
{{ value|nl2br }}{% else %}{{ message|trans }}{% endif %} \ No newline at end of file diff --git a/Resources/views/Extensions/PrintOrMessage/default.html.twig b/Resources/views/Extensions/PrintOrMessage/default.html.twig new file mode 100644 index 000000000..f58878151 --- /dev/null +++ b/Resources/views/Extensions/PrintOrMessage/default.html.twig @@ -0,0 +1 @@ +{% if value is not empty %}{{ value|trans }}{% else %}{{ message|trans }}{% endif %} \ No newline at end of file diff --git a/Templating/ChillTwigHelper.php b/Templating/ChillTwigHelper.php new file mode 100644 index 000000000..7e665f8a3 --- /dev/null +++ b/Templating/ChillTwigHelper.php @@ -0,0 +1,62 @@ + true, + 'is_safe' => ['html', 'html_attrs'] + ]), + ]; + } + + /** + * Print `value` inside a template, or, if $value is empty, + * print $message. + * + * The template can be customized. The template is a full path to another + * template, or one of the key belows: + * + * - 'default' ; + * - 'blockquote' ; + * + * @param Environment $twig + * @param string $value + * @param string $message + * @param string $template + * @return string + */ + public function printOrMessage( + Environment $twig, + $value, + $message = 'No value', + $template = 'default' + ) { + switch ($template) { + case 'default': + case 'blockquote': + $t = '@ChillMain/Extensions/PrintOrMessage/'.$template.'.html.twig'; + break; + default: + $t = $template; + } + + return $twig->render($t, [ + 'value' => $value, + 'message' => $message + ]); + } +} diff --git a/Templating/ChillTwigRoutingHelper.php b/Templating/ChillTwigRoutingHelper.php new file mode 100644 index 000000000..6e9bc900f --- /dev/null +++ b/Templating/ChillTwigRoutingHelper.php @@ -0,0 +1,114 @@ +requestStack = $requestStack; + $this->originalExtension = $originalExtension; + } + + + public function getFunctions() + { + return [ + new TwigFunction('chill_return_path_or', [$this, 'getReturnPathOr'], ['is_safe_callback' => [$this, 'isUrlGenerationSafe']] ), + new TwigFunction('chill_path_add_return_path', [$this, 'getPathAddReturnPath'], ['is_safe_callback' => [$this, 'isUrlGenerationSafe']] ), + new TwigFunction('chill_path_forward_return_path', [$this, 'getPathForwardReturnPath'], ['is_safe_callback' => [$this, 'isUrlGenerationSafe']] ) + ]; + } + + public function isUrlGenerationSafe(\Twig_Node $argsNode) + { + return $this->originalExtension->isUrlGenerationSafe($argsNode); + } + + /** + * Return the return path if it exists, or generate the path if not. + * + * @param string $name + * @param array $parameters + * @param bool $relative + * @return string + */ + public function getReturnPathOr($name, $parameters = [], $relative = false) + { + $request = $this->requestStack->getCurrentRequest(); + + if ($request->query->has('returnPath')) { + return $request->query->get('returnPath'); + } + + return $this->originalExtension->getPath($name, $parameters, $relative); + } + + /** + * Build an url with a returnPath parameter to current page + * + * @param string $name + * @param array $parameters + * @param bool $relative + * @return string + */ + public function getPathAddReturnPath($name, $parameters = [], $relative = false) + { + $request = $this->requestStack->getCurrentRequest(); + + $parameters['returnPath'] = $request->getRequestUri(); + + return $this->originalExtension->getPath($name, $parameters, $relative); + } + + /** + * Build an url with a returnPath parameter to current page + * + * @param string $name + * @param array $parameters + * @param bool $relative + * @return string + */ + public function getPathForwardReturnPath($name, $parameters = [], $relative = false) + { + $request = $this->requestStack->getCurrentRequest(); + + if ($request->query->has('returnPath')) { + $parameters['returnPath'] = $request->query->get('returnPath'); + } + + return $this->originalExtension + ->getPath( + $name, + $parameters, + $relative + ); + } + +}