mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-09-03 13:33:48 +00:00
cs: Fix code style (safe rules only).
This commit is contained in:
@@ -1,23 +1,10 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* Copyright (C) 2014-2015, Champs Libres Cooperative SCRLFS,
|
||||
* <http://www.champs-libres.coop>, <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/>.
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\MainBundle\Templating;
|
||||
@@ -28,30 +15,14 @@ use Twig\TwigFilter;
|
||||
/**
|
||||
* Twig filter to transform a string in a safer way to be the content of a csv
|
||||
* cell.
|
||||
*
|
||||
*
|
||||
* This filter replace the char " by ""
|
||||
*/
|
||||
class CSVCellTwig extends AbstractExtension
|
||||
{
|
||||
/*
|
||||
* Returns a list of filters to add to the existing list.
|
||||
*
|
||||
* (non-PHPdoc)
|
||||
* @see Twig_Extension::getFilters()
|
||||
*/
|
||||
public function getFilters()
|
||||
{
|
||||
return array(
|
||||
new TwigFilter(
|
||||
'csv_cell',
|
||||
array($this, 'csvCellFilter'),
|
||||
array('is_safe' => array('html')))
|
||||
);
|
||||
}
|
||||
|
||||
/*
|
||||
* Replace into a string the char " by ""
|
||||
*
|
||||
*
|
||||
* @param String $content The input string.
|
||||
* @return String The safe string.
|
||||
*/
|
||||
@@ -59,7 +30,24 @@ class CSVCellTwig extends AbstractExtension
|
||||
{
|
||||
return str_replace('"', '""', $content);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Returns a list of filters to add to the existing list.
|
||||
*
|
||||
* (non-PHPdoc)
|
||||
* @see Twig_Extension::getFilters()
|
||||
*/
|
||||
public function getFilters()
|
||||
{
|
||||
return [
|
||||
new TwigFilter(
|
||||
'csv_cell',
|
||||
[$this, 'csvCellFilter'],
|
||||
['is_safe' => ['html']]
|
||||
),
|
||||
];
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns the name of the extension.
|
||||
*
|
||||
|
@@ -1,29 +1,21 @@
|
||||
<?php
|
||||
/*
|
||||
* Copyright (C) 2021 Champs Libres Cooperative <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\MainBundle\Templating;
|
||||
|
||||
use Twig\Extension\AbstractExtension;
|
||||
use Twig\TwigFilter;
|
||||
|
||||
use Parsedown;
|
||||
|
||||
/**
|
||||
* Render markdown
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\MainBundle\Templating;
|
||||
|
||||
use Parsedown;
|
||||
use Twig\Extension\AbstractExtension;
|
||||
|
||||
use Twig\TwigFilter;
|
||||
|
||||
/**
|
||||
* Render markdown.
|
||||
*/
|
||||
final class ChillMarkdownRenderExtension extends AbstractExtension
|
||||
{
|
||||
@@ -42,8 +34,8 @@ final class ChillMarkdownRenderExtension extends AbstractExtension
|
||||
{
|
||||
return [
|
||||
new TwigFilter('chill_markdown_to_html', [$this, 'renderMarkdownToHtml'], [
|
||||
'is_safe' => [ 'html' ]
|
||||
])
|
||||
'is_safe' => ['html'],
|
||||
]),
|
||||
];
|
||||
}
|
||||
|
||||
|
@@ -1,32 +1,20 @@
|
||||
<?php
|
||||
/*
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* Copyright (C) 2014-2019, Champs Libres Cooperative SCRLFS,
|
||||
* <http://www.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\MainBundle\Templating;
|
||||
|
||||
use Twig\Extension\AbstractExtension;
|
||||
use Twig\TwigFilter;
|
||||
use Twig\Environment;
|
||||
|
||||
/**
|
||||
*
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\MainBundle\Templating;
|
||||
|
||||
use DateTimeInterface;
|
||||
use Twig\Environment;
|
||||
use Twig\Extension\AbstractExtension;
|
||||
use Twig\TwigFilter;
|
||||
use function array_merge;
|
||||
|
||||
class ChillTwigHelper extends AbstractExtension
|
||||
{
|
||||
public function getFilters()
|
||||
@@ -34,51 +22,53 @@ class ChillTwigHelper extends AbstractExtension
|
||||
return [
|
||||
new TwigFilter('chill_print_or_message', [$this, 'printOrMessage'], [
|
||||
'needs_environment' => true,
|
||||
'is_safe' => ['html', 'html_attrs']
|
||||
'is_safe' => ['html', 'html_attrs'],
|
||||
]),
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Print `value` inside a template, or, if $value is empty,
|
||||
* 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:
|
||||
*
|
||||
* template, or one of the key belows:
|
||||
*
|
||||
* - 'default' ;
|
||||
* - 'blockquote' ;
|
||||
*
|
||||
*
|
||||
* `DateTimeInterface are also rendered. The date and time format may be set
|
||||
* using those key in `$options´ parameter:
|
||||
*
|
||||
*
|
||||
* - `date_format` (default to `'medium'`)
|
||||
* - `time_format` (default to `'none'`)
|
||||
*
|
||||
* @param Environment $twig
|
||||
*
|
||||
* @param string $value Default to 'No value'. Fallback to default if null
|
||||
* @param string $message
|
||||
* @param string $template
|
||||
* @param array $options
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function printOrMessage(
|
||||
Environment $twig,
|
||||
$value,
|
||||
$message = 'No value',
|
||||
$value,
|
||||
$message = 'No value',
|
||||
$template = 'default',
|
||||
array $options = []
|
||||
) {
|
||||
if ($value instanceof \DateTimeInterface) {
|
||||
$options = \array_merge([
|
||||
if ($value instanceof DateTimeInterface) {
|
||||
$options = array_merge([
|
||||
'date_format' => 'medium',
|
||||
'time_format' => 'none'
|
||||
'time_format' => 'none',
|
||||
], $options);
|
||||
|
||||
switch ($template) {
|
||||
case 'default':
|
||||
case 'blockquote':
|
||||
$t = '@ChillMain/Extensions/PrintOrMessage/'.$template.'_date.html.twig';
|
||||
$t = '@ChillMain/Extensions/PrintOrMessage/' . $template . '_date.html.twig';
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
$t = $template;
|
||||
}
|
||||
@@ -86,16 +76,18 @@ class ChillTwigHelper extends AbstractExtension
|
||||
switch ($template) {
|
||||
case 'default':
|
||||
case 'blockquote':
|
||||
$t = '@ChillMain/Extensions/PrintOrMessage/'.$template.'.html.twig';
|
||||
$t = '@ChillMain/Extensions/PrintOrMessage/' . $template . '.html.twig';
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
$t = $template;
|
||||
}
|
||||
}
|
||||
|
||||
return $twig->render($t, \array_merge([
|
||||
|
||||
return $twig->render($t, array_merge([
|
||||
'value' => $value,
|
||||
'message' => $message ?? 'No value'
|
||||
'message' => $message ?? 'No value',
|
||||
], $options));
|
||||
}
|
||||
}
|
||||
|
@@ -1,152 +1,139 @@
|
||||
<?php
|
||||
/*
|
||||
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* Copyright (C) 2014-2019, Champs Libres Cooperative SCRLFS,
|
||||
* <http://www.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/>.
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\MainBundle\Templating;
|
||||
|
||||
use Symfony\Bridge\Twig\Extension\RoutingExtension;
|
||||
use Symfony\Component\HttpFoundation\RequestStack;
|
||||
use Twig\Extension\AbstractExtension;
|
||||
use Twig\Node\Node;
|
||||
use Twig\TwigFunction;
|
||||
use Twig\TwigFilter;
|
||||
use Symfony\Component\HttpFoundation\RequestStack;
|
||||
use Symfony\Bridge\Twig\Extension\RoutingExtension;
|
||||
use Twig\TwigFunction;
|
||||
|
||||
/**
|
||||
* Provides function to build path with returnPath.
|
||||
*
|
||||
* The logic of the function is based on the original routing extension.
|
||||
*
|
||||
* The logic of the function is based on the original routing extension.
|
||||
*/
|
||||
class ChillTwigRoutingHelper extends AbstractExtension
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @var RequestStack
|
||||
*/
|
||||
protected $requestStack;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var RoutingExtension
|
||||
*/
|
||||
protected $originalExtension;
|
||||
|
||||
|
||||
/**
|
||||
* @var RequestStack
|
||||
*/
|
||||
protected $requestStack;
|
||||
|
||||
public function __construct(
|
||||
RequestStack $requestStack,
|
||||
RequestStack $requestStack,
|
||||
RoutingExtension $originalExtension
|
||||
) {
|
||||
$this->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 getFilters()
|
||||
{
|
||||
return [
|
||||
new TwigFilter('chill_return_path_label', [$this, 'getLabelReturnPath']),
|
||||
];
|
||||
}
|
||||
|
||||
public function isUrlGenerationSafe(Node $argsNode)
|
||||
|
||||
public function getFunctions()
|
||||
{
|
||||
return $this->originalExtension->isUrlGenerationSafe($argsNode);
|
||||
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 getLabelReturnPath($default)
|
||||
{
|
||||
$request = $this->requestStack->getCurrentRequest();
|
||||
|
||||
|
||||
return $request->query->get('returnPathLabel', null) ?? $default;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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
|
||||
*
|
||||
* Build an url with a returnPath parameter to current page.
|
||||
*
|
||||
* @param string $name
|
||||
* @param array $parameters
|
||||
* @param bool $relative
|
||||
* @param mixed|null $label
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getPathAddReturnPath($name, $parameters = [], $relative = false, $label = null)
|
||||
{
|
||||
$request = $this->requestStack->getCurrentRequest();
|
||||
|
||||
|
||||
$parameters['returnPath'] = $request->getRequestUri();
|
||||
|
||||
|
||||
if ($label) {
|
||||
$parameters['returnPathLabel'] = $label;
|
||||
}
|
||||
|
||||
|
||||
return $this->originalExtension->getPath($name, $parameters, $relative);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Build an url with a returnPath parameter to current page
|
||||
*
|
||||
* 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,
|
||||
$name,
|
||||
$parameters,
|
||||
$relative
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
|
||||
public function isUrlGenerationSafe(Node $argsNode)
|
||||
{
|
||||
return $this->originalExtension->isUrlGenerationSafe($argsNode);
|
||||
}
|
||||
}
|
||||
|
@@ -1,38 +1,23 @@
|
||||
<?php
|
||||
/*
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* Copyright (C) 2014-2019, Champs Libres Cooperative SCRLFS,
|
||||
* <http://www.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\MainBundle\Templating\Entity;
|
||||
|
||||
/**
|
||||
*
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\MainBundle\Templating\Entity;
|
||||
|
||||
abstract class AbstractChillEntityRender implements ChillEntityRenderInterface
|
||||
{
|
||||
protected function getDefaultOpeningBox($classSuffix): string
|
||||
{
|
||||
return '<section class="chill-entity entity-'.$classSuffix.'">';
|
||||
}
|
||||
|
||||
protected function getDefaultClosingBox(): string
|
||||
{
|
||||
return '</section>';
|
||||
}
|
||||
|
||||
protected function getDefaultOpeningBox($classSuffix): string
|
||||
{
|
||||
return '<section class="chill-entity entity-' . $classSuffix . '">';
|
||||
}
|
||||
}
|
||||
|
@@ -1,14 +1,21 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\MainBundle\Templating\Entity;
|
||||
|
||||
use Symfony\Component\Templating\EngineInterface;
|
||||
use Chill\MainBundle\Entity\Address;
|
||||
use Symfony\Component\Templating\EngineInterface;
|
||||
use function array_merge;
|
||||
use function strtr;
|
||||
|
||||
class AddressRender implements ChillEntityRenderInterface
|
||||
{
|
||||
private EngineInterface $templating;
|
||||
|
||||
public const DEFAULT_OPTIONS = [
|
||||
'with_valid_from' => false,
|
||||
'with_valid_to' => false,
|
||||
@@ -16,57 +23,59 @@ class AddressRender implements ChillEntityRenderInterface
|
||||
'with_delimiter' => false,
|
||||
'has_no_address' => false,
|
||||
'multiline' => true,
|
||||
'extended_infos' => false
|
||||
'extended_infos' => false,
|
||||
];
|
||||
|
||||
private EngineInterface $templating;
|
||||
|
||||
public function __construct(EngineInterface $templating)
|
||||
{
|
||||
$this->templating = $templating;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function supports($entity, array $options): bool
|
||||
{
|
||||
return $entity instanceof Address;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Address addr
|
||||
*/
|
||||
public function renderString($addr, array $options): string
|
||||
{
|
||||
$lines = [];
|
||||
if (!empty($addr->getStreet())) {
|
||||
$lines[0] = $addr->getStreet();
|
||||
}
|
||||
if (!empty($addr->getStreetNumber())) {
|
||||
$lines[0] .= ", ".$addr->getStreetNumber();
|
||||
}
|
||||
if (!empty($addr->getPostcode())) {
|
||||
$lines[1] = \strtr("{postcode} {label}", [
|
||||
'{postcode}' => $addr->getPostcode()->getCode(),
|
||||
'{label}' => $addr->getPostcode()->getName()
|
||||
]);
|
||||
}
|
||||
|
||||
return implode(" - ", $lines);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* @param Address addr
|
||||
*/
|
||||
public function renderBox($addr, array $options): string
|
||||
{
|
||||
$options = \array_merge(self::DEFAULT_OPTIONS, $options);
|
||||
$options = array_merge(self::DEFAULT_OPTIONS, $options);
|
||||
|
||||
return $this->templating
|
||||
->render('@ChillMain/Entity/address.html.twig', [
|
||||
'address' => $addr,
|
||||
'render' => $options['render'] ?? 'bloc',
|
||||
'options' => $options
|
||||
'options' => $options,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Address addr
|
||||
* @param mixed $addr
|
||||
*/
|
||||
public function renderString($addr, array $options): string
|
||||
{
|
||||
$lines = [];
|
||||
|
||||
if (!empty($addr->getStreet())) {
|
||||
$lines[0] = $addr->getStreet();
|
||||
}
|
||||
|
||||
if (!empty($addr->getStreetNumber())) {
|
||||
$lines[0] .= ', ' . $addr->getStreetNumber();
|
||||
}
|
||||
|
||||
if (!empty($addr->getPostcode())) {
|
||||
$lines[1] = strtr('{postcode} {label}', [
|
||||
'{postcode}' => $addr->getPostcode()->getCode(),
|
||||
'{label}' => $addr->getPostcode()->getName(),
|
||||
]);
|
||||
}
|
||||
|
||||
return implode(' - ', $lines);
|
||||
}
|
||||
|
||||
public function supports($entity, array $options): bool
|
||||
{
|
||||
return $entity instanceof Address;
|
||||
}
|
||||
}
|
||||
|
@@ -1,34 +1,23 @@
|
||||
<?php
|
||||
/*
|
||||
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* Copyright (C) 2014-2019, Champs Libres Cooperative SCRLFS,
|
||||
* <http://www.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/>.
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\MainBundle\Templating\Entity;
|
||||
|
||||
/**
|
||||
* Render an entity using `__toString()`
|
||||
* Render an entity using `__toString()`.
|
||||
*/
|
||||
class ChillEntityRender extends AbstractChillEntityRender
|
||||
{
|
||||
public function renderBox($entity, array $options): string
|
||||
{
|
||||
return $this->getDefaultOpeningBox('default').$entity
|
||||
.$this->getDefaultClosingBox();
|
||||
return $this->getDefaultOpeningBox('default') . $entity
|
||||
. $this->getDefaultClosingBox();
|
||||
}
|
||||
|
||||
public function renderString($entity, array $options): string
|
||||
|
@@ -1,45 +1,32 @@
|
||||
<?php
|
||||
/*
|
||||
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* Copyright (C) 2014-2019, Champs Libres Cooperative SCRLFS,
|
||||
* <http://www.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/>.
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\MainBundle\Templating\Entity;
|
||||
|
||||
use Twig\Extension\AbstractExtension;
|
||||
use Twig\TwigFilter;
|
||||
|
||||
/**
|
||||
* Class ChillEntityRenderExtension
|
||||
*
|
||||
* @package Chill\MainBundle\Templating\Entity
|
||||
* Class ChillEntityRenderExtension.
|
||||
*/
|
||||
class ChillEntityRenderExtension extends AbstractExtension
|
||||
{
|
||||
/**
|
||||
* @var ChillEntityRenderInterface
|
||||
*/
|
||||
protected $renders = [];
|
||||
|
||||
/**
|
||||
* @var ChillEntityRender
|
||||
*/
|
||||
protected $defaultRender;
|
||||
|
||||
|
||||
/**
|
||||
* @var ChillEntityRenderInterface
|
||||
*/
|
||||
protected $renders = [];
|
||||
|
||||
/**
|
||||
* ChillEntityRenderExtension constructor.
|
||||
*/
|
||||
@@ -47,7 +34,12 @@ class ChillEntityRenderExtension extends AbstractExtension
|
||||
{
|
||||
$this->defaultRender = new ChillEntityRender();
|
||||
}
|
||||
|
||||
|
||||
public function addRender(ChillEntityRenderInterface $render)
|
||||
{
|
||||
$this->renders[] = $render;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array|TwigFilter[]
|
||||
*/
|
||||
@@ -55,54 +47,43 @@ class ChillEntityRenderExtension extends AbstractExtension
|
||||
{
|
||||
return [
|
||||
new TwigFilter('chill_entity_render_string', [$this, 'renderString'], [
|
||||
'is_safe' => [ 'html' ]
|
||||
'is_safe' => ['html'],
|
||||
]),
|
||||
new TwigFilter('chill_entity_render_box', [$this, 'renderBox'], [
|
||||
'is_safe' => [ 'html' ]
|
||||
])
|
||||
'is_safe' => ['html'],
|
||||
]),
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $entity
|
||||
* @param array $options
|
||||
* @return string
|
||||
*/
|
||||
public function renderString($entity, array $options = []): string
|
||||
{
|
||||
if (NULL === $entity) {
|
||||
return '';
|
||||
}
|
||||
return $this->getRender($entity, $options)
|
||||
->renderString($entity, $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $entity
|
||||
* @param array $options
|
||||
* @return string
|
||||
*/
|
||||
public function renderBox($entity, array $options = []): string
|
||||
{
|
||||
if (NULL === $entity) {
|
||||
if (null === $entity) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return $this->getRender($entity, $options)
|
||||
->renderBox($entity, $options);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param ChillEntityRenderInterface $render
|
||||
* @param $entity
|
||||
*/
|
||||
public function addRender(ChillEntityRenderInterface $render)
|
||||
public function renderString($entity, array $options = []): string
|
||||
{
|
||||
$this->renders[] = $render;
|
||||
if (null === $entity) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return $this->getRender($entity, $options)
|
||||
->renderString($entity, $options);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $entity
|
||||
* @param $options
|
||||
* @return ChillEntityRenderInterface|null
|
||||
*/
|
||||
protected function getRender($entity, $options): ?ChillEntityRenderInterface
|
||||
{
|
||||
@@ -111,6 +92,7 @@ class ChillEntityRenderExtension extends AbstractExtension
|
||||
return $render;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->defaultRender;
|
||||
}
|
||||
}
|
||||
|
@@ -1,23 +1,12 @@
|
||||
<?php
|
||||
/*
|
||||
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* Copyright (C) 2014-2019, Champs Libres Cooperative SCRLFS,
|
||||
* <http://www.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/>.
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\MainBundle\Templating\Entity;
|
||||
|
||||
/**
|
||||
@@ -27,40 +16,34 @@ namespace Chill\MainBundle\Templating\Entity;
|
||||
interface ChillEntityRenderInterface
|
||||
{
|
||||
/**
|
||||
* Return true if the class support this object for the given options
|
||||
*
|
||||
* @param type $entity
|
||||
* @param array $options
|
||||
* @return bool
|
||||
*/
|
||||
public function supports($entity, array $options): bool;
|
||||
|
||||
/**
|
||||
* Return the entity as a string.
|
||||
*
|
||||
* Example: returning the name of a person.
|
||||
*
|
||||
* @param object $entity
|
||||
* @param array $options
|
||||
* @return string
|
||||
*/
|
||||
public function renderString($entity, array $options): string;
|
||||
|
||||
/**
|
||||
* Return the entity in a box
|
||||
*
|
||||
* Return the entity in a box.
|
||||
*
|
||||
* Example: return a person inside a box:
|
||||
*
|
||||
*
|
||||
* ```html
|
||||
* <span class="chill-entity">
|
||||
* <span class="chill-entity__first-name">Roger</span>
|
||||
* <span class="chill-entity__last-name">Dupont</span>
|
||||
* </span>
|
||||
* ```
|
||||
*
|
||||
*
|
||||
* @param type $entity
|
||||
* @param array $options
|
||||
* @return string
|
||||
*/
|
||||
public function renderBox($entity, array $options): string;
|
||||
|
||||
/**
|
||||
* Return the entity as a string.
|
||||
*
|
||||
* Example: returning the name of a person.
|
||||
*
|
||||
* @param object $entity
|
||||
*/
|
||||
public function renderString($entity, array $options): string;
|
||||
|
||||
/**
|
||||
* Return true if the class support this object for the given options.
|
||||
*
|
||||
* @param type $entity
|
||||
*/
|
||||
public function supports($entity, array $options): bool;
|
||||
}
|
||||
|
@@ -1,43 +1,31 @@
|
||||
<?php
|
||||
/*
|
||||
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* Copyright (C) 2014-2020, Champs Libres Cooperative SCRLFS,
|
||||
* <http://www.champs-libres.coop>, <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/>.
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\MainBundle\Templating\Entity;
|
||||
|
||||
use Chill\MainBundle\Entity\Embeddable\CommentEmbeddable;
|
||||
use Chill\MainBundle\Repository\UserRepository;
|
||||
use Chill\MainBundle\Templating\Entity\AbstractChillEntityRender;
|
||||
use Symfony\Component\Templating\EngineInterface;
|
||||
use function array_merge;
|
||||
|
||||
class CommentRender extends AbstractChillEntityRender
|
||||
{
|
||||
/**
|
||||
* @var \Chill\MainBundle\Repository\UserRepository
|
||||
*/
|
||||
private $userRepository;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var EngineInterface
|
||||
*/
|
||||
private $engine;
|
||||
|
||||
/**
|
||||
* @var \Chill\MainBundle\Repository\UserRepository
|
||||
*/
|
||||
private $userRepository;
|
||||
|
||||
public function __construct(
|
||||
UserRepository $userRepository,
|
||||
EngineInterface $engine
|
||||
@@ -48,42 +36,36 @@ class CommentRender extends AbstractChillEntityRender
|
||||
|
||||
/**
|
||||
* @param CommentEmbeddable $entity
|
||||
* @param array $options
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function renderBox($entity, array $options): string
|
||||
{
|
||||
// default options
|
||||
$options = \array_merge([
|
||||
'user' => [],
|
||||
'disable_markdown' => false,
|
||||
'limit_lines' => null,
|
||||
'metadata' => true
|
||||
], $options);
|
||||
|
||||
$options = array_merge([
|
||||
'user' => [],
|
||||
'disable_markdown' => false,
|
||||
'limit_lines' => null,
|
||||
'metadata' => true,
|
||||
], $options);
|
||||
|
||||
if ($entity->getUserId()) {
|
||||
$user = $this->userRepository->find($entity->getUserId());
|
||||
}
|
||||
|
||||
|
||||
return $this->engine
|
||||
->render(
|
||||
'@ChillMain/Entity/CommentEmbeddable.html.twig',
|
||||
[
|
||||
'opening_box' => $this->getDefaultOpeningBox('comment-embeddable'),
|
||||
'closing_box' => $this->getDefaultClosingBox(),
|
||||
'user' => $user ?? NULL,
|
||||
'user' => $user ?? null,
|
||||
'comment' => $entity,
|
||||
'options' => $options
|
||||
'options' => $options,
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param CommentEmbeddable $entity
|
||||
* @param array $options
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function renderString($entity, array $options): string
|
||||
{
|
||||
|
@@ -1,39 +1,27 @@
|
||||
<?php
|
||||
/*
|
||||
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* Copyright (C) 2014-2019, Champs Libres Cooperative SCRLFS,
|
||||
* <http://www.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/>.
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\MainBundle\Templating\Entity;
|
||||
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
|
||||
/**
|
||||
* Add service tagged with `chill.render_entity` to appropriate service
|
||||
*
|
||||
* Add service tagged with `chill.render_entity` to appropriate service.
|
||||
*/
|
||||
class CompilerPass implements CompilerPassInterface
|
||||
{
|
||||
public function process(ContainerBuilder $container)
|
||||
{
|
||||
$extension = $container->getDefinition(ChillEntityRenderExtension::class);
|
||||
|
||||
|
||||
foreach ($container->findTaggedServiceIds('chill.render_entity') as $id => $tags) {
|
||||
$extension->addMethodCall('addRender', [new Reference($id)]);
|
||||
}
|
||||
|
@@ -1,20 +1,29 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\MainBundle\Templating\Entity;
|
||||
|
||||
use Chill\MainBundle\Entity\User;
|
||||
use Chill\MainBundle\Templating\TranslatableStringHelper;
|
||||
use Symfony\Component\Templating\EngineInterface;
|
||||
use function array_merge;
|
||||
|
||||
class UserRender implements ChillEntityRenderInterface
|
||||
{
|
||||
private TranslatableStringHelper $translatableStringHelper;
|
||||
public const DEFAULT_OPTIONS = [
|
||||
'main_scope' => true,
|
||||
'user_job' => true,
|
||||
];
|
||||
|
||||
private EngineInterface $engine;
|
||||
|
||||
const DEFAULT_OPTIONS = [
|
||||
'main_scope' => true,
|
||||
'user_job' => true
|
||||
];
|
||||
private TranslatableStringHelper $translatableStringHelper;
|
||||
|
||||
public function __construct(TranslatableStringHelper $translatableStringHelper, EngineInterface $engine)
|
||||
{
|
||||
@@ -22,45 +31,40 @@ class UserRender implements ChillEntityRenderInterface
|
||||
$this->engine = $engine;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function supports($entity, array $options): bool
|
||||
public function renderBox($entity, array $options): string
|
||||
{
|
||||
return $entity instanceof User;
|
||||
$opts = array_merge(self::DEFAULT_OPTIONS, $options);
|
||||
|
||||
return $this->engine->render('@ChillMain/Entity/user.html.twig', [
|
||||
'user' => $entity,
|
||||
'opts' => $opts,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
* @param User $entity
|
||||
*/
|
||||
public function renderString($entity, array $options): string
|
||||
{
|
||||
$opts = \array_merge(self::DEFAULT_OPTIONS, $options);
|
||||
$opts = array_merge(self::DEFAULT_OPTIONS, $options);
|
||||
|
||||
$str = $entity->getLabel();
|
||||
if (NULL !== $entity->getUserJob() && $opts['user_job']) {
|
||||
$str .= ' ('.$this->translatableStringHelper
|
||||
->localize($entity->getUserJob()->getLabel()).')';
|
||||
|
||||
if (null !== $entity->getUserJob() && $opts['user_job']) {
|
||||
$str .= ' (' . $this->translatableStringHelper
|
||||
->localize($entity->getUserJob()->getLabel()) . ')';
|
||||
}
|
||||
if (NULL !== $entity->getMainScope() && $opts['main_scope']) {
|
||||
$str .= ' ('.$this->translatableStringHelper
|
||||
->localize($entity->getMainScope()->getName()).')';
|
||||
|
||||
if (null !== $entity->getMainScope() && $opts['main_scope']) {
|
||||
$str .= ' (' . $this->translatableStringHelper
|
||||
->localize($entity->getMainScope()->getName()) . ')';
|
||||
}
|
||||
|
||||
return $str;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function renderBox($entity, array $options): string
|
||||
public function supports($entity, array $options): bool
|
||||
{
|
||||
$opts = \array_merge(self::DEFAULT_OPTIONS, $options);
|
||||
|
||||
return $this->engine->render('@ChillMain/Entity/user.html.twig', [
|
||||
'user' => $entity,
|
||||
'opts' => $opts
|
||||
]);
|
||||
return $entity instanceof User;
|
||||
}
|
||||
}
|
||||
|
@@ -1,85 +1,73 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Copyright (C) 2016 Champs-Libres <info@champs-libres.coop>
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* 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/>.
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\MainBundle\Templating\Events;
|
||||
|
||||
use ArrayAccess;
|
||||
use RuntimeException;
|
||||
use Symfony\Component\EventDispatcher\Event;
|
||||
|
||||
/**
|
||||
* This event is transmitted on event chill_block.*
|
||||
*
|
||||
* You may access to the context as an array :
|
||||
*
|
||||
* This event is transmitted on event chill_block.*.
|
||||
*
|
||||
* You may access to the context as an array :
|
||||
*
|
||||
* ```
|
||||
* $var = $event['context_key']
|
||||
* ```
|
||||
*
|
||||
* The documentation for the bundle where the event is launched should give
|
||||
*
|
||||
* The documentation for the bundle where the event is launched should give
|
||||
* you the context keys.
|
||||
*
|
||||
*
|
||||
* The keys are read-only: if you try to update the context using array access
|
||||
* (example, using `$event['context_key'] = $bar;`, an error will be thrown.
|
||||
*
|
||||
*
|
||||
* @author Julien Fastré <julien.fastre@champs-libres.coop>
|
||||
*/
|
||||
class DelegatedBlockRenderingEvent extends Event implements \ArrayAccess
|
||||
class DelegatedBlockRenderingEvent extends Event implements ArrayAccess
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @var mixed[]
|
||||
*/
|
||||
protected $context;
|
||||
|
||||
/**
|
||||
* The returned content of the event
|
||||
* The returned content of the event.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $content = '';
|
||||
|
||||
|
||||
/**
|
||||
* @var mixed[]
|
||||
*/
|
||||
protected $context;
|
||||
|
||||
public function __construct(array $context)
|
||||
{
|
||||
$this->context = $context;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* add content to the event. This content will be printed in the
|
||||
* layout which launched the event
|
||||
*
|
||||
* layout which launched the event.
|
||||
*
|
||||
* @param string $text
|
||||
*/
|
||||
public function addContent($text)
|
||||
{
|
||||
$this->content .= $text;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* the content of the event
|
||||
*
|
||||
* the content of the event.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getContent()
|
||||
{
|
||||
return $this->content;
|
||||
}
|
||||
|
||||
|
||||
public function offsetExists($offset)
|
||||
{
|
||||
return isset($this->context[$offset]);
|
||||
@@ -92,14 +80,13 @@ class DelegatedBlockRenderingEvent extends Event implements \ArrayAccess
|
||||
|
||||
public function offsetSet($offset, $value)
|
||||
{
|
||||
throw new \RuntimeException("The event context is read-only, you are not "
|
||||
. "allowed to update it.");
|
||||
throw new RuntimeException('The event context is read-only, you are not '
|
||||
. 'allowed to update it.');
|
||||
}
|
||||
|
||||
public function offsetUnset($offset)
|
||||
{
|
||||
throw new \RuntimeException("The event context is read-only, you are not "
|
||||
. "allowed to update it.");
|
||||
throw new RuntimeException('The event context is read-only, you are not '
|
||||
. 'allowed to update it.');
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,23 +1,37 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\MainBundle\Templating\Listing;
|
||||
|
||||
use Chill\MainBundle\Form\Type\Listing\FilterOrderType;
|
||||
use Symfony\Component\Form\FormFactoryInterface;
|
||||
use Symfony\Component\Form\FormInterface;
|
||||
use Symfony\Component\HttpFoundation\RequestStack;
|
||||
use function array_merge;
|
||||
|
||||
class FilterOrderHelper
|
||||
{
|
||||
private FormFactoryInterface $formFactory;
|
||||
private RequestStack $requestStack;
|
||||
private ?array $searchBoxFields = null;
|
||||
private array $checkboxes = [];
|
||||
private ?array $submitted = null;
|
||||
|
||||
private FormFactoryInterface $formFactory;
|
||||
|
||||
private ?string $formName = 'f';
|
||||
private string $formType = FilterOrderType::class;
|
||||
|
||||
private array $formOptions = [];
|
||||
|
||||
private string $formType = FilterOrderType::class;
|
||||
|
||||
private RequestStack $requestStack;
|
||||
|
||||
private ?array $searchBoxFields = null;
|
||||
|
||||
private ?array $submitted = null;
|
||||
|
||||
public function __construct(
|
||||
FormFactoryInterface $formFactory,
|
||||
@@ -27,29 +41,32 @@ class FilterOrderHelper
|
||||
$this->requestStack = $requestStack;
|
||||
}
|
||||
|
||||
public function setSearchBox($searchBoxFields = null): self
|
||||
{
|
||||
$this->searchBoxFields = $searchBoxFields;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function addCheckbox(string $name, array $choices, ?array $default = [], ?array $trans = []): self
|
||||
{
|
||||
$missing = count($choices) - count($trans) - 1;
|
||||
$this->checkboxes[$name] = [
|
||||
'choices' => $choices, 'default' => $default,
|
||||
'trans' =>
|
||||
\array_merge(
|
||||
'trans' => array_merge(
|
||||
$trans,
|
||||
0 < $missing ?
|
||||
array_fill(0, $missing, null) : []
|
||||
)
|
||||
),
|
||||
];
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function buildForm(): FormInterface
|
||||
{
|
||||
return $this->formFactory
|
||||
->createNamed($this->formName, $this->formType, $this->getDefaultData(), array_merge([
|
||||
'helper' => $this,
|
||||
'method' => 'GET',
|
||||
'csrf_protection' => false,
|
||||
], $this->formOptions))
|
||||
->handleRequest($this->requestStack->getCurrentRequest());
|
||||
}
|
||||
|
||||
public function getCheckboxData(string $name): array
|
||||
{
|
||||
return $this->getFormData()['checkboxes'][$name];
|
||||
@@ -60,28 +77,31 @@ class FilterOrderHelper
|
||||
return $this->checkboxes;
|
||||
}
|
||||
|
||||
public function hasSearchBox(): bool
|
||||
public function getQueryString(): ?string
|
||||
{
|
||||
return $this->searchBoxFields !== null;
|
||||
return $this->getFormData()['q'];
|
||||
}
|
||||
|
||||
private function getFormData(): array
|
||||
public function hasSearchBox(): bool
|
||||
{
|
||||
if (NULL === $this->submitted) {
|
||||
$this->submitted = $this->buildForm()
|
||||
->getData();
|
||||
}
|
||||
return null !== $this->searchBoxFields;
|
||||
}
|
||||
|
||||
return $this->submitted;
|
||||
public function setSearchBox($searchBoxFields = null): self
|
||||
{
|
||||
$this->searchBoxFields = $searchBoxFields;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
private function getDefaultData(): array
|
||||
{
|
||||
$r = [];
|
||||
$r = [];
|
||||
|
||||
if ($this->hasSearchBox()) {
|
||||
$r['q'] = '';
|
||||
}
|
||||
|
||||
if ($this->hasSearchBox()) {
|
||||
$r['q'] = '';
|
||||
}
|
||||
foreach ($this->checkboxes as $name => $c) {
|
||||
$r['checkboxes'][$name] = $c['default'];
|
||||
}
|
||||
@@ -89,19 +109,13 @@ class FilterOrderHelper
|
||||
return $r;
|
||||
}
|
||||
|
||||
public function getQueryString(): ?string
|
||||
private function getFormData(): array
|
||||
{
|
||||
return $this->getFormData()['q'];
|
||||
}
|
||||
if (null === $this->submitted) {
|
||||
$this->submitted = $this->buildForm()
|
||||
->getData();
|
||||
}
|
||||
|
||||
public function buildForm(): FormInterface
|
||||
{
|
||||
return $this->formFactory
|
||||
->createNamed($this->formName, $this->formType, $this->getDefaultData(), \array_merge([
|
||||
'helper' => $this,
|
||||
'method' => 'GET',
|
||||
'csrf_protection' => false,
|
||||
], $this->formOptions))
|
||||
->handleRequest($this->requestStack->getCurrentRequest());
|
||||
return $this->submitted;
|
||||
}
|
||||
}
|
||||
|
@@ -1,5 +1,12 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\MainBundle\Templating\Listing;
|
||||
|
||||
use Symfony\Component\Form\FormFactoryInterface;
|
||||
@@ -7,11 +14,14 @@ use Symfony\Component\HttpFoundation\RequestStack;
|
||||
|
||||
class FilterOrderHelperBuilder
|
||||
{
|
||||
private ?array $searchBoxFields = null;
|
||||
private array $checkboxes = [];
|
||||
|
||||
private FormFactoryInterface $formFactory;
|
||||
|
||||
private RequestStack $requestStack;
|
||||
|
||||
private ?array $searchBoxFields = null;
|
||||
|
||||
public function __construct(
|
||||
FormFactoryInterface $formFactory,
|
||||
RequestStack $requestStack
|
||||
@@ -20,16 +30,16 @@ class FilterOrderHelperBuilder
|
||||
$this->requestStack = $requestStack;
|
||||
}
|
||||
|
||||
public function addSearchBox(?array $fields = [], ?array $options = []): self
|
||||
public function addCheckbox(string $name, array $choices, ?array $default = [], ?array $trans = []): self
|
||||
{
|
||||
$this->searchBoxFields = $fields;
|
||||
$this->checkboxes[$name] = ['choices' => $choices, 'default' => $default, 'trans' => $trans];
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function addCheckbox(string $name, array $choices, ?array $default = [], ?array $trans = []): self
|
||||
public function addSearchBox(?array $fields = [], ?array $options = []): self
|
||||
{
|
||||
$this->checkboxes[$name] = [ 'choices' => $choices, 'default' => $default, 'trans' => $trans];
|
||||
$this->searchBoxFields = $fields;
|
||||
|
||||
return $this;
|
||||
}
|
||||
@@ -42,12 +52,13 @@ class FilterOrderHelperBuilder
|
||||
);
|
||||
|
||||
$helper->setSearchBox($this->searchBoxFields);
|
||||
|
||||
foreach ($this->checkboxes as $name => [
|
||||
'choices' => $choices,
|
||||
'default' => $default,
|
||||
'trans' => $trans
|
||||
'trans' => $trans,
|
||||
]) {
|
||||
$helper->addCheckbox($name, $choices, $default, $trans);
|
||||
$helper->addCheckbox($name, $choices, $default, $trans);
|
||||
}
|
||||
|
||||
return $helper;
|
||||
|
@@ -1,14 +1,21 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\MainBundle\Templating\Listing;
|
||||
|
||||
use Symfony\Component\Form\FormFactoryBuilderInterface;
|
||||
use Symfony\Component\Form\FormFactoryInterface;
|
||||
use Symfony\Component\HttpFoundation\RequestStack;
|
||||
|
||||
class FilterOrderHelperFactory implements FilterOrderHelperFactoryInterface
|
||||
{
|
||||
private FormFactoryInterface $formFactory;
|
||||
|
||||
private RequestStack $requestStack;
|
||||
|
||||
public function __construct(
|
||||
|
@@ -1,5 +1,12 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\MainBundle\Templating\Listing;
|
||||
|
||||
interface FilterOrderHelperFactoryInterface
|
||||
|
@@ -1,5 +1,12 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\MainBundle\Templating\Listing;
|
||||
|
||||
use Twig\Environment;
|
||||
@@ -8,27 +15,25 @@ use Twig\TwigFilter;
|
||||
|
||||
class Templating extends AbstractExtension
|
||||
{
|
||||
|
||||
public function getFilters()
|
||||
{
|
||||
return [
|
||||
public function getFilters()
|
||||
{
|
||||
return [
|
||||
new TwigFilter('chill_render_filter_order_helper', [$this, 'renderFilterOrderHelper'], [
|
||||
'needs_environment' => true, 'is_safe' => ['html'],
|
||||
])
|
||||
];
|
||||
}
|
||||
|
||||
public function renderFilterOrderHelper(
|
||||
Environment $environment,
|
||||
FilterOrderHelper $helper,
|
||||
?string $template = '@ChillMain/FilterOrder/base.html.twig',
|
||||
?array $options = []
|
||||
) {
|
||||
return $environment->render($template, [
|
||||
'helper' => $helper,
|
||||
'form' => $helper->buildForm()->createView(),
|
||||
'options' => $options
|
||||
]);
|
||||
}
|
||||
]),
|
||||
];
|
||||
}
|
||||
|
||||
public function renderFilterOrderHelper(
|
||||
Environment $environment,
|
||||
FilterOrderHelper $helper,
|
||||
?string $template = '@ChillMain/FilterOrder/base.html.twig',
|
||||
?array $options = []
|
||||
) {
|
||||
return $environment->render($template, [
|
||||
'helper' => $helper,
|
||||
'form' => $helper->buildForm()->createView(),
|
||||
'options' => $options,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
@@ -1,5 +1,12 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Chill\MainBundle\Templating;
|
||||
@@ -52,5 +59,4 @@ final class TranslatableStringHelper implements TranslatableStringHelperInterfac
|
||||
|
||||
return $translatableStrings[$langs[0]];
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,5 +1,12 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Chill\MainBundle\Templating;
|
||||
|
@@ -1,22 +1,10 @@
|
||||
<?php
|
||||
/*
|
||||
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* Copyright (C) 2014-2015, Champs Libres Cooperative SCRLFS,
|
||||
* <http://www.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/>.
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\MainBundle\Templating;
|
||||
@@ -28,41 +16,35 @@ use Twig\TwigFilter;
|
||||
class TranslatableStringTwig extends AbstractExtension
|
||||
{
|
||||
use ContainerAwareTrait;
|
||||
|
||||
|
||||
/**
|
||||
* @var TranslatableStringHelper $helper
|
||||
* @var TranslatableStringHelper
|
||||
*/
|
||||
private $helper;
|
||||
|
||||
|
||||
/**
|
||||
* TranslatableStringTwig constructor.
|
||||
*
|
||||
* @param TranslatableStringHelper $translatableStringHelper
|
||||
*/
|
||||
public function __construct(TranslatableStringHelper $translatableStringHelper)
|
||||
{
|
||||
$this->helper = $translatableStringHelper;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Returns a list of filters to add to the existing list.
|
||||
*
|
||||
*
|
||||
* (non-PHPdoc)
|
||||
* @see Twig_Extension::getFilters()
|
||||
*/
|
||||
public function getFilters()
|
||||
{
|
||||
return array(
|
||||
return [
|
||||
new TwigFilter(
|
||||
'localize_translatable_string', array($this, 'localize')));
|
||||
'localize_translatable_string',
|
||||
[$this, 'localize']
|
||||
), ];
|
||||
}
|
||||
|
||||
public function localize(array $translatableStrings)
|
||||
{
|
||||
return $this->helper
|
||||
->localize($translatableStrings);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Returns the name of the extension.
|
||||
*
|
||||
@@ -73,4 +55,9 @@ class TranslatableStringTwig extends AbstractExtension
|
||||
return 'chill_main_localize';
|
||||
}
|
||||
|
||||
}
|
||||
public function localize(array $translatableStrings)
|
||||
{
|
||||
return $this->helper
|
||||
->localize($translatableStrings);
|
||||
}
|
||||
}
|
||||
|
@@ -1,51 +1,40 @@
|
||||
<?php
|
||||
/*
|
||||
* Copyright (C) 2018 Champs Libres Cooperative <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\MainBundle\Templating\UI;
|
||||
|
||||
use Symfony\Component\Security\Core\User\UserInterface;
|
||||
use Chill\MainBundle\Entity\User;
|
||||
|
||||
/**
|
||||
* Show a number of notification to user in the upper right corner
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* @author Julien Fastré <julien.fastre@champs-libres.coop>
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\MainBundle\Templating\UI;
|
||||
|
||||
use Chill\MainBundle\Entity\User;
|
||||
use Symfony\Component\Security\Core\User\UserInterface;
|
||||
|
||||
/**
|
||||
* Show a number of notification to user in the upper right corner.
|
||||
*/
|
||||
class CountNotificationUser
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @var NotificationCounterInterface[]
|
||||
*/
|
||||
protected $counters = [];
|
||||
|
||||
|
||||
public function addNotificationCounter(NotificationCounterInterface $counter)
|
||||
{
|
||||
$this->counters[] = $counter;
|
||||
}
|
||||
|
||||
|
||||
public function getSumNotification(UserInterface $u): int
|
||||
{
|
||||
$sum = 0;
|
||||
|
||||
$sum = 0;
|
||||
|
||||
foreach ($this->counters as $counter) {
|
||||
$sum += $counter->addNotification($u);
|
||||
}
|
||||
|
||||
|
||||
return $sum;
|
||||
}
|
||||
}
|
||||
|
@@ -1,32 +1,20 @@
|
||||
<?php
|
||||
/*
|
||||
* Copyright (C) 2018 Champs Libres Cooperative <info@champs-libres.coop>
|
||||
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* 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/>.
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\MainBundle\Templating\UI;
|
||||
|
||||
use Symfony\Component\Security\Core\User\UserInterface;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Julien Fastré <julien.fastre@champs-libres.coop>
|
||||
*/
|
||||
interface NotificationCounterInterface
|
||||
{
|
||||
/**
|
||||
* Add a number of notification
|
||||
* Add a number of notification.
|
||||
*/
|
||||
public function addNotification(UserInterface $u): int;
|
||||
}
|
||||
|
@@ -1,5 +1,12 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\MainBundle\Templating\Widget;
|
||||
|
||||
use Twig\Environment;
|
||||
@@ -7,4 +14,4 @@ use Twig\Environment;
|
||||
interface WidgetInterface
|
||||
{
|
||||
public function render(Environment $env, $place, array $context, array $config);
|
||||
}
|
||||
}
|
||||
|
@@ -1,163 +1,147 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Copyright (C) 2016 Champs-Libres <info@champs-libres.coop>
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* 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/>.
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\MainBundle\Templating\Widget;
|
||||
|
||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||
use Chill\MainBundle\Templating\Widget\WidgetInterface;
|
||||
use Chill\MainBundle\Templating\Events\DelegatedBlockRenderingEvent;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||
use Twig\Environment;
|
||||
use Twig\Extension\AbstractExtension;
|
||||
use Twig\TwigFunction;
|
||||
use function ksort;
|
||||
|
||||
/**
|
||||
* Add the function `chill_delegated_block`.
|
||||
*
|
||||
*
|
||||
* In a template, you can now allow rendering of a block from other bundle.
|
||||
*
|
||||
*
|
||||
* The layout template must explicitly call the rendering of other block,
|
||||
* with the twig function
|
||||
*
|
||||
*
|
||||
* ```
|
||||
* chill_delegated_block('block_name', { 'array' : 'with context' } )
|
||||
* ```
|
||||
*
|
||||
*
|
||||
* This will launch an event
|
||||
* `Chill\MainBundle\Templating\Events\DelegatedBlockRenderingEvent` with
|
||||
* the event's name 'chill_block.block_name'.
|
||||
*
|
||||
*
|
||||
* You may add content to the page using the function
|
||||
* `DelegatedBlockRenderingEvent::addContent`.
|
||||
*
|
||||
* See also the documentation of
|
||||
*
|
||||
* See also the documentation of
|
||||
* `Chill\MainBundle\Templating\Events\DelegatedBlockRenderingEvent`
|
||||
* for usage of this event class
|
||||
*
|
||||
*
|
||||
* @author Julien Fastré <julien.fastre@champs-libres.coop>
|
||||
*/
|
||||
class WidgetRenderingTwig extends AbstractExtension
|
||||
{
|
||||
|
||||
/**
|
||||
* Contains the widget. This is a double dimension array :
|
||||
*
|
||||
* - first key is the place,
|
||||
* - second key is the ordering ;
|
||||
* - the value is an array where the widget is the first argument and the
|
||||
* second is the config
|
||||
*
|
||||
* i.e :
|
||||
*
|
||||
* $widget['place']['ordering'] = array($widget, $config);
|
||||
*
|
||||
*
|
||||
*
|
||||
* @var array an array of widget by place and ordering
|
||||
*/
|
||||
protected $widget = array();
|
||||
|
||||
/**
|
||||
*
|
||||
* @var EventDispatcherInterface
|
||||
*/
|
||||
protected $eventDispatcher;
|
||||
|
||||
|
||||
/**
|
||||
* Contains the widget. This is a double dimension array :.
|
||||
*
|
||||
* - first key is the place,
|
||||
* - second key is the ordering ;
|
||||
* - the value is an array where the widget is the first argument and the
|
||||
* second is the config
|
||||
*
|
||||
* i.e :
|
||||
*
|
||||
* $widget['place']['ordering'] = array($widget, $config);
|
||||
*
|
||||
* @var array an array of widget by place and ordering
|
||||
*/
|
||||
protected $widget = [];
|
||||
|
||||
public function __construct(EventDispatcherInterface $eventDispatcher)
|
||||
{
|
||||
$this->eventDispatcher = $eventDispatcher;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* add a widget to this class, which become available for a future call.
|
||||
*
|
||||
* This function is used by DependencyInjection\CompilerPass\WidgetCompilerPass,
|
||||
* which add the widget to this class when it is created by from DI, according
|
||||
* to the given config under `chill_main`.
|
||||
*
|
||||
* @param string $place
|
||||
* @param WidgetInterface $widget
|
||||
* @param mixed $ordering
|
||||
*/
|
||||
public function addWidget($place, $ordering, $widget, array $config = [])
|
||||
{
|
||||
$this->widget[$place][$ordering] = [$widget, $config];
|
||||
}
|
||||
|
||||
public function getFunctions()
|
||||
{
|
||||
return [
|
||||
new TwigFunction(
|
||||
'chill_delegated_block',
|
||||
[$this, 'renderingWidget'],
|
||||
[
|
||||
'is_safe' => ['html'],
|
||||
'needs_environment' => true,
|
||||
'deprecated' => true, 'alternative' => 'chill_widget',
|
||||
]
|
||||
),
|
||||
new TwigFunction(
|
||||
'chill_widget',
|
||||
[$this, 'renderingWidget'],
|
||||
['is_safe' => ['html'], 'needs_environment' => true]
|
||||
),
|
||||
];
|
||||
}
|
||||
|
||||
public function getName()
|
||||
{
|
||||
return 'chill_main_widget';
|
||||
}
|
||||
|
||||
public function getFunctions()
|
||||
{
|
||||
return array(
|
||||
new TwigFunction('chill_delegated_block',
|
||||
array($this, 'renderingWidget'),
|
||||
array(
|
||||
'is_safe' => array('html'),
|
||||
'needs_environment' => true,
|
||||
'deprecated' => true, 'alternative' => 'chill_widget'
|
||||
)),
|
||||
new TwigFunction('chill_widget',
|
||||
array($this, 'renderingWidget'),
|
||||
array('is_safe' => array('html'), 'needs_environment' => true))
|
||||
);
|
||||
}
|
||||
|
||||
public function renderingWidget(Environment $env, $block, array $context = array())
|
||||
|
||||
public function renderingWidget(Environment $env, $block, array $context = [])
|
||||
{
|
||||
// get the content of widgets
|
||||
$content = '';
|
||||
|
||||
foreach ($this->getWidgetsArraysOrdered($block) as $a) {
|
||||
/* @var $widget Widget\WidgetInterface */
|
||||
$widget = $a[0];
|
||||
$config = $a[1];
|
||||
|
||||
|
||||
$content .= $widget->render($env, $block, $context, $config);
|
||||
}
|
||||
|
||||
|
||||
// for old rendering events (deprecated)
|
||||
$event = new DelegatedBlockRenderingEvent($context);
|
||||
|
||||
$this->eventDispatcher->dispatch('chill_block.'.$block, $event);
|
||||
|
||||
return $content." ".$event->getContent();
|
||||
|
||||
$this->eventDispatcher->dispatch('chill_block.' . $block, $event);
|
||||
|
||||
return $content . ' ' . $event->getContent();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* add a widget to this class, which become available for a future call.
|
||||
*
|
||||
* This function is used by DependencyInjection\CompilerPass\WidgetCompilerPass,
|
||||
* which add the widget to this class when it is created by from DI, according
|
||||
* to the given config under `chill_main`.
|
||||
*
|
||||
* @param string $place
|
||||
* @param WidgetInterface $widget
|
||||
* @param array $config
|
||||
*/
|
||||
public function addWidget($place, $ordering, $widget, array $config = array())
|
||||
{
|
||||
$this->widget[$place][$ordering] = array($widget, $config);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $place
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getWidgetsArraysOrdered($place)
|
||||
{
|
||||
if (!array_key_exists($place, $this->widget)) {
|
||||
$this->widget[$place] = array();
|
||||
$this->widget[$place] = [];
|
||||
}
|
||||
|
||||
\ksort($this->widget[$place]);
|
||||
|
||||
|
||||
ksort($this->widget[$place]);
|
||||
|
||||
return $this->widget[$place];
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user