Completed
Pull Request — 1.x (#473)
by Maximilian
02:36 queued 52s
created

TreeBlockService::configureSettings()   B

Complexity

Conditions 5
Paths 1

Size

Total Lines 19
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 19
rs 8.8571
c 0
b 0
f 0
cc 5
eloc 10
nc 1
nop 1
1
<?php
2
3
/*
4
 * This file is part of the Sonata Project package.
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\Options;
21
use Symfony\Component\OptionsResolver\OptionsResolver;
22
23
class TreeBlockService extends BaseBlockService
0 ignored issues
show
Deprecated Code introduced by
The class Sonata\BlockBundle\Block\BaseBlockService has been deprecated with message: since 3.2, to be removed with 4.0

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
24
{
25
    /**
26
     * @var array
27
     */
28
    protected $defaults;
29
30
    /**
31
     * @param string          $name
32
     * @param EngineInterface $templating
33
     * @param array           $defaults
34
     */
35
    public function __construct($name, EngineInterface $templating, array $defaults = array())
36
    {
37
        parent::__construct($name, $templating);
38
        $this->defaults = $defaults;
39
    }
40
41
    /**
42
     * {@inheritdoc}
43
     *
44
     * NOOP as there is nothing to edit.
45
     */
46
    public function buildEditForm(FormMapper $form, BlockInterface $block)
47
    {
48
        // there is nothing to edit here!
49
    }
50
51
    /**
52
     * {@inheritdoc}
53
     */
54
    public function execute(BlockContextInterface $blockContext, Response $response = null)
55
    {
56
        return $this->renderResponse($blockContext->getTemplate(), array(
57
            'block' => $blockContext->getBlock(),
58
            'settings' => $blockContext->getSettings(),
59
        ), $response);
60
    }
61
62
    /**
63
     * {@inheritdoc}
64
     */
65
    public function configureSettings(OptionsResolver $resolver)
66
    {
67
        // the callables are a workaround to make bundle configuration win over the default values
68
        // see https://github.com/sonata-project/SonataDoctrinePhpcrAdminBundle/pull/345
69
        $resolver->setDefaults(array(
70
            'template' => function (Options $options, $value) {
71
                return $value ?: 'SonataDoctrinePHPCRAdminBundle:Block:tree.html.twig';
72
            },
73
            'id' => function (Options $options, $value) {
74
                return $value ?: '/';
75
            },
76
            'selected' => function (Options $options, $value) {
77
                return $value ?: null;
78
            },
79
            'routing_defaults' => function (Options $options, $value) {
80
                return $value ?: $this->defaults;
81
            },
82
        ));
83
    }
84
}
85