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\AdminBundle\Form\FormMapper; |
15
|
|
|
use Sonata\BlockBundle\Block\BlockContextInterface; |
16
|
|
|
use Sonata\BlockBundle\Block\Service\AbstractAdminBlockService; |
17
|
|
|
use Sonata\BlockBundle\Model\BlockInterface; |
18
|
|
|
use Sonata\CoreBundle\Form\Type\ImmutableArrayType; |
19
|
|
|
use Sonata\CoreBundle\Model\Metadata; |
20
|
|
|
use Symfony\Component\Form\Extension\Core\Type\ChoiceType; |
21
|
|
|
use Symfony\Component\Form\Extension\Core\Type\TextType; |
22
|
|
|
use Symfony\Component\HttpFoundation\Response; |
23
|
|
|
use Symfony\Component\OptionsResolver\OptionsResolver; |
24
|
|
|
|
25
|
|
|
final class ShariffShareBlockService extends AbstractAdminBlockService |
26
|
|
|
{ |
27
|
|
|
/** |
28
|
|
|
* {@inheritdoc} |
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
|
|
|
/** |
42
|
|
|
* {@inheritdoc} |
43
|
|
|
*/ |
44
|
|
|
public function buildEditForm(FormMapper $formMapper, BlockInterface $block): void |
45
|
|
|
{ |
46
|
|
|
$formMapper->add('settings', ImmutableArrayType::class, [ |
47
|
|
|
'keys' => [ |
48
|
|
|
['url', TextType::class, [ |
49
|
|
|
'label' => 'form.label_url', |
50
|
|
|
'required' => false, |
51
|
|
|
]], |
52
|
|
|
['class', TextType::class, [ |
53
|
|
|
'label' => 'form.label_class', |
54
|
|
|
'required' => false, |
55
|
|
|
]], |
56
|
|
|
['services', ChoiceType::class, [ |
57
|
|
|
'label' => 'form.label_services', |
58
|
|
|
'choices' => [ |
59
|
|
|
'form.choice_twitter' => 'twitter', |
60
|
|
|
'form.choice_facebook' => 'facebook', |
61
|
|
|
'form.choice_googleplus' => 'googleplus', |
62
|
|
|
'form.choice_addthis' => 'addthis', |
63
|
|
|
'form.choice_linkedin' => 'linkedin', |
64
|
|
|
'form.choice_reddit' => 'reddit', |
65
|
|
|
'form.choice_stumbleupon' => 'stumbleupon', |
66
|
|
|
'form.choice_flattr' => 'flattr', |
67
|
|
|
'form.choice_pinterest' => 'pinterest', |
68
|
|
|
'form.choice_xing' => 'xing', |
69
|
|
|
'form.choice_mail' => 'mail', |
70
|
|
|
], |
71
|
|
|
'required' => false, |
72
|
|
|
'multiple' => true, |
73
|
|
|
]], |
74
|
|
|
['theme', ChoiceType::class, [ |
75
|
|
|
'label' => 'form.label_theme', |
76
|
|
|
'choices' => [ |
77
|
|
|
'standard' => 'standard', |
78
|
|
|
'grey' => 'grey', |
79
|
|
|
'white' => 'white', |
80
|
|
|
], |
81
|
|
|
'choice_translation_domain' => false, |
82
|
|
|
]], |
83
|
|
|
['orientation', ChoiceType::class, [ |
84
|
|
|
'label' => 'form.label_orientation', |
85
|
|
|
'choices' => [ |
86
|
|
|
'form.choice_vertical' => 'vertical', |
87
|
|
|
'form.choice_horizontal' => 'horizontal', |
88
|
|
|
], |
89
|
|
|
]], |
90
|
|
|
['flattrUser', TextType::class, [ |
91
|
|
|
'label' => 'form.label_flattr_user', |
92
|
|
|
'required' => false, |
93
|
|
|
]], |
94
|
|
|
['flattrCategory', TextType::class, [ |
95
|
|
|
'label' => 'form.label_flattr_category', |
96
|
|
|
'required' => false, |
97
|
|
|
]], |
98
|
|
|
], |
99
|
|
|
'translation_domain' => 'Core23ShariffBundle', |
100
|
|
|
]); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* {@inheritdoc} |
105
|
|
|
*/ |
106
|
|
|
public function configureSettings(OptionsResolver $resolver): void |
107
|
|
|
{ |
108
|
|
|
$resolver->setDefaults([ |
109
|
|
|
'url' => null, |
110
|
|
|
'class' => null, |
111
|
|
|
'services' => ['twitter', 'facebook', 'googleplus'], |
112
|
|
|
'theme' => 'standard', |
113
|
|
|
'orientation' => 'horizontal', |
114
|
|
|
'flattrUser' => null, |
115
|
|
|
'flattrCategory' => null, |
116
|
|
|
'template' => '@Core23Shariff/Block/block_shariff.html.twig', |
117
|
|
|
]); |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* {@inheritdoc} |
122
|
|
|
*/ |
123
|
|
|
public function getBlockMetadata($code = null) |
124
|
|
|
{ |
125
|
|
|
return new Metadata($this->getName(), $code ?? $this->getName(), false, 'Core23ShariffBundle', [ |
126
|
|
|
'class' => 'fa fa-share-square-o', |
127
|
|
|
]); |
128
|
|
|
} |
129
|
|
|
} |
130
|
|
|
|