Completed
Push — master ( 62ab6e...8576ea )
by Sullivan
17:21 queued 14:21
created

TreeBlockService::configureSettings()   B

Complexity

Conditions 5
Paths 1

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 11
rs 8.8571
cc 5
eloc 6
nc 1
nop 1
1
<?php
2
3
/*
4
 * This file is part of the Sonata project.
5
 *
6
 * (c) Thomas Rabaix <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Sonata\DoctrinePHPCRAdminBundle\Block;
13
14
use Sonata\AdminBundle\Form\FormMapper;
15
use Sonata\BlockBundle\Block\BaseBlockService;
16
use Sonata\BlockBundle\Block\BlockContextInterface;
17
use Sonata\BlockBundle\Model\BlockInterface;
18
use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface;
19
use Symfony\Component\HttpFoundation\Response;
20
use Symfony\Component\OptionsResolver\OptionsResolver;
21
22
class TreeBlockService extends BaseBlockService
23
{
24
    /**
25
     * @var array
26
     */
27
    protected $defaults;
28
29
    /**
30
     * @param string          $name
31
     * @param EngineInterface $templating
32
     * @param array           $defaults
33
     */
34
    public function __construct($name, EngineInterface $templating, array $defaults = array())
35
    {
36
        parent::__construct($name, $templating);
37
        $this->defaults = $defaults;
38
    }
39
40
    /**
41
     * {@inheritdoc}
42
     *
43
     * NOOP as there is nothing to edit.
44
     */
45
    public function buildEditForm(FormMapper $form, BlockInterface $block)
46
    {
47
        // there is nothing to edit here!
48
    }
49
50
    /**
51
     * {@inheritdoc}
52
     */
53
    public function execute(BlockContextInterface $blockContext, Response $response = null)
54
    {
55
        return $this->renderResponse($blockContext->getTemplate(), array(
56
            'block'     => $blockContext->getBlock(),
57
            'settings'  => $blockContext->getSettings(),
58
        ), $response);
59
    }
60
61
    /**
62
     * {@inheritdoc}
63
     */
64
    public function configureSettings(OptionsResolver $resolver)
65
    {
66
        // the callables are a workaround to make bundle configuration win over the default values
67
        // see https://github.com/sonata-project/SonataDoctrinePhpcrAdminBundle/pull/345
68
        $resolver->setDefaults(array(
69
            'template'         => function (Options $options, $value) { return $value ?: 'SonataDoctrinePHPCRAdminBundle:Block:tree.html.twig'; },
70
            'id'               => function (Options $options, $value) { return $value ?: '/'; },
71
            'selected'         => function (Options $options, $value) { return $value ?: null; },
72
            'routing_defaults' => function (Options $options, $value) { return $value ?: $this->defaults; },
73
        ));
74
    }
75
}
76