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\NewsBundle\Block; |
15
|
|
|
|
16
|
|
|
use Sonata\AdminBundle\Admin\Pool; |
17
|
|
|
use Sonata\AdminBundle\Form\FormMapper; |
18
|
|
|
use Sonata\BlockBundle\Block\BlockContextInterface; |
19
|
|
|
use Sonata\BlockBundle\Block\Service\AbstractAdminBlockService; |
20
|
|
|
use Sonata\BlockBundle\Meta\Metadata; |
21
|
|
|
use Sonata\BlockBundle\Model\BlockInterface; |
22
|
|
|
use Sonata\Doctrine\Model\ManagerInterface; |
23
|
|
|
use Sonata\Form\Type\ImmutableArrayType; |
24
|
|
|
use Sonata\NewsBundle\Model\CommentManagerInterface; |
25
|
|
|
use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface; |
26
|
|
|
use Symfony\Component\Form\Extension\Core\Type\ChoiceType; |
27
|
|
|
use Symfony\Component\Form\Extension\Core\Type\IntegerType; |
28
|
|
|
use Symfony\Component\Form\Extension\Core\Type\TextType; |
29
|
|
|
use Symfony\Component\HttpFoundation\Response; |
30
|
|
|
use Symfony\Component\OptionsResolver\OptionsResolver; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @author Thomas Rabaix <[email protected]> |
34
|
|
|
*/ |
35
|
|
|
class RecentCommentsBlockService extends AbstractAdminBlockService |
|
|
|
|
36
|
|
|
{ |
37
|
|
|
/** |
38
|
|
|
* @var CommentManagerInterface |
39
|
|
|
*/ |
40
|
|
|
protected $manager; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @var Pool |
44
|
|
|
*/ |
45
|
|
|
protected $adminPool; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @param string $name |
49
|
|
|
* @param Pool $adminPool |
50
|
|
|
*/ |
51
|
|
|
public function __construct($name, EngineInterface $templating, ManagerInterface $commentManager, ?Pool $adminPool = null) |
52
|
|
|
{ |
53
|
|
|
if (!$commentManager instanceof CommentManagerInterface) { |
54
|
|
|
@trigger_error( |
|
|
|
|
55
|
|
|
'Calling the '.__METHOD__.' method with a Sonata\Doctrine\Model\ManagerInterface is deprecated' |
56
|
|
|
.' since version 2.4 and will be removed in 3.0.' |
57
|
|
|
.' Use the new signature with a Sonata\NewsBundle\Model\CommentManagerInterface instead.', |
58
|
|
|
E_USER_DEPRECATED |
59
|
|
|
); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
$this->manager = $commentManager; |
|
|
|
|
63
|
|
|
$this->adminPool = $adminPool; |
64
|
|
|
|
65
|
|
|
parent::__construct($name, $templating); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
public function execute(BlockContextInterface $blockContext, ?Response $response = null) |
69
|
|
|
{ |
70
|
|
|
$criteria = [ |
71
|
|
|
'mode' => $blockContext->getSetting('mode'), |
72
|
|
|
]; |
73
|
|
|
|
74
|
|
|
$parameters = [ |
75
|
|
|
'context' => $blockContext, |
76
|
|
|
'settings' => $blockContext->getSettings(), |
77
|
|
|
'block' => $blockContext->getBlock(), |
78
|
|
|
'pager' => $this->manager->getPager($criteria, 1, $blockContext->getSetting('number')), |
79
|
|
|
'admin_pool' => $this->adminPool, |
80
|
|
|
]; |
81
|
|
|
|
82
|
|
|
if ('admin' === $blockContext->getSetting('mode')) { |
83
|
|
|
return $this->renderPrivateResponse($blockContext->getTemplate(), $parameters, $response); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
return $this->renderResponse($blockContext->getTemplate(), $parameters, $response); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
public function buildEditForm(FormMapper $formMapper, BlockInterface $block): void |
90
|
|
|
{ |
91
|
|
|
$formMapper->add('settings', ImmutableArrayType::class, [ |
92
|
|
|
'keys' => [ |
93
|
|
|
['number', IntegerType::class, [ |
94
|
|
|
'required' => true, |
95
|
|
|
'label' => 'form.label_number', |
96
|
|
|
]], |
97
|
|
|
['title', TextType::class, [ |
98
|
|
|
'label' => 'form.label_title', |
99
|
|
|
'required' => false, |
100
|
|
|
]], |
101
|
|
|
['translation_domain', TextType::class, [ |
102
|
|
|
'label' => 'form.label_translation_domain', |
103
|
|
|
'required' => false, |
104
|
|
|
]], |
105
|
|
|
['icon', TextType::class, [ |
106
|
|
|
'label' => 'form.label_icon', |
107
|
|
|
'required' => false, |
108
|
|
|
]], |
109
|
|
|
['class', TextType::class, [ |
110
|
|
|
'label' => 'form.label_class', |
111
|
|
|
'required' => false, |
112
|
|
|
]], |
113
|
|
|
['mode', ChoiceType::class, [ |
114
|
|
|
'choices' => [ |
115
|
|
|
'form.label_mode_public' => 'public', |
116
|
|
|
'form.label_mode_admin' => 'admin', |
117
|
|
|
], |
118
|
|
|
'label' => 'form.label_mode', |
119
|
|
|
]], |
120
|
|
|
], |
121
|
|
|
'translation_domain' => 'SonataNewsBundle', |
122
|
|
|
]); |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
public function configureSettings(OptionsResolver $resolver): void |
126
|
|
|
{ |
127
|
|
|
$resolver->setDefaults([ |
128
|
|
|
'number' => 5, |
129
|
|
|
'mode' => 'public', |
130
|
|
|
'title' => null, |
131
|
|
|
'translation_domain' => null, |
132
|
|
|
'icon' => 'fa fa-comments', |
133
|
|
|
'class' => null, |
134
|
|
|
'template' => '@SonataNews/Block/recent_comments.html.twig', |
135
|
|
|
]); |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
public function getBlockMetadata($code = null) |
139
|
|
|
{ |
140
|
|
|
return new Metadata($this->getName(), (null !== $code ? $code : $this->getName()), false, 'SonataNewsBundle', [ |
141
|
|
|
'class' => 'fa fa-comments-o', |
142
|
|
|
]); |
143
|
|
|
} |
144
|
|
|
} |
145
|
|
|
|
This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.