Completed
Push — master ( 2cf16b...bf4a2d )
by Jordi Sala
13:35 queued 22s
created

FacebookSendButtonBlockService::buildEditForm()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 25

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 25
rs 9.52
c 0
b 0
f 0
cc 1
nc 1
nop 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A FacebookSendButtonBlockService::configureCreateForm() 0 4 1
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\Service\EditableBlockService;
17
use Sonata\BlockBundle\Form\Mapper\FormMapper;
18
use Sonata\BlockBundle\Meta\Metadata;
19
use Sonata\BlockBundle\Meta\MetadataInterface;
20
use Sonata\BlockBundle\Model\BlockInterface;
21
use Sonata\Form\Type\ImmutableArrayType;
22
use Sonata\Form\Validator\ErrorElement;
23
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
24
use Symfony\Component\Form\Extension\Core\Type\IntegerType;
25
use Symfony\Component\Form\Extension\Core\Type\UrlType;
26
use Symfony\Component\OptionsResolver\OptionsResolver;
27
28
/**
29
 * Facebook send button integration.
30
 *
31
 * @see https://developers.facebook.com/docs/plugins/send-button/
32
 *
33
 * @author Sylvain Deloux <[email protected]>
34
 */
35
final class FacebookSendButtonBlockService extends BaseFacebookSocialPluginsBlockService implements EditableBlockService
36
{
37
    public function configureSettings(OptionsResolver $resolver): void
38
    {
39
        $resolver->setDefaults([
40
            'template' => '@SonataSeo/Block/block_facebook_send_button.html.twig',
41
            'url' => null,
42
            'width' => null,
43
            'height' => null,
44
            'colorscheme' => $this->colorschemeList['light'],
45
        ]);
46
    }
47
48
    public function configureCreateForm(FormMapper $formMapper, BlockInterface $block): void
49
    {
50
        $this->configureEditForm($formMapper, $block);
51
    }
52
53
    public function configureEditForm(FormMapper $formMapper, BlockInterface $block): void
54
    {
55
        $formMapper->add('settings', ImmutableArrayType::class, [
56
            'keys' => [
57
                ['url', UrlType::class, [
58
                    'required' => false,
59
                    'label' => 'form.label_url',
60
                ]],
61
                ['width', IntegerType::class, [
62
                    'required' => false,
63
                    'label' => 'form.label_width',
64
                ]],
65
                ['height', IntegerType::class, [
66
                    'required' => false,
67
                    'label' => 'form.label_height',
68
                ]],
69
                ['colorscheme', ChoiceType::class, [
70
                    'required' => true,
71
                    'choices' => $this->colorschemeList,
72
                    'label' => 'form.label_colorscheme',
73
                ]],
74
            ],
75
            'translation_domain' => 'SonataSeoBundle',
76
        ]);
77
    }
78
79
    public function validate(ErrorElement $errorElement, BlockInterface $block): void
80
    {
81
    }
82
83
    public function getMetadata(): MetadataInterface
84
    {
85
        return new Metadata('sonata.seo.block.facebook.send_button', null, null, 'SonataSeoBundle', [
86
            'class' => 'fa fa-facebook-official',
87
        ]);
88
    }
89
}
90