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

configureEditForm()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 29

Duplication

Lines 0
Ratio 0 %

Importance

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