FacebookLikeButtonBlockService   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 90
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 4
dl 0
loc 90
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A configureSettings() 0 13 1
A configureCreateForm() 0 4 1
A configureEditForm() 0 39 1
A validate() 0 3 1
A getMetadata() 0 6 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\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
final 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
    public function configureSettings(OptionsResolver $resolver): void
57
    {
58
        $resolver->setDefaults([
59
            'template' => '@SonataSeo/Block/block_facebook_like_button.html.twig',
60
            'url' => null,
61
            'width' => null,
62
            'show_faces' => true,
63
            'share' => true,
64
            'layout' => $this->layoutList['standard'],
65
            'colorscheme' => $this->colorschemeList['light'],
66
            'action' => $this->actionTypes['like'],
67
        ]);
68
    }
69
70
    public function configureCreateForm(FormMapper $formMapper, BlockInterface $block): void
71
    {
72
        $this->configureEditForm($formMapper, $block);
73
    }
74
75
    public function configureEditForm(FormMapper $formMapper, BlockInterface $block): void
76
    {
77
        $formMapper->add('settings', ImmutableArrayType::class, [
78
            'keys' => [
79
                ['url', UrlType::class, [
80
                    'required' => false,
81
                    'label' => 'form.label_url',
82
                ]],
83
                ['width', IntegerType::class, [
84
                    'required' => false,
85
                    'label' => 'form.label_width',
86
                ]],
87
                ['show_faces', CheckboxType::class, [
88
                    'required' => false,
89
                    'label' => 'form.label_show_faces',
90
                ]],
91
                ['share', CheckboxType::class, [
92
                    'required' => false,
93
                    'label' => 'form.label_share',
94
                ]],
95
                ['layout', ChoiceType::class, [
96
                    'required' => true,
97
                    'choices' => $this->layoutList,
98
                    'label' => 'form.label_layout',
99
                ]],
100
                ['colorscheme', ChoiceType::class, [
101
                    'required' => true,
102
                    'choices' => $this->colorschemeList,
103
                    'label' => 'form.label_colorscheme',
104
                ]],
105
                ['action', ChoiceType::class, [
106
                    'required' => true,
107
                    'choices' => $this->actionTypes,
108
                    'label' => 'form.label_action',
109
                ]],
110
            ],
111
            'translation_domain' => 'SonataSeoBundle',
112
        ]);
113
    }
114
115
    public function validate(ErrorElement $errorElement, BlockInterface $block): void
116
    {
117
    }
118
119
    public function getMetadata(): MetadataInterface
120
    {
121
        return new Metadata('sonata.seo.block.facebook.like_button', null, null, 'SonataSeoBundle', [
122
            'class' => 'fa fa-facebook-official',
123
        ]);
124
    }
125
}
126