<commit_before><?php

namespace Oro\Bundle\ActionBundle\Twig;

use Symfony\Component\HttpFoundation\RequestStack;

use Oro\Bundle\ActionBundle\Helper\ApplicationsHelper;
use Oro\Bundle\ActionBundle\Model\ActionManager;
use Oro\Bundle\EntityBundle\ORM\DoctrineHelper;

class ActionExtension extends \Twig_Extension
{
    const NAME = 'oro_action';

    /** @var ActionManager */
    protected $manager;

    /** @var ApplicationsHelper */
    protected $appsHelper;

    /** @var DoctrineHelper */
    protected $doctrineHelper;

    /** @var RequestStack */
    protected $requestStack;

    /**
     * @param ActionManager $manager
     * @param ApplicationsHelper $appsHelper
     * @param DoctrineHelper $doctrineHelper
     * @param RequestStack $requestStack
     */
    public function __construct(
        ActionManager $manager,
        ApplicationsHelper $appsHelper,
        DoctrineHelper $doctrineHelper,
        RequestStack $requestStack
    ) {
        $this->manager = $manager;
        $this->appsHelper = $appsHelper;
        $this->doctrineHelper = $doctrineHelper;
        $this->requestStack = $requestStack;
    }

    /**
     * {@inheritdoc}
     */
    public function getName()
    {
        return self::NAME;
    }

    /**
     * {@inheritdoc}
     */
    public function getFunctions()
    {
        return array(
            new \Twig_SimpleFunction(
                'oro_action_widget_parameters',
                [$this, 'getWidgetParameters'],
                ['needs_context' => true]
            ),
            new \Twig_SimpleFunction('oro_action_widget_route', [$this, 'getWidgetRoute']),
            new \Twig_SimpleFunction('has_actions', [$this, 'hasActions']),
        );
    }

    /**
     * @param array $context
     * @return array
     */
    public function getWidgetParameters(array $context)
    {
        $request = $this->requestStack->getMasterRequest();

        $params = [
            'route' => $request->get('_route'),
            'fromUrl' => $request->getRequestUri()
        ];

        if (array_key_exists('entity', $context) && is_object($context['entity']) &&
            !$this->doctrineHelper->isNewEntity($context['entity'])
        ) {<commit_msg>BB-2152: Move ActionsBundle to platform - fix 500 error when edit or create not manageable entity<commit_after><?php

namespace Oro\Bundle\ActionBundle\Twig;

use Symfony\Component\HttpFoundation\RequestStack;

use Oro\Bundle\ActionBundle\Helper\ApplicationsHelper;
use Oro\Bundle\ActionBundle\Model\ActionManager;
use Oro\Bundle\EntityBundle\ORM\DoctrineHelper;

class ActionExtension extends \Twig_Extension
{
    const NAME = 'oro_action';

    /** @var ActionManager */
    protected $manager;

    /** @var ApplicationsHelper */
    protected $appsHelper;

    /** @var DoctrineHelper */
    protected $doctrineHelper;

    /** @var RequestStack */
    protected $requestStack;

    /**
     * @param ActionManager $manager
     * @param ApplicationsHelper $appsHelper
     * @param DoctrineHelper $doctrineHelper
     * @param RequestStack $requestStack
     */
    public function __construct(
        ActionManager $manager,
        ApplicationsHelper $appsHelper,
        DoctrineHelper $doctrineHelper,
        RequestStack $requestStack
    ) {
        $this->manager = $manager;
        $this->appsHelper = $appsHelper;
        $this->doctrineHelper = $doctrineHelper;
        $this->requestStack = $requestStack;
    }

    /**
     * {@inheritdoc}
     */
    public function getName()
    {
        return self::NAME;
    }

    /**
     * {@inheritdoc}
     */
    public function getFunctions()
    {
        return array(
            new \Twig_SimpleFunction(
                'oro_action_widget_parameters',
                [$this, 'getWidgetParameters'],
                ['needs_context' => true]
            ),
            new \Twig_SimpleFunction('oro_action_widget_route', [$this, 'getWidgetRoute']),
            new \Twig_SimpleFunction('has_actions', [$this, 'hasActions']),
        );
    }

    /**
     * @param array $context
     * @return array
     */
    public function getWidgetParameters(array $context)
    {
        $request = $this->requestStack->getMasterRequest();

        $params = [
            'route' => $request->get('_route'),
            'fromUrl' => $request->getRequestUri()
        ];

        $entity = array_key_exists('entity', $context) && is_object($context['entity']) ? $context['entity'] : null;

        if ($entity &&
            $this->doctrineHelper->isManageableEntity($entity) &&
            !$this->doctrineHelper->isNewEntity($context['entity'])
        ) {
{'fraction_non_alphanumeric': 0.1254310344827586, 'fraction_numerical': 0.0015086206896551724, 'mean_word_length': 2.484234234234234, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 31, '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': '3829032', 'n_tokens_mistral': 1312, 'n_tokens_neox': 1261, 'n_words': 245}