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\ChoiceType; |
24
|
|
|
use Symfony\Component\Form\Extension\Core\Type\IntegerType; |
25
|
|
|
use Symfony\Component\Form\Extension\Core\Type\UrlType; |
26
|
|
|
use Symfony\Component\OptionsResolver\OptionsResolver; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Facebook share button integration. |
30
|
|
|
* |
31
|
|
|
* @see https://developers.facebook.com/docs/plugins/share-button/ |
32
|
|
|
* |
33
|
|
|
* @author Sylvain Deloux <[email protected]> |
34
|
|
|
*/ |
35
|
|
|
class FacebookShareButtonBlockService extends BaseFacebookSocialPluginsBlockService implements EditableBlockService |
36
|
|
|
{ |
37
|
|
|
/** |
38
|
|
|
* @var string[] |
39
|
|
|
*/ |
40
|
|
|
protected $layoutList = [ |
41
|
|
|
'box_count' => 'form.label_layout_box_count', |
42
|
|
|
'button_count' => 'form.label_layout_button_count', |
43
|
|
|
'button' => 'form.label_layout_button', |
44
|
|
|
'icon_link' => 'form.label_layout_icon_link', |
45
|
|
|
'icon' => 'form.label_layout_icon', |
46
|
|
|
'link' => 'form.label_layout_link', |
47
|
|
|
]; |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* {@inheritdoc} |
51
|
|
|
*/ |
52
|
|
|
public function configureSettings(OptionsResolver $resolver): void |
53
|
|
|
{ |
54
|
|
|
$resolver->setDefaults([ |
55
|
|
|
'template' => '@SonataSeo/Block/block_facebook_share_button.html.twig', |
56
|
|
|
'url' => null, |
57
|
|
|
'width' => null, |
58
|
|
|
'layout' => $this->layoutList['box_count'], |
59
|
|
|
]); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
public function configureCreateForm(FormMapper $form, BlockInterface $block): void |
63
|
|
|
{ |
64
|
|
|
$this->configureEditForm($form, $block); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* {@inheritdoc} |
69
|
|
|
*/ |
70
|
|
|
public function configureEditForm(FormMapper $form, BlockInterface $block): void |
71
|
|
|
{ |
72
|
|
|
$form->add('settings', ImmutableArrayType::class, [ |
73
|
|
|
'keys' => [ |
74
|
|
|
['url', UrlType::class, [ |
75
|
|
|
'required' => false, |
76
|
|
|
'label' => 'form.label_url', |
77
|
|
|
]], |
78
|
|
|
['width', IntegerType::class, [ |
79
|
|
|
'required' => false, |
80
|
|
|
'label' => 'form.label_width', |
81
|
|
|
]], |
82
|
|
|
['layout', ChoiceType::class, [ |
83
|
|
|
'required' => true, |
84
|
|
|
'choices' => $this->layoutList, |
85
|
|
|
'label' => 'form.label_layout', |
86
|
|
|
]], |
87
|
|
|
], |
88
|
|
|
'translation_domain' => 'SonataSeoBundle', |
89
|
|
|
]); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
public function validate(ErrorElement $errorElement, BlockInterface $block): void |
93
|
|
|
{ |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* {@inheritdoc} |
98
|
|
|
*/ |
99
|
|
|
public function getMetadata(): MetadataInterface |
100
|
|
|
{ |
101
|
|
|
return new Metadata('sonata.seo.block.facebook.share_button', null, null, 'SonataSeoBundle', [ |
102
|
|
|
'class' => 'fa fa-facebook-official', |
103
|
|
|
]); |
104
|
|
|
} |
105
|
|
|
} |
106
|
|
|
|