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
|
|
|
final class TwitterFollowButtonBlockService extends BaseTwitterButtonBlockService implements EditableBlockService |
36
|
|
|
{ |
37
|
|
|
public function configureSettings(OptionsResolver $resolver): void |
38
|
|
|
{ |
39
|
|
|
$resolver->setDefaults([ |
40
|
|
|
'template' => '@SonataSeo/Block/block_twitter_follow_button.html.twig', |
41
|
|
|
'user' => null, |
42
|
|
|
'show_username' => true, |
43
|
|
|
'large_button' => false, |
44
|
|
|
'opt_out' => false, |
45
|
|
|
'language' => $this->languageList['en'], |
46
|
|
|
]); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function configureCreateForm(FormMapper $formMapper, BlockInterface $block): void |
50
|
|
|
{ |
51
|
|
|
$this->configureEditForm($formMapper, $block); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public function configureEditForm(FormMapper $formMapper, BlockInterface $block): void |
55
|
|
|
{ |
56
|
|
|
$formMapper->add('settings', ImmutableArrayType::class, [ |
57
|
|
|
'keys' => [ |
58
|
|
|
['user', TextType::class, [ |
59
|
|
|
'required' => true, |
60
|
|
|
'label' => 'form.label_user', |
61
|
|
|
]], |
62
|
|
|
['show_username', CheckboxType::class, [ |
63
|
|
|
'required' => false, |
64
|
|
|
'label' => 'form.label_show_username', |
65
|
|
|
]], |
66
|
|
|
['large_button', CheckboxType::class, [ |
67
|
|
|
'required' => false, |
68
|
|
|
'label' => 'form.label_large_button', |
69
|
|
|
]], |
70
|
|
|
['opt_out', CheckboxType::class, [ |
71
|
|
|
'required' => false, |
72
|
|
|
'label' => 'form.label_opt_out', |
73
|
|
|
]], |
74
|
|
|
['language', ChoiceType::class, [ |
75
|
|
|
'required' => true, |
76
|
|
|
'choices' => $this->languageList, |
77
|
|
|
'label' => 'form.label_language', |
78
|
|
|
]], |
79
|
|
|
], |
80
|
|
|
'translation_domain' => 'SonataSeoBundle', |
81
|
|
|
]); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
public function validate(ErrorElement $errorElement, BlockInterface $block): void |
85
|
|
|
{ |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
public function getMetadata(): MetadataInterface |
89
|
|
|
{ |
90
|
|
|
return new Metadata('sonata.seo.block.twitter.follow_button', null, null, 'SonataSeoBundle', [ |
91
|
|
|
'class' => 'fa fa-twitter', |
92
|
|
|
]); |
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
|