Actualización

This commit is contained in:
Xes
2025-04-10 12:24:57 +02:00
parent 8969cc929d
commit 45420b6f0d
39760 changed files with 4303286 additions and 0 deletions

View File

@@ -0,0 +1,41 @@
<?php
/*
* This file is part of the Sonata Project package.
*
* (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Sonata\CoreBundle\Twig\Extension;
/**
* NEXT_MAJOR : remove this class and the twig/extensions dependency.
*
* @deprecated since version 3.2, to be removed in 4.0.
*/
final class DeprecatedTextExtension extends \Twig_Extensions_Extension_Text
{
public function twig_truncate_filter(\Twig_Environment $env, $value, $length = 30, $preserve = false, $separator = '...')
{
$this->notifyDeprecation();
return parent::twig_truncate_filter($env, $value, $length, $preserve, $separator);
}
public function twig_wordwrap_filter(\Twig_Environment $env, $value, $length = 80, $separator = "\n", $preserve = false)
{
$this->notifyDeprecation();
return parent::twig_wordwrap_filter($env, $value, $length, $separator, $preserve);
}
private function notifyDeprecation()
{
@trigger_error(
'Using the sonata.core.twig.extension.text service is deprecated since 3.2 and will be removed in 4.0'
);
}
}

View File

@@ -0,0 +1,77 @@
<?php
/*
* This file is part of the Sonata Project package.
*
* (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Sonata\CoreBundle\Twig\Extension;
use Sonata\CoreBundle\FlashMessage\FlashManager;
/**
* This is the Sonata core flash message Twig extension.
*
* @author Vincent Composieux <composieux@ekino.com>
*/
class FlashMessageExtension extends \Twig_Extension
{
/**
* @var FlashManager
*/
protected $flashManager;
/**
* @param FlashManager $flashManager
*/
public function __construct(FlashManager $flashManager)
{
$this->flashManager = $flashManager;
}
/**
* {@inheritdoc}
*/
public function getFunctions()
{
return array(
new \Twig_SimpleFunction('sonata_flashmessages_get', array($this, 'getFlashMessages')),
new \Twig_SimpleFunction('sonata_flashmessages_types', array($this, 'getFlashMessagesTypes')),
);
}
/**
* Returns flash messages handled by Sonata core flash manager.
*
* @param string $type Type of flash message
* @param string $domain Translation domain to use
*
* @return string
*/
public function getFlashMessages($type, $domain = null)
{
return $this->flashManager->get($type, $domain);
}
/**
* Returns flash messages types handled by Sonata core flash manager.
*
* @return string
*/
public function getFlashMessagesTypes()
{
return $this->flashManager->getHandledTypes();
}
/**
* {@inheritdoc}
*/
public function getName()
{
return 'sonata_core_flashmessage';
}
}

View File

@@ -0,0 +1,46 @@
<?php
/*
* This file is part of the Sonata Project package.
*
* (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Sonata\CoreBundle\Twig\Extension;
class FormTypeExtension extends \Twig_Extension implements \Twig_Extension_GlobalsInterface
{
/**
* @var bool
*/
private $wrapFieldsWithAddons;
/**
* @param $formType
*/
public function __construct($formType)
{
$this->wrapFieldsWithAddons = (true === $formType || $formType === 'standard');
}
/**
* {@inheritdoc}
*/
public function getGlobals()
{
return array(
'wrap_fields_with_addons' => $this->wrapFieldsWithAddons,
);
}
/**
* {@inheritdoc}
*/
public function getName()
{
return 'sonata_core_wrapping';
}
}

View File

@@ -0,0 +1,72 @@
<?php
/*
* This file is part of the Sonata Project package.
*
* (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Sonata\CoreBundle\Twig\Extension;
use Sonata\CoreBundle\Component\Status\StatusClassRendererInterface;
/**
* @author Hugo Briand <briand@ekino.com>
*/
class StatusExtension extends \Twig_Extension
{
/**
* @var StatusClassRendererInterface[]
*/
protected $statusServices = array();
/**
* Adds a renderer to the status services list.
*
* @param StatusClassRendererInterface $renderer
*/
public function addStatusService(StatusClassRendererInterface $renderer)
{
$this->statusServices[] = $renderer;
}
/**
* {@inheritdoc}
*/
public function getFilters()
{
return array(
new \Twig_SimpleFilter('sonata_status_class', array($this, 'statusClass')),
);
}
/**
* @param mixed $object
* @param mixed $statusType
* @param string $default
*
* @return string
*/
public function statusClass($object, $statusType = null, $default = '')
{
/** @var StatusClassRendererInterface $statusService */
foreach ($this->statusServices as $statusService) {
if ($statusService->handlesObject($object, $statusType)) {
return $statusService->getStatusClass($object, $statusType, $default);
}
}
return $default;
}
/**
* {@inheritdoc}
*/
public function getName()
{
return 'sonata_core_status';
}
}

View File

@@ -0,0 +1,114 @@
<?php
/*
* This file is part of the Sonata Project package.
*
* (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Sonata\CoreBundle\Twig\Extension;
use Sonata\CoreBundle\Model\Adapter\AdapterInterface;
use Sonata\CoreBundle\Twig\TokenParser\TemplateBoxTokenParser;
use Symfony\Component\Translation\TranslatorInterface;
class TemplateExtension extends \Twig_Extension
{
/**
* @var bool
*/
protected $debug;
/**
* @var AdapterInterface
*/
protected $modelAdapter;
/**
* @var TranslatorInterface
*/
protected $translator;
/**
* @param bool $debug Is Symfony debug enabled?
* @param TranslatorInterface $translator Symfony Translator service
* @param AdapterInterface $modelAdapter A Sonata model adapter
*/
public function __construct($debug, TranslatorInterface $translator, AdapterInterface $modelAdapter)
{
$this->debug = $debug;
$this->translator = $translator;
$this->modelAdapter = $modelAdapter;
}
/**
* {@inheritdoc}
*/
public function getFilters()
{
return array(
new \Twig_SimpleFilter('sonata_slugify', array($this, 'slugify'), array('deprecated' => true, 'alternative' => 'slugify')),
new \Twig_SimpleFilter('sonata_urlsafeid', array($this, 'getUrlsafeIdentifier')),
);
}
/**
* {@inheritdoc}
*/
public function getTokenParsers()
{
return array(
new TemplateBoxTokenParser($this->debug, $this->translator),
);
}
/**
* Slugify a text.
*
* @param $text
*
* @return string
*/
public function slugify($text)
{
// replace non letter or digits by -
$text = preg_replace('~[^\\pL\d]+~u', '-', $text);
// trim
$text = trim($text, '-');
// transliterate
if (function_exists('iconv')) {
$text = iconv('UTF-8', 'ASCII//TRANSLIT', $text);
}
// lowercase
$text = strtolower($text);
// remove unwanted characters
$text = preg_replace('~[^-\w]+~', '', $text);
return $text;
}
/**
* @param $model
*
* @return string
*/
public function getUrlsafeIdentifier($model)
{
return $this->modelAdapter->getUrlsafeIdentifier($model);
}
/**
* {@inheritdoc}
*/
public function getName()
{
return 'sonata_core_template';
}
}

View File

@@ -0,0 +1,86 @@
<?php
/*
* This file is part of the Sonata Project package.
*
* (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Sonata\CoreBundle\Twig\Node;
use Symfony\Component\Translation\TranslatorInterface;
class TemplateBoxNode extends \Twig_Node
{
/**
* @var int
*/
protected $enabled;
/**
* @var TranslatorInterface
*/
protected $translator;
/**
* @param \Twig_Node_Expression $message Node message to display
* @param \Twig_Node_Expression $translationBundle Node translation bundle to use for display
* @param int $enabled Is Symfony debug enabled?
* @param TranslatorInterface $translator Symfony Translator service
* @param null|string $lineno Symfony template line number
* @param null $tag Symfony tag name
*/
public function __construct(\Twig_Node_Expression $message, \Twig_Node_Expression $translationBundle = null, $enabled, TranslatorInterface $translator, $lineno, $tag = null)
{
$this->enabled = $enabled;
$this->translator = $translator;
$nodes = array('message' => $message);
if ($translationBundle) {
$nodes['translationBundle'] = $translationBundle;
}
parent::__construct($nodes, array(), $lineno, $tag);
}
/**
* {@inheritdoc}
*/
public function compile(\Twig_Compiler $compiler)
{
$compiler
->addDebugInfo($this);
if (!$this->enabled) {
$compiler->write("// token for sonata_template_box, however the box is disabled\n");
return;
}
$value = $this->getNode('message')->getAttribute('value');
$translationBundle = null;
if ($this->hasNode('translationBundle')) {
$translationBundle = $this->getNode('translationBundle');
}
if ($translationBundle) {
$translationBundle = $translationBundle->getAttribute('value');
}
$message = <<<CODE
"<div class='alert alert-default alert-info'>
<strong>{$this->translator->trans($value, array(), $translationBundle)}</strong>
<div>{$this->translator->trans('sonata_core_template_box_file_found_in', array(), 'SonataCoreBundle')} <code>{\$this->getTemplateName()}</code>.</div>
</div>"
CODE;
$compiler
->write("echo $message;");
}
}

View File

@@ -0,0 +1,68 @@
<?php
/*
* This file is part of the Sonata Project package.
*
* (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Sonata\CoreBundle\Twig\TokenParser;
use Sonata\CoreBundle\Twig\Node\TemplateBoxNode;
use Symfony\Component\Translation\TranslatorInterface;
class TemplateBoxTokenParser extends \Twig_TokenParser
{
/**
* @var bool
*/
protected $enabled;
/**
* @var TranslatorInterface
*/
protected $translator;
/**
* @param bool $enabled Is Symfony debug enabled?
* @param TranslatorInterface $translator Symfony Translator service
*/
public function __construct($enabled, TranslatorInterface $translator)
{
$this->enabled = $enabled;
$this->translator = $translator;
}
/**
* {@inheritdoc}
*/
public function parse(\Twig_Token $token)
{
if ($this->parser->getStream()->test(\Twig_Token::STRING_TYPE)) {
$message = $this->parser->getExpressionParser()->parseExpression();
} else {
$message = new \Twig_Node_Expression_Constant('Template information', $token->getLine());
}
if ($this->parser->getStream()->test(\Twig_Token::STRING_TYPE)) {
$translationBundle = $this->parser->getExpressionParser()->parseExpression();
} else {
$translationBundle = null;
}
$this->parser->getStream()->expect(\Twig_Token::BLOCK_END_TYPE);
return new TemplateBoxNode($message, $translationBundle, $this->enabled, $this->translator, $token->getLine(), $this->getTag());
}
/**
* {@inheritdoc}
*/
public function getTag()
{
return 'sonata_template_box';
}
}