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

configureCreateForm()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
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
final class TwitterShareButtonBlockService extends BaseTwitterButtonBlockService implements EditableBlockService
37
{
38
    public function configureSettings(OptionsResolver $resolver): void
39
    {
40
        $resolver->setDefaults([
41
            'template' => '@SonataSeo/Block/block_twitter_share_button.html.twig',
42
            'url' => null,
43
            'text' => null,
44
            'show_count' => true,
45
            'via' => null,
46
            'recommend' => null,
47
            'hashtag' => null,
48
            'large_button' => false,
49
            'opt_out' => false,
50
            'language' => $this->languageList['en'],
51
        ]);
52
    }
53
54
    public function configureCreateForm(FormMapper $formMapper, BlockInterface $block): void
55
    {
56
        $this->configureEditForm($formMapper, $block);
57
    }
58
59
    public function configureEditForm(FormMapper $formMapper, BlockInterface $block): void
60
    {
61
        $formMapper->add('settings', ImmutableArrayType::class, [
62
            'keys' => [
63
                ['url', UrlType::class, [
64
                    'required' => false,
65
                    'label' => 'form.label_url',
66
                ]],
67
                ['text', TextType::class, [
68
                    'required' => false,
69
                    'label' => 'form.label_text',
70
                ]],
71
                ['show_count', CheckboxType::class, [
72
                    'required' => false,
73
                    'label' => 'form.label_show_count',
74
                ]],
75
                ['via', TextType::class, [
76
                    'required' => false,
77
                    'label' => 'form.label_via',
78
                ]],
79
                ['recommend', TextType::class, [
80
                    'required' => false,
81
                    'label' => 'form.label_recommend',
82
                ]],
83
                ['hashtag', TextType::class, [
84
                    'required' => false,
85
                    'label' => 'form.label_hashtag',
86
                ]],
87
                ['large_button', CheckboxType::class, [
88
                    'required' => false,
89
                    'label' => 'form.label_large_button',
90
                ]],
91
                ['opt_out', CheckboxType::class, [
92
                    'required' => false,
93
                    'label' => 'form.label_opt_out',
94
                ]],
95
                ['language', ChoiceType::class, [
96
                    'required' => true,
97
                    'choices' => $this->languageList,
98
                    'label' => 'form.label_language',
99
                ]],
100
            ],
101
            'translation_domain' => 'SonataSeoBundle',
102
        ]);
103
    }
104
105
    public function validate(ErrorElement $errorElement, BlockInterface $block): void
106
    {
107
    }
108
109
    public function getMetadata(): MetadataInterface
110
    {
111
        return new Metadata('sonata.seo.block.twitter.share_button', null, null, 'SonataSeoBundle', [
112
            'class' => 'fa fa-twitter',
113
        ]);
114
    }
115
}
116