<commit_before><?php

/*
 * This file is part of the Integrated package.
 *
 * (c) e-Active B.V. <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Integrated\Bundle\WebsiteBundle\Twig\Extension;

use Symfony\Component\OptionsResolver\OptionsResolver;

use Integrated\Bundle\PageBundle\Document\Page\Page;
use Integrated\Bundle\PageBundle\Document\Page\Grid\Grid;

/**
 * @author <NAME> <<EMAIL>>
 */
class GridExtension extends \Twig_Extension
{
    /**
     * @var OptionsResolver
     */
    protected $resolver;

    /**
     */
    public function __construct()
    {
        $this->resolver = new OptionsResolver();
        $this->resolver->setDefaults([
            'template' => 'IntegratedWebsiteBundle:Page:grid.html.twig',
        ]);
    }

    /**
     * {@inheritdoc}
     */
    public function getFunctions()
    {
        return [
            new \Twig_SimpleFunction(
                'integrated_grid',
                [$this, 'renderGrid'],
                ['is_safe' => ['html'], 'needs_environment' => true, 'needs_context' => true]
            ),
        ];
    }

    /**
     * @param \Twig_Environment $environment
     * @param array $context
     * @param string $id
     * @param array $options
     * @return string
     */
    public function renderGrid(\Twig_Environment $environment, $context, $id, array $options = [])
    {
        $options = $this->resolver->resolve($options);

        $edit = isset($context['integrated_block_edit']) && true === $context['integrated_block_edit'];
        $page = isset($context['page']) ? $context['page'] : null;

        $html = '';

        if ($edit) {
            $html .= '<div class="integrated-website-grid integrated-website-droppable" data-id="' . $id . '">';
        }

        if ($page instanceof Page) {
            $grid = $page->getGrid($id);

            if (!$grid instanceof Grid) {
                $grid = new Grid($id);
            }

            if ($edit) {
                $html .= '<script type="text/json">' . json_encode(['data' => $grid->toArray()]) . '</script>';
            }

            $html .= $environment->render($options['template'], ['grid' => $grid]);
        }

        if ($edit) {
            $html .= '</div>';
        }

        return $html;
    }

    /**
     * {@inheritdoc}
     */
    public function getName()
    {
        return 'integrated_website_grid';
    }
}<commit_msg>[INTEGRATED-428] Show blocks in edit mode<commit_after><?php

/*
 * This file is part of the Integrated package.
 *
 * (c) e-Active B.V. <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Integrated\Bundle\WebsiteBundle\Twig\Extension;

use Symfony\Component\OptionsResolver\OptionsResolver;

use Integrated\Bundle\PageBundle\Document\Page\Page;
use Integrated\Bundle\PageBundle\Document\Page\Grid\Grid;

/**
 * @author <NAME> <<EMAIL>>
 */
class GridExtension extends \Twig_Extension
{
    /**
     * @var OptionsResolver
     */
    protected $resolver;

    /**
     */
    public function __construct()
    {
        $this->resolver = new OptionsResolver();
        $this->resolver->setDefaults([
            'template' => 'IntegratedWebsiteBundle:Page:grid.html.twig',
        ]);
    }

    /**
     * {@inheritdoc}
     */
    public function getFunctions()
    {
        return [
            new \Twig_SimpleFunction(
                'integrated_grid',
                [$this, 'renderGrid'],
                ['is_safe' => ['html'], 'needs_environment' => true, 'needs_context' => true]
            ),
        ];
    }

    /**
     * @param \Twig_Environment $environment
     * @param array $context
     * @param string $id
     * @param array $options
     *
     * @return string
     */
    public function renderGrid(\Twig_Environment $environment, $context, $id, array $options = [])
    {
        $options = $this->resolver->resolve($options);

        $edit = isset($context['integrated_block_edit']) && true === $context['integrated_block_edit'];
        $page = isset($context['page']) ? $context['page'] : null;

        $html = '';

        if ($edit) {
            $html .= '<div class="integrated-website-grid integrated-website-droppable" data-id="' . $id . '">';
        }

        if ($page instanceof Page) {
            $grid = $page->getGrid($id);

            if (!$grid instanceof Grid) {
                $grid = new Grid($id);
            }

            if ($edit) {
                $html .= '<script type="text/json">' . json_encode(['data' => $grid->toArray()]) . '</script>';
            }

            $html .= $environment->render($options['template'], [
                'integrated_block_edit' => $edit,
                'grid' => $grid,
            ]);
        }

        if ($edit) {
            $html .= '</div>';
        }

        return $html;
    }

    /**
     * {@inheritdoc}
     */
    public function getName()
    {
        return 'integrated_website_grid';
    }
}
{'fraction_non_alphanumeric': 0.1563231850117096, 'fraction_numerical': 0.000585480093676815, 'mean_word_length': 2.032544378698225, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 50, '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': '6865251', 'n_tokens_mistral': 1511, 'n_tokens_neox': 1440, 'n_words': 315}