|
4 | 4 |
|
5 | 5 | use Pimcore\Model\Document\Tag\Area\Info; |
6 | 6 | use Pimcore\Model\Document\Tag\Checkbox; |
7 | | -use Pimcore\Translation\Translator; |
8 | 7 | use Pimcore\Templating\Renderer\TagRenderer; |
| 8 | +use Pimcore\Translation\Translator; |
9 | 9 | use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface; |
| 10 | +use ToolboxBundle\Registry\StoreProviderRegistryInterface; |
10 | 11 |
|
11 | 12 | class BrickConfigBuilder |
12 | 13 | { |
@@ -66,20 +67,26 @@ class BrickConfigBuilder |
66 | 67 | protected $configWindowSize = null; |
67 | 68 |
|
68 | 69 | /** |
69 | | - * ElementBuilder constructor. |
70 | | - * |
| 70 | + * @var StoreProviderRegistryInterface |
| 71 | + */ |
| 72 | + protected $storeProvider = null; |
| 73 | + |
| 74 | + /** |
71 | 75 | * @param Translator $translator |
72 | 76 | * @param TagRenderer $tagRenderer |
73 | 77 | * @param EngineInterface $templating |
| 78 | + * @param StoreProviderRegistryInterface $storeProvider |
74 | 79 | */ |
75 | 80 | public function __construct( |
76 | 81 | Translator $translator, |
77 | 82 | TagRenderer $tagRenderer, |
78 | | - EngineInterface $templating |
| 83 | + EngineInterface $templating, |
| 84 | + StoreProviderRegistryInterface $storeProvider |
79 | 85 | ) { |
80 | 86 | $this->translator = $translator; |
81 | 87 | $this->tagRenderer = $tagRenderer; |
82 | 88 | $this->templating = $templating; |
| 89 | + $this->storeProvider = $storeProvider; |
83 | 90 | } |
84 | 91 |
|
85 | 92 | /** |
@@ -181,7 +188,53 @@ private function needStore($type) |
181 | 188 | */ |
182 | 189 | private function hasValidStore($parsedConfig) |
183 | 190 | { |
184 | | - return isset($parsedConfig['store']) && is_array($parsedConfig['store']) && count($parsedConfig['store']) > 0; |
| 191 | + if (isset($parsedConfig['store']) && is_array($parsedConfig['store']) && count($parsedConfig['store']) > 0) { |
| 192 | + return true; |
| 193 | + } |
| 194 | + |
| 195 | + if (isset($parsedConfig['store_provider']) && $this->storeProvider->has($parsedConfig['store_provider'])) { |
| 196 | + return true; |
| 197 | + } |
| 198 | + |
| 199 | + return false; |
| 200 | + } |
| 201 | + |
| 202 | + /** |
| 203 | + * @param string $type |
| 204 | + * @param array $config |
| 205 | + * |
| 206 | + * @return array |
| 207 | + * @throws \Exception |
| 208 | + */ |
| 209 | + private function buildStore($type, $config) |
| 210 | + { |
| 211 | + $dataConfig = $config; |
| 212 | + |
| 213 | + unset($dataConfig['store'], $dataConfig['store_provider']); |
| 214 | + |
| 215 | + $storeValues = []; |
| 216 | + if (isset($config['store']) && !is_null($config['store'])) { |
| 217 | + $storeValues = $config['store']; |
| 218 | + } elseif (isset($config['store_provider']) && !is_null($config['store_provider'])) { |
| 219 | + $storeProvider = $this->storeProvider->get($config['store_provider']); |
| 220 | + $storeValues = $storeProvider->getValues(); |
| 221 | + } |
| 222 | + |
| 223 | + if (count($storeValues) === 0) { |
| 224 | + throw new \Exception($type . ' (' . $this->documentEditableId . ') has no valid configured store'); |
| 225 | + } |
| 226 | + |
| 227 | + $store = []; |
| 228 | + foreach ($storeValues as $k => $v) { |
| 229 | + if (is_array($v)) { |
| 230 | + $v = $v['name']; |
| 231 | + } |
| 232 | + $store[] = [$k, $this->translator->trans($v, [], 'admin')]; |
| 233 | + } |
| 234 | + |
| 235 | + $dataConfig['store'] = $store; |
| 236 | + |
| 237 | + return $dataConfig; |
185 | 238 | } |
186 | 239 |
|
187 | 240 | /** |
@@ -293,23 +346,8 @@ private function getTagConfig($type, $config, $additionalConfig) |
293 | 346 | } |
294 | 347 |
|
295 | 348 | //check store |
296 | | - if ($this->needStore($type) && isset($parsedConfig['store']) && !is_null($parsedConfig['store'])) { |
297 | | - if (empty($parsedConfig['store'])) { |
298 | | - throw new \Exception($type . ' (' . $this->documentEditableId . ') has no valid configured store'); |
299 | | - } |
300 | | - |
301 | | - $store = []; |
302 | | - foreach ($parsedConfig['store'] as $k => $v) { |
303 | | - if (is_array($v)) { |
304 | | - $v = $v['name']; |
305 | | - } |
306 | | - |
307 | | - $store[] = [$k, $this->translator->trans($v, [], 'admin')]; |
308 | | - } |
309 | | - |
310 | | - $parsedConfig['store'] = $store; |
311 | | - } else { |
312 | | - unset($parsedConfig['store']); |
| 349 | + if ($this->needStore($type) && $this->hasValidStore($parsedConfig)) { |
| 350 | + $parsedConfig = $this->buildStore($type, $parsedConfig); |
313 | 351 | } |
314 | 352 |
|
315 | 353 | return $parsedConfig; |
|
0 commit comments