Completed
Pull Request — master (#356)
by Christian
09:45
created

FacebookShareButtonBlockService::buildEditForm()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 21

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 21
rs 9.584
c 0
b 0
f 0
cc 1
nc 1
nop 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A FacebookShareButtonBlockService::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 share button integration.
30
 *
31
 * @see https://developers.facebook.com/docs/plugins/share-button/
32
 *
33
 * @author Sylvain Deloux <[email protected]>
34
 */
35
final class FacebookShareButtonBlockService extends BaseFacebookSocialPluginsBlockService implements EditableBlockService
36
{
37
    /**
38
     * @var string[]
39
     */
40
    protected $layoutList = [
41
        'box_count' => 'form.label_layout_box_count',
42
        'button_count' => 'form.label_layout_button_count',
43
        'button' => 'form.label_layout_button',
44
        'icon_link' => 'form.label_layout_icon_link',
45
        'icon' => 'form.label_layout_icon',
46
        'link' => 'form.label_layout_link',
47
    ];
48
49
    public function configureSettings(OptionsResolver $resolver): void
50
    {
51
        $resolver->setDefaults([
52
            'template' => '@SonataSeo/Block/block_facebook_share_button.html.twig',
53
            'url' => null,
54
            'width' => null,
55
            'layout' => $this->layoutList['box_count'],
56
        ]);
57
    }
58
59
    public function configureCreateForm(FormMapper $form, BlockInterface $block): void
60
    {
61
        $this->configureEditForm($form, $block);
62
    }
63
64
    public function configureEditForm(FormMapper $form, BlockInterface $block): void
65
    {
66
        $form->add('settings', ImmutableArrayType::class, [
67
            'keys' => [
68
                ['url', UrlType::class, [
69
                    'required' => false,
70
                    'label' => 'form.label_url',
71
                ]],
72
                ['width', IntegerType::class, [
73
                    'required' => false,
74
                    'label' => 'form.label_width',
75
                ]],
76
                ['layout', ChoiceType::class, [
77
                    'required' => true,
78
                    'choices' => $this->layoutList,
79
                    'label' => 'form.label_layout',
80
                ]],
81
            ],
82
            'translation_domain' => 'SonataSeoBundle',
83
        ]);
84
    }
85
86
    public function validate(ErrorElement $errorElement, BlockInterface $block): void
87
    {
88
    }
89
90
    public function getMetadata(): MetadataInterface
91
    {
92
        return new Metadata('sonata.seo.block.facebook.share_button', null, null, 'SonataSeoBundle', [
93
            'class' => 'fa fa-facebook-official',
94
        ]);
95
    }
96
}
97