Completed
Push — 1.2 ( d3ea0d...d8c512 )
by David
16:21
created

TreeBlockService   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 3
Bugs 2 Features 1
Metric Value
wmc 9
c 3
b 2
f 1
lcom 1
cbo 3
dl 0
loc 62
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A buildEditForm() 0 4 1
A execute() 0 7 1
B setDefaultSettings() 0 9 5
A validateBlock() 0 4 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\AdminBundle\Validator\ErrorElement;
16
use Sonata\BlockBundle\Block\BaseBlockService;
17
use Sonata\BlockBundle\Block\BlockContextInterface;
18
use Sonata\BlockBundle\Model\BlockInterface;
19
use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface;
20
use Symfony\Component\HttpFoundation\Response;
21
use Symfony\Component\OptionsResolver\Options;
22
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
23
24
class TreeBlockService extends BaseBlockService
25
{
26
    /**
27
     * @var array
28
     */
29
    protected $defaults;
30
31
    /**
32
     * @param string $name
33
     * @param EngineInterface $templating
34
     * @param array $defaults
35
     */
36
    public function __construct($name, EngineInterface $templating, array $defaults = array())
37
    {
38
        parent::__construct($name, $templating);
39
        $this->defaults = $defaults;
40
    }
41
42
    /**
43
     * {@inheritDoc}
44
     *
45
     * NOOP as there is nothing to edit.
46
     */
47
    public function buildEditForm(FormMapper $form, BlockInterface $block)
48
    {
49
        // there is nothing to edit here!
50
    }
51
52
    /**
53
     * {@inheritDoc}
54
     */
55
    public function execute(BlockContextInterface $blockContext, Response $response = null)
56
    {
57
        return $this->renderResponse($blockContext->getTemplate(), array(
58
            'block'     => $blockContext->getBlock(),
59
            'settings'  => $blockContext->getSettings(),
60
        ), $response);
61
    }
62
63
    /**
64
     * {@inheritDoc}
65
     */
66
    public function setDefaultSettings(OptionsResolverInterface $resolver)
67
    {
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
    /**
77
     * {@inheritDoc}
78
     *
79
     * NOOP as we do not edit and hence have nothing to validate.
80
     */
81
    public function validateBlock(ErrorElement $errorElement, BlockInterface $block)
82
    {
83
        // there is nothing to validate here
84
    }
85
}
86