Completed
Pull Request — master (#356)
by Christian
03:38
created

FacebookLikeBoxBlockService   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 84
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A configureSettings() 0 14 1
A configureCreateForm() 0 4 1
A configureEditForm() 0 41 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 box integration.
31
 *
32
 * @see https://developers.facebook.com/docs/plugins/like-box-for-pages/
33
 *
34
 * @author Sylvain Deloux <[email protected]>
35
 */
36
class FacebookLikeBoxBlockService extends BaseFacebookSocialPluginsBlockService implements EditableBlockService
37
{
38
    /**
39
     * {@inheritdoc}
40
     */
41
    public function configureSettings(OptionsResolver $resolver): void
42
    {
43
        $resolver->setDefaults([
44
            'template' => '@SonataSeo/Block/block_facebook_like_box.html.twig',
45
            'url' => null,
46
            'width' => null,
47
            'height' => null,
48
            'colorscheme' => $this->colorschemeList['light'],
49
            'show_faces' => true,
50
            'show_header' => true,
51
            'show_posts' => false,
52
            'show_border' => true,
53
        ]);
54
    }
55
56
    public function configureCreateForm(FormMapper $form, BlockInterface $block): void
57
    {
58
        $this->configureEditForm($form, $block);
59
    }
60
61
    /**
62
     * {@inheritdoc}
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
                ['height', IntegerType::class, [
77
                    'required' => false,
78
                    'label' => 'form.label_height',
79
                ]],
80
                ['colorscheme', ChoiceType::class, [
81
                    'required' => true,
82
                    'choices' => $this->colorschemeList,
83
                    'label' => 'form.label_colorscheme',
84
                ]],
85
                ['show_faces', CheckboxType::class, [
86
                    'required' => false,
87
                    'label' => 'form.label_show_faces',
88
                ]],
89
                ['show_header', CheckboxType::class, [
90
                    'required' => false,
91
                    'label' => 'form.label_show_header',
92
                ]],
93
                ['show_posts', CheckboxType::class, [
94
                    'required' => false,
95
                    'label' => 'form.label_show_posts',
96
                ]],
97
                ['show_border', CheckboxType::class, [
98
                    'required' => false,
99
                    'label' => 'form.label_show_border',
100
                ]],
101
            ],
102
            'translation_domain' => 'SonataSeoBundle',
103
        ]);
104
    }
105
106
    public function validate(ErrorElement $errorElement, BlockInterface $block): void
107
    {
108
    }
109
110
    /**
111
     * {@inheritdoc}
112
     */
113
    public function getMetadata(): MetadataInterface
114
    {
115
        return new Metadata('sonata.seo.block.facebook.like_box', null, null, 'SonataSeoBundle', [
116
            'class' => 'fa fa-facebook-official',
117
        ]);
118
    }
119
}
120