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';
}
}