Completed
Pull Request — master (#356)
by Christian
04:53 queued 02:04
created

configureEditForm()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 39

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 39
rs 9.296
c 0
b 0
f 0
cc 1
nc 1
nop 2
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\CheckboxType;
24
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
25
use Symfony\Component\Form\Extension\Core\Type\IntegerType;
26
use Symfony\Component\Form\Extension\Core\Type\UrlType;
27
use Symfony\Component\OptionsResolver\OptionsResolver;
28
29
/**
30
 * Facebook like button integration.
31
 *
32
 * @see https://developers.facebook.com/docs/plugins/like-button/
33
 *
34
 * @author Sylvain Deloux <[email protected]>
35
 */
36
class FacebookLikeButtonBlockService extends BaseFacebookSocialPluginsBlockService implements EditableBlockService
37
{
38
    /**
39
     * @var string[]
40
     */
41
    protected $layoutList = [
42
        'standard' => 'form.label_layout_standard',
43
        'box_count' => 'form.label_layout_box_count',
44
        'button_count' => 'form.label_layout_button_count',
45
        'button' => 'form.label_layout_button',
46
    ];
47
48
    /**
49
     * @var string[]
50
     */
51
    protected $actionTypes = [
52
        'like' => 'form.label_action_like',
53
        'recommend' => 'form.label_action_recommend',
54
    ];
55
56
    /**
57
     * {@inheritdoc}
58
     */
59
    public function configureSettings(OptionsResolver $resolver): void
60
    {
61
        $resolver->setDefaults([
62
            'template' => '@SonataSeo/Block/block_facebook_like_button.html.twig',
63
            'url' => null,
64
            'width' => null,
65
            'show_faces' => true,
66
            'share' => true,
67
            'layout' => $this->layoutList['standard'],
68
            'colorscheme' => $this->colorschemeList['light'],
69
            'action' => $this->actionTypes['like'],
70
        ]);
71
    }
72
73
    public function configureCreateForm(FormMapper $form, BlockInterface $block): void
74
    {
75
        $this->configureEditForm($form, $block);
76
    }
77
78
    /**
79
     * {@inheritdoc}
80
     */
81
    public function configureEditForm(FormMapper $form, BlockInterface $block): void
82
    {
83
        $form->add('settings', ImmutableArrayType::class, [
84
            'keys' => [
85
                ['url', UrlType::class, [
86
                    'required' => false,
87
                    'label' => 'form.label_url',
88
                ]],
89
                ['width', IntegerType::class, [
90
                    'required' => false,
91
                    'label' => 'form.label_width',
92
                ]],
93
                ['show_faces', CheckboxType::class, [
94
                    'required' => false,
95
                    'label' => 'form.label_show_faces',
96
                ]],
97
                ['share', CheckboxType::class, [
98
                    'required' => false,
99
                    'label' => 'form.label_share',
100
                ]],
101
                ['layout', ChoiceType::class, [
102
                    'required' => true,
103
                    'choices' => $this->layoutList,
104
                    'label' => 'form.label_layout',
105
                ]],
106
                ['colorscheme', ChoiceType::class, [
107
                    'required' => true,
108
                    'choices' => $this->colorschemeList,
109
                    'label' => 'form.label_colorscheme',
110
                ]],
111
                ['action', ChoiceType::class, [
112
                    'required' => true,
113
                    'choices' => $this->actionTypes,
114
                    'label' => 'form.label_action',
115
                ]],
116
            ],
117
            'translation_domain' => 'SonataSeoBundle',
118
        ]);
119
    }
120
121
    public function validate(ErrorElement $errorElement, BlockInterface $block): void
122
    {
123
    }
124
125
    /**
126
     * {@inheritdoc}
127
     */
128
    public function getMetadata(): MetadataInterface
129
    {
130
        return new Metadata('sonata.seo.block.facebook.like_button', null, null, 'SonataSeoBundle', [
131
            'class' => 'fa fa-facebook-official',
132
        ]);
133
    }
134
}
135