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

configureEditForm()   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
<?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
class FacebookSendButtonBlockService extends BaseFacebookSocialPluginsBlockService implements EditableBlockService
36
{
37
    /**
38
     * {@inheritdoc}
39
     */
40
    public function configureSettings(OptionsResolver $resolver): void
41
    {
42
        $resolver->setDefaults([
43
            'template' => '@SonataSeo/Block/block_facebook_send_button.html.twig',
44
            'url' => null,
45
            'width' => null,
46
            'height' => null,
47
            'colorscheme' => $this->colorschemeList['light'],
48
        ]);
49
    }
50
51
    public function configureCreateForm(FormMapper $form, BlockInterface $block): void
52
    {
53
        $this->configureEditForm($form, $block);
54
    }
55
56
    /**
57
     * {@inheritdoc}
58
     */
59
    public function configureEditForm(FormMapper $form, BlockInterface $block): void
60
    {
61
        $form->add('settings', ImmutableArrayType::class, [
62
            'keys' => [
63
                ['url', UrlType::class, [
64
                    'required' => false,
65
                    'label' => 'form.label_url',
66
                ]],
67
                ['width', IntegerType::class, [
68
                    'required' => false,
69
                    'label' => 'form.label_width',
70
                ]],
71
                ['height', IntegerType::class, [
72
                    'required' => false,
73
                    'label' => 'form.label_height',
74
                ]],
75
                ['colorscheme', ChoiceType::class, [
76
                    'required' => true,
77
                    'choices' => $this->colorschemeList,
78
                    'label' => 'form.label_colorscheme',
79
                ]],
80
            ],
81
            'translation_domain' => 'SonataSeoBundle',
82
        ]);
83
    }
84
85
    public function validate(ErrorElement $errorElement, BlockInterface $block): void
86
    {
87
    }
88
89
    /**
90
     * {@inheritdoc}
91
     */
92
    public function getMetadata(): MetadataInterface
93
    {
94
        return new Metadata('sonata.seo.block.facebook.send_button', null, null, 'SonataSeoBundle', [
95
            'class' => 'fa fa-facebook-official',
96
        ]);
97
    }
98
}
99