|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/* |
|
6
|
|
|
* (c) Christian Gripp <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Core23\ShariffBundle\Block\Service; |
|
13
|
|
|
|
|
14
|
|
|
use Sonata\BlockBundle\Block\BlockContextInterface; |
|
15
|
|
|
use Sonata\BlockBundle\Block\Service\AbstractBlockService; |
|
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\TextType; |
|
25
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
26
|
|
|
use Symfony\Component\OptionsResolver\OptionsResolver; |
|
27
|
|
|
|
|
28
|
|
|
final class ShariffShareBlockService extends AbstractBlockService implements EditableBlockService |
|
29
|
|
|
{ |
|
30
|
|
|
public function execute(BlockContextInterface $blockContext, Response $response = null) |
|
31
|
|
|
{ |
|
32
|
|
|
$parameters = [ |
|
33
|
|
|
'context' => $blockContext, |
|
34
|
|
|
'settings' => $blockContext->getSettings(), |
|
35
|
|
|
'block' => $blockContext->getBlock(), |
|
36
|
|
|
]; |
|
37
|
|
|
|
|
38
|
|
|
return $this->renderResponse($blockContext->getTemplate(), $parameters, $response); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
public function configureCreateForm(FormMapper $form, BlockInterface $block): void |
|
42
|
|
|
{ |
|
43
|
|
|
$this->configureEditForm($form, $block); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
public function configureEditForm(FormMapper $formMapper, BlockInterface $block): void |
|
47
|
|
|
{ |
|
48
|
|
|
$formMapper->add('settings', ImmutableArrayType::class, [ |
|
49
|
|
|
'keys' => [ |
|
50
|
|
|
['url', TextType::class, [ |
|
51
|
|
|
'label' => 'form.label_url', |
|
52
|
|
|
'required' => false, |
|
53
|
|
|
]], |
|
54
|
|
|
['class', TextType::class, [ |
|
55
|
|
|
'label' => 'form.label_class', |
|
56
|
|
|
'required' => false, |
|
57
|
|
|
]], |
|
58
|
|
|
['services', ChoiceType::class, [ |
|
59
|
|
|
'label' => 'form.label_services', |
|
60
|
|
|
'choices' => [ |
|
61
|
|
|
'form.choice_twitter' => 'twitter', |
|
62
|
|
|
'form.choice_facebook' => 'facebook', |
|
63
|
|
|
'form.choice_googleplus' => 'googleplus', |
|
64
|
|
|
'form.choice_addthis' => 'addthis', |
|
65
|
|
|
'form.choice_linkedin' => 'linkedin', |
|
66
|
|
|
'form.choice_reddit' => 'reddit', |
|
67
|
|
|
'form.choice_stumbleupon' => 'stumbleupon', |
|
68
|
|
|
'form.choice_flattr' => 'flattr', |
|
69
|
|
|
'form.choice_pinterest' => 'pinterest', |
|
70
|
|
|
'form.choice_xing' => 'xing', |
|
71
|
|
|
'form.choice_mail' => 'mail', |
|
72
|
|
|
], |
|
73
|
|
|
'required' => false, |
|
74
|
|
|
'multiple' => true, |
|
75
|
|
|
]], |
|
76
|
|
|
['theme', ChoiceType::class, [ |
|
77
|
|
|
'label' => 'form.label_theme', |
|
78
|
|
|
'choices' => [ |
|
79
|
|
|
'standard' => 'standard', |
|
80
|
|
|
'grey' => 'grey', |
|
81
|
|
|
'white' => 'white', |
|
82
|
|
|
], |
|
83
|
|
|
'choice_translation_domain' => false, |
|
84
|
|
|
]], |
|
85
|
|
|
['orientation', ChoiceType::class, [ |
|
86
|
|
|
'label' => 'form.label_orientation', |
|
87
|
|
|
'choices' => [ |
|
88
|
|
|
'form.choice_vertical' => 'vertical', |
|
89
|
|
|
'form.choice_horizontal' => 'horizontal', |
|
90
|
|
|
], |
|
91
|
|
|
]], |
|
92
|
|
|
['flattrUser', TextType::class, [ |
|
93
|
|
|
'label' => 'form.label_flattr_user', |
|
94
|
|
|
'required' => false, |
|
95
|
|
|
]], |
|
96
|
|
|
['flattrCategory', TextType::class, [ |
|
97
|
|
|
'label' => 'form.label_flattr_category', |
|
98
|
|
|
'required' => false, |
|
99
|
|
|
]], |
|
100
|
|
|
], |
|
101
|
|
|
'translation_domain' => 'Core23ShariffBundle', |
|
102
|
|
|
]); |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
public function configureSettings(OptionsResolver $resolver): void |
|
106
|
|
|
{ |
|
107
|
|
|
$resolver->setDefaults([ |
|
108
|
|
|
'url' => null, |
|
109
|
|
|
'class' => null, |
|
110
|
|
|
'services' => ['twitter', 'facebook', 'googleplus'], |
|
111
|
|
|
'theme' => 'standard', |
|
112
|
|
|
'orientation' => 'horizontal', |
|
113
|
|
|
'flattrUser' => null, |
|
114
|
|
|
'flattrCategory' => null, |
|
115
|
|
|
'template' => '@Core23Shariff/Block/block_shariff.html.twig', |
|
116
|
|
|
]); |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
public function validate(ErrorElement $errorElement, BlockInterface $block): void |
|
120
|
|
|
{ |
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
|
|
public function getMetadata(): MetadataInterface |
|
124
|
|
|
{ |
|
125
|
|
|
return new Metadata($this->getName(), null, null, 'Core23ShariffBundle', [ |
|
126
|
|
|
'class' => 'fa fa-share-square-o', |
|
127
|
|
|
]); |
|
128
|
|
|
} |
|
129
|
|
|
} |
|
130
|
|
|
|