Completed
Push — master ( 389b32...637f4d )
by Grégoire
13s queued 10s
created

Block/Social/PinterestPinButtonBlockService.php (1 issue)

Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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\AdminBundle\Form\FormMapper;
17
use Sonata\BlockBundle\Block\BlockContextInterface;
18
use Sonata\BlockBundle\Block\Service\AbstractAdminBlockService;
19
use Sonata\BlockBundle\Model\BlockInterface;
20
use Sonata\CoreBundle\Form\Type\ImmutableArrayType;
21
use Sonata\CoreBundle\Model\Metadata;
22
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
23
use Symfony\Component\Form\Extension\Core\Type\IntegerType;
24
use Symfony\Component\Form\Extension\Core\Type\TextType;
25
use Symfony\Component\Form\Extension\Core\Type\UrlType;
26
use Symfony\Component\HttpFoundation\Response;
27
use Symfony\Component\OptionsResolver\OptionsResolver;
28
29
/**
30
 * Pinterest pin button integration.
31
 *
32
 * @see http://fr.business.pinterest.com/widget-builder/#do_pin_it_button
33
 *
34
 * @author Vincent Composieux <[email protected]>
35
 */
36
final class PinterestPinButtonBlockService extends AbstractAdminBlockService
37
{
38
    public function configureSettings(OptionsResolver $resolver): void
39
    {
40
        $resolver->setDefaults([
41
            'template' => '@SonataSeo/Block/block_pinterest_pin_button.html.twig',
42
            'size' => null,
43
            'shape' => null,
44
            'url' => null,
45
            'image' => null,
46
            'description' => null,
47
        ]);
48
    }
49
50
    public function buildEditForm(FormMapper $formMapper, BlockInterface $block): void
51
    {
52
        $formMapper->add('settings', ImmutableArrayType::class, [
53
            'keys' => [
54
                ['url', UrlType::class, [
55
                    'required' => false,
56
                    'label' => 'form.label_url',
57
                ]],
58
                ['image', TextType::class, [
59
                    'required' => false,
60
                    'label' => 'form.label_image',
61
                ]],
62
                ['description', TextType::class, [
63
                    'required' => false,
64
                    'label' => 'form.label_description',
65
                ]],
66
                ['size', IntegerType::class, [
67
                    'required' => false,
68
                    'label' => 'form.label_size',
69
                ]],
70
                ['shape', ChoiceType::class, [
71
                    'required' => false,
72
                    'choices' => [
73
                        'rectangular' => 'form.label_shape_rectangular',
74
                        'round' => 'form.label_shape_round',
75
                    ],
76
                    'label' => 'form.label_shape',
77
                ]],
78
            ],
79
            'translation_domain' => 'SonataSeoBundle',
80
        ]);
81
    }
82
83
    public function execute(BlockContextInterface $blockContext, Response $response = null)
84
    {
85
        $block = $blockContext->getBlock();
86
        $settings = array_merge($blockContext->getSettings(), $block->getSettings());
87
88
        return $this->renderResponse($blockContext->getTemplate(), [
89
            'block' => $blockContext->getBlock(),
90
            'settings' => $settings,
91
        ], $response);
92
    }
93
94
    public function getBlockMetadata($code = null)
95
    {
96
        return new Metadata($this->getName(), (null !== $code ? $code : $this->getName()), false, 'SonataSeoBundle', [
0 ignored issues
show
Deprecated Code introduced by
The class Sonata\CoreBundle\Model\Metadata has been deprecated with message: since sonata-project/core-bundle 3.13.0, to be removed in 4.0. Use Sonata\BlockBundle\Meta\Metadata instead.

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...
97
            'class' => 'fa fa-pinterest-p',
98
        ]);
99
    }
100
}
101