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

configureEditForm()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 45

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 45
rs 9.2
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\Form\Extension\Core\Type\UrlType;
27
use Symfony\Component\OptionsResolver\OptionsResolver;
28
29
/**
30
 * Twitter share button integration.
31
 *
32
 * @see https://about.twitter.com/resources/buttons#tweet
33
 *
34
 * @author Sylvain Deloux <[email protected]>
35
 */
36
class TwitterShareButtonBlockService extends BaseTwitterButtonBlockService implements EditableBlockService
37
{
38
    /**
39
     * {@inheritdoc}
40
     */
41
    public function configureSettings(OptionsResolver $resolver): void
42
    {
43
        $resolver->setDefaults([
44
            'template' => '@SonataSeo/Block/block_twitter_share_button.html.twig',
45
            'url' => null,
46
            'text' => null,
47
            'show_count' => true,
48
            'via' => null,
49
            'recommend' => null,
50
            'hashtag' => null,
51
            'large_button' => false,
52
            'opt_out' => false,
53
            'language' => $this->languageList['en'],
54
        ]);
55
    }
56
57
    public function configureCreateForm(FormMapper $form, BlockInterface $block): void
58
    {
59
        $this->configureEditForm($form, $block);
60
    }
61
62
    /**
63
     * {@inheritdoc}
64
     */
65
    public function configureEditForm(FormMapper $form, BlockInterface $block): void
66
    {
67
        $form->add('settings', ImmutableArrayType::class, [
68
            'keys' => [
69
                ['url', UrlType::class, [
70
                    'required' => false,
71
                    'label' => 'form.label_url',
72
                ]],
73
                ['text', TextType::class, [
74
                    'required' => false,
75
                    'label' => 'form.label_text',
76
                ]],
77
                ['show_count', CheckboxType::class, [
78
                    'required' => false,
79
                    'label' => 'form.label_show_count',
80
                ]],
81
                ['via', TextType::class, [
82
                    'required' => false,
83
                    'label' => 'form.label_via',
84
                ]],
85
                ['recommend', TextType::class, [
86
                    'required' => false,
87
                    'label' => 'form.label_recommend',
88
                ]],
89
                ['hashtag', TextType::class, [
90
                    'required' => false,
91
                    'label' => 'form.label_hashtag',
92
                ]],
93
                ['large_button', CheckboxType::class, [
94
                    'required' => false,
95
                    'label' => 'form.label_large_button',
96
                ]],
97
                ['opt_out', CheckboxType::class, [
98
                    'required' => false,
99
                    'label' => 'form.label_opt_out',
100
                ]],
101
                ['language', ChoiceType::class, [
102
                    'required' => true,
103
                    'choices' => $this->languageList,
104
                    'label' => 'form.label_language',
105
                ]],
106
            ],
107
            'translation_domain' => 'SonataSeoBundle',
108
        ]);
109
    }
110
111
    public function validate(ErrorElement $errorElement, BlockInterface $block): void
112
    {
113
    }
114
115
    /**
116
     * {@inheritdoc}
117
     */
118
    public function getMetadata(): MetadataInterface
119
    {
120
        return new Metadata('sonata.seo.block.twitter.share_button', null, null, 'SonataSeoBundle', [
121
            'class' => 'fa fa-twitter',
122
        ]);
123
    }
124
}
125