<commit_before><?php

/*
 * This file is part of the Sonata Project package.
 *
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Sonata\AdminBundle\Twig\Extension;

use Doctrine\Common\Util\ClassUtils;
use Psr\Log\LoggerInterface;
use Sonata\AdminBundle\Admin\AdminInterface;
use Sonata\AdminBundle\Admin\FieldDescriptionInterface;
use Sonata\AdminBundle\Admin\Pool;
use Sonata\AdminBundle\Exception\NoValueException;
use Twig_Environment;

/**
 * Class SonataAdminExtension.
 *
 * @author  <NAME> <<EMAIL>>
 */
class SonataAdminExtension extends \Twig_Extension implements \Twig_Extension_InitRuntimeInterface
{
    /**
     * @var Pool
     */
    protected $pool;

    /**
     * @var LoggerInterface
     */
    protected $logger;

    /**
     * @param Pool            $pool
     * @param LoggerInterface $logger
     */
    public function __construct(Pool $pool, LoggerInterface $logger = null)
    {
        $this->pool      = $pool;
        $this->logger    = $logger;
    }

    /**
     * {@inheritdoc}
     */
    public function getFilters()
    {
        return array(
            new \Twig_SimpleFilter(
                'render_list_element',
                array($this, 'renderListElement'),
                array('is_safe'     => array('html'),
                'needs_environment' => true, )
            ),
            new \Twig_SimpleFilter(
                'render_view_element',
                array($this, 'renderViewElement'),
                array('is_safe'     => array('html'),
                'needs_environment' => true, )
            ),
            new \Twig_SimpleFilter(
                'render_view_element_compare',
                array($this, 'renderViewElementCompare'),
                array('is_safe' => array('html'))
            ),
            new \Twig_SimpleFilter(
                'render_relation_element',
                array($this, 'renderRelationElement')
            ),
            new \Twig_SimpleFilter(
                'sonata_urlsafeid',
                array($this, 'getUrlsafeIdentifier')
            ),
            new \Twig_SimpleFilter(
                'sonata_xeditable_type',
                array($this, 'getXEditableType')
            ),
        );
    }

    /**
     * {@inheritdoc}
     */
    public function getName()
    {
        return 'sonata_admin';
    }

    /**
     * Get template.
     *
     * @param FieldDescriptionInterface $fieldDescription
     * @param string                    $defaultTemplate
     *
     * @return \Twig_Template
     */
    protected function getTemplate(
        FieldDescriptionInterface $fieldDescription,
        $defaultTemplate,
        Twig_Environment $environment
    ) {
        $templateName = $fieldDescription->getTemplate() ?: $defaultTemplate;

        try {
            $template = $environment->loadTemplate($templateName);
        } catch (\Twig_Error_Loader $e) {
            $template = $environment->loadTemplate($defaultTemplate);

            if (null !== $this->logger) {
                $this->logger->warning(sprintf(
                    'An error occured trying to load the template "%s" for the field "%s", '.
                    'the default template "%s" was used instead: "%s". ',
                    $templateName,
                    $fieldDescription->getFieldName(),
                    $defaultTemplate,
                    $e->getMessage()
                ));
            }
        }

        return $template;
    }

    /**
     * render a list element from the FieldDescription.
     *
     * @param mixed                     $object
     * @param FieldDescriptionInterface $fieldDescription
     * @param array                     $params
     *
     * @return string
     */
    public function renderListElement(
        Twig_Environment $environment,
        $object,
        FieldDescriptionInterface $fieldDescription,
        $params = array()
    ) {
        $template = $this->getTemplate(
            $fieldDescription,
            $fieldDescription->getAdmin()->getTemplate('base_list_field'),
            $environment
        );

        return $this->output($fieldDescription, $template, array_merge($params, array(
            'admin'             => $fieldDescription->getAdmin(),
            'object'            => $object,
            'value'             => $this->getValueFromFieldDescription($object, $fieldDescription),
            'field_description' => $fieldDescription,
        )), $environment);
    }

    /**
     * @param FieldDescriptionInterface $fieldDescription
     * @param \Twig_Template            $template
     * @param array                     $parameters
     *
     * @return string
     */
    public function output(
        FieldDescriptionInterface $fieldDescription,
        \Twig_Template $template,
        array $parameters = array(),
        Twig_Environment $environment
    ) {<commit_msg>remove default value<commit_after><?php

/*
 * This file is part of the Sonata Project package.
 *
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Sonata\AdminBundle\Twig\Extension;

use Doctrine\Common\Util\ClassUtils;
use Psr\Log\LoggerInterface;
use Sonata\AdminBundle\Admin\AdminInterface;
use Sonata\AdminBundle\Admin\FieldDescriptionInterface;
use Sonata\AdminBundle\Admin\Pool;
use Sonata\AdminBundle\Exception\NoValueException;
use Twig_Environment;

/**
 * Class SonataAdminExtension.
 *
 * @author  <NAME> <<EMAIL>>
 */
class SonataAdminExtension extends \Twig_Extension implements \Twig_Extension_InitRuntimeInterface
{
    /**
     * @var Pool
     */
    protected $pool;

    /**
     * @var LoggerInterface
     */
    protected $logger;

    /**
     * @param Pool            $pool
     * @param LoggerInterface $logger
     */
    public function __construct(Pool $pool, LoggerInterface $logger = null)
    {
        $this->pool      = $pool;
        $this->logger    = $logger;
    }

    /**
     * {@inheritdoc}
     */
    public function getFilters()
    {
        return array(
            new \Twig_SimpleFilter(
                'render_list_element',
                array($this, 'renderListElement'),
                array('is_safe'     => array('html'),
                'needs_environment' => true, )
            ),
            new \Twig_SimpleFilter(
                'render_view_element',
                array($this, 'renderViewElement'),
                array('is_safe'     => array('html'),
                'needs_environment' => true, )
            ),
            new \Twig_SimpleFilter(
                'render_view_element_compare',
                array($this, 'renderViewElementCompare'),
                array('is_safe' => array('html'))
            ),
            new \Twig_SimpleFilter(
                'render_relation_element',
                array($this, 'renderRelationElement')
            ),
            new \Twig_SimpleFilter(
                'sonata_urlsafeid',
                array($this, 'getUrlsafeIdentifier')
            ),
            new \Twig_SimpleFilter(
                'sonata_xeditable_type',
                array($this, 'getXEditableType')
            ),
        );
    }

    /**
     * {@inheritdoc}
     */
    public function getName()
    {
        return 'sonata_admin';
    }

    /**
     * Get template.
     *
     * @param FieldDescriptionInterface $fieldDescription
     * @param string                    $defaultTemplate
     *
     * @return \Twig_Template
     */
    protected function getTemplate(
        FieldDescriptionInterface $fieldDescription,
        $defaultTemplate,
        Twig_Environment $environment
    ) {
        $templateName = $fieldDescription->getTemplate() ?: $defaultTemplate;

        try {
            $template = $environment->loadTemplate($templateName);
        } catch (\Twig_Error_Loader $e) {
            $template = $environment->loadTemplate($defaultTemplate);

            if (null !== $this->logger) {
                $this->logger->warning(sprintf(
                    'An error occured trying to load the template "%s" for the field "%s", '.
                    'the default template "%s" was used instead: "%s". ',
                    $templateName,
                    $fieldDescription->getFieldName(),
                    $defaultTemplate,
                    $e->getMessage()
                ));
            }
        }

        return $template;
    }

    /**
     * render a list element from the FieldDescription.
     *
     * @param mixed                     $object
     * @param FieldDescriptionInterface $fieldDescription
     * @param array                     $params
     *
     * @return string
     */
    public function renderListElement(
        Twig_Environment $environment,
        $object,
        FieldDescriptionInterface $fieldDescription,
        $params = array()
    ) {
        $template = $this->getTemplate(
            $fieldDescription,
            $fieldDescription->getAdmin()->getTemplate('base_list_field'),
            $environment
        );

        return $this->output($fieldDescription, $template, array_merge($params, array(
            'admin'             => $fieldDescription->getAdmin(),
            'object'            => $object,
            'value'             => $this->getValueFromFieldDescription($object, $fieldDescription),
            'field_description' => $fieldDescription,
        )), $environment);
    }

    /**
     * @param FieldDescriptionInterface $fieldDescription
     * @param \Twig_Template            $template
     * @param array                     $parameters
     *
     * @return string
     */
    public function output(
        FieldDescriptionInterface $fieldDescription,
        \Twig_Template $template,
        array $parameters,
        Twig_Environment $environment
    ) {
{'fraction_non_alphanumeric': 0.10775991211425147, 'fraction_numerical': 0.0, 'mean_word_length': 1.7870860005566378, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 65, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '116502', 'n_tokens_mistral': 2577, 'n_tokens_neox': 2512, 'n_words': 535}