PinterestPinButtonBlockService::getMetadata()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Sonata Project package.
7
 *
8
 * (c) Thomas Rabaix <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Sonata\SeoBundle\Block\Social;
15
16
use Sonata\BlockBundle\Block\BlockContextInterface;
17
use Sonata\BlockBundle\Block\Service\AbstractBlockService;
18
use Sonata\BlockBundle\Block\Service\EditableBlockService;
19
use Sonata\BlockBundle\Form\Mapper\FormMapper;
20
use Sonata\BlockBundle\Meta\Metadata;
21
use Sonata\BlockBundle\Meta\MetadataInterface;
22
use Sonata\BlockBundle\Model\BlockInterface;
23
use Sonata\Form\Type\ImmutableArrayType;
24
use Sonata\Form\Validator\ErrorElement;
25
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
26
use Symfony\Component\Form\Extension\Core\Type\IntegerType;
27
use Symfony\Component\Form\Extension\Core\Type\TextType;
28
use Symfony\Component\Form\Extension\Core\Type\UrlType;
29
use Symfony\Component\HttpFoundation\Response;
30
use Symfony\Component\OptionsResolver\OptionsResolver;
31
32
/**
33
 * Pinterest pin button integration.
34
 *
35
 * @see http://fr.business.pinterest.com/widget-builder/#do_pin_it_button
36
 *
37
 * @author Vincent Composieux <[email protected]>
38
 */
39
final class PinterestPinButtonBlockService extends AbstractBlockService implements EditableBlockService
40
{
41
    public function configureSettings(OptionsResolver $resolver): void
42
    {
43
        $resolver->setDefaults([
44
            'template' => '@SonataSeo/Block/block_pinterest_pin_button.html.twig',
45
            'size' => null,
46
            'shape' => null,
47
            'url' => null,
48
            'image' => null,
49
            'description' => null,
50
        ]);
51
    }
52
53
    public function configureCreateForm(FormMapper $formMapper, BlockInterface $block): void
54
    {
55
        $this->configureEditForm($formMapper, $block);
56
    }
57
58
    public function configureEditForm(FormMapper $formMapper, BlockInterface $block): void
59
    {
60
        $formMapper->add('settings', ImmutableArrayType::class, [
61
            'keys' => [
62
                ['url', UrlType::class, [
63
                    'required' => false,
64
                    'label' => 'form.label_url',
65
                ]],
66
                ['image', TextType::class, [
67
                    'required' => false,
68
                    'label' => 'form.label_image',
69
                ]],
70
                ['description', TextType::class, [
71
                    'required' => false,
72
                    'label' => 'form.label_description',
73
                ]],
74
                ['size', IntegerType::class, [
75
                    'required' => false,
76
                    'label' => 'form.label_size',
77
                ]],
78
                ['shape', ChoiceType::class, [
79
                    'required' => false,
80
                    'choices' => [
81
                        'rectangular' => 'form.label_shape_rectangular',
82
                        'round' => 'form.label_shape_round',
83
                    ],
84
                    'label' => 'form.label_shape',
85
                ]],
86
            ],
87
            'translation_domain' => 'SonataSeoBundle',
88
        ]);
89
    }
90
91
    public function execute(BlockContextInterface $blockContext, ?Response $response = null): Response
92
    {
93
        $block = $blockContext->getBlock();
94
        $settings = array_merge($blockContext->getSettings(), $block->getSettings());
95
96
        return $this->renderResponse($blockContext->getTemplate(), [
97
            'block' => $blockContext->getBlock(),
98
            'settings' => $settings,
99
        ], $response);
100
    }
101
102
    public function validate(ErrorElement $errorElement, BlockInterface $block): void
103
    {
104
    }
105
106
    public function getMetadata(): MetadataInterface
107
    {
108
        return new Metadata('sonata.seo.block.pinterest.pin_button', null, null, 'SonataSeoBundle', [
109
            'class' => 'fa fa-pinterest-p',
110
        ]);
111
    }
112
}
113