Completed
Push — master ( 2cf16b...bf4a2d )
by Jordi Sala
13:35 queued 22s
created

configureEditForm()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 33

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 33
rs 9.392
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\TextType;
26
use Symfony\Component\OptionsResolver\OptionsResolver;
27
28
/**
29
 * Twitter mention button integration.
30
 *
31
 * @see https://about.twitter.com/resources/buttons#mention
32
 *
33
 * @author Sylvain Deloux <[email protected]>
34
 */
35
final class TwitterMentionButtonBlockService extends BaseTwitterButtonBlockService implements EditableBlockService
36
{
37
    public function configureSettings(OptionsResolver $resolver): void
38
    {
39
        $resolver->setDefaults([
40
            'template' => '@SonataSeo/Block/block_twitter_mention_button.html.twig',
41
            'user' => null,
42
            'text' => null,
43
            'recommend' => null,
44
            'large_button' => false,
45
            'opt_out' => false,
46
            'language' => $this->languageList['en'],
47
        ]);
48
    }
49
50
    public function configureCreateForm(FormMapper $formMapper, BlockInterface $block): void
51
    {
52
        $this->configureEditForm($formMapper, $block);
53
    }
54
55
    public function configureEditForm(FormMapper $formMapper, BlockInterface $block): void
56
    {
57
        $formMapper->add('settings', ImmutableArrayType::class, [
58
            'keys' => [
59
                ['user', TextType::class, [
60
                    'required' => true,
61
                    'label' => 'form.label_user',
62
                ]],
63
                ['text', TextType::class, [
64
                    'required' => false,
65
                    'label' => 'form.label_text',
66
                ]],
67
                ['recommend', TextType::class, [
68
                    'required' => false,
69
                    'label' => 'form.label_recommend',
70
                ]],
71
                ['large_button', CheckboxType::class, [
72
                    'required' => false,
73
                    'label' => 'form.label_large_button',
74
                ]],
75
                ['opt_out', CheckboxType::class, [
76
                    'required' => false,
77
                    'label' => 'form.label_opt_out',
78
                ]],
79
                ['language', ChoiceType::class, [
80
                    'required' => true,
81
                    'choices' => $this->languageList,
82
                    'label' => 'form.label_language',
83
                ]],
84
            ],
85
            'translation_domain' => 'SonataSeoBundle',
86
        ]);
87
    }
88
89
    public function validate(ErrorElement $errorElement, BlockInterface $block): void
90
    {
91
    }
92
93
    public function getMetadata(): MetadataInterface
94
    {
95
        return new Metadata('sonata.seo.block.twitter.mention_button', null, null, 'SonataSeoBundle', [
96
            'class' => 'fa fa-twitter',
97
        ]);
98
    }
99
}
100