|
13 | 13 |
|
14 | 14 | namespace Sulu\Bundle\HeadlessBundle\Content; |
15 | 15 |
|
| 16 | +use Sulu\Bundle\AdminBundle\Metadata\FormMetadata\FieldMetadata; |
16 | 17 | use Sulu\Bundle\AdminBundle\Metadata\FormMetadata\FormMetadata; |
17 | 18 | use Sulu\Bundle\AdminBundle\Metadata\FormMetadata\TypedFormMetadata; |
18 | 19 | use Sulu\Bundle\AdminBundle\Metadata\MetadataProviderInterface; |
19 | 20 | use Sulu\Bundle\HeadlessBundle\Content\ExtensionResolver\ExtensionResolverProvider; |
20 | 21 | use Sulu\Bundle\HttpCacheBundle\ReferenceStore\ReferenceStoreInterface; |
21 | 22 | use Sulu\Component\Persistence\Model\AuditableInterface; |
| 23 | +use Sulu\Content\Application\ContentDataMapper\DataMapper\TemplateDataMapper; |
22 | 24 | use Sulu\Content\Domain\Model\AuthorInterface; |
23 | 25 | use Sulu\Content\Domain\Model\DimensionContentInterface; |
24 | 26 | use Sulu\Content\Domain\Model\ExcerptInterface; |
25 | 27 | use Sulu\Content\Domain\Model\LinkInterface; |
| 28 | +use Sulu\Content\Domain\Model\RoutableInterface; |
26 | 29 | use Sulu\Content\Domain\Model\SeoInterface; |
27 | 30 | use Sulu\Content\Domain\Model\ShadowInterface; |
28 | 31 | use Sulu\Content\Domain\Model\TaxonomyInterface; |
@@ -149,6 +152,7 @@ private function resolveTemplateContent( |
149 | 152 |
|
150 | 153 | $fieldMetadataList = $formMetadata->getFlatFieldMetadata(); |
151 | 154 | $templateData = $dimensionContent->getTemplateData(); |
| 155 | + $templateData = $this->fillRouteFieldsFromRoute($dimensionContent, $templateData, $fieldMetadataList); |
152 | 156 |
|
153 | 157 | if (null !== $properties) { |
154 | 158 | $filteredFieldMetadata = []; |
@@ -216,6 +220,57 @@ private function resolveExtensionProperties( |
216 | 220 | } |
217 | 221 | } |
218 | 222 |
|
| 223 | + /** |
| 224 | + * @param array<string, mixed> $templateData |
| 225 | + * @param array<string, FieldMetadata> $fieldMetadataList |
| 226 | + * |
| 227 | + * @return array<string, mixed> |
| 228 | + */ |
| 229 | + private function fillRouteFieldsFromRoute( |
| 230 | + TemplateInterface $dimensionContent, |
| 231 | + array $templateData, |
| 232 | + array $fieldMetadataList, |
| 233 | + ): array { |
| 234 | + if (!$dimensionContent instanceof RoutableInterface) { |
| 235 | + return $templateData; |
| 236 | + } |
| 237 | + |
| 238 | + $route = $dimensionContent->getRoute(); |
| 239 | + if (null === $route) { |
| 240 | + return $templateData; |
| 241 | + } |
| 242 | + |
| 243 | + foreach ($fieldMetadataList as $name => $field) { |
| 244 | + if (!$field->hasTag(TemplateDataMapper::SKIP_TAG)) { |
| 245 | + continue; |
| 246 | + } |
| 247 | + |
| 248 | + $type = $field->getType(); |
| 249 | + if ('route' === $type) { |
| 250 | + $templateData[$name] = $route->getSlug(); |
| 251 | + } elseif ('page_tree_route' === $type) { |
| 252 | + $parentRoute = $route->getParentRoute(); |
| 253 | + if (null === $parentRoute) { |
| 254 | + continue; |
| 255 | + } |
| 256 | + $parentSlug = $parentRoute->getSlug(); |
| 257 | + $slug = $route->getSlug(); |
| 258 | + $suffix = \str_starts_with($slug, $parentSlug) |
| 259 | + ? \substr($slug, \strlen($parentSlug)) |
| 260 | + : ''; |
| 261 | + $templateData[$name] = [ |
| 262 | + 'page' => [ |
| 263 | + 'uuid' => $parentRoute->getResourceId(), |
| 264 | + 'path' => $parentSlug, |
| 265 | + ], |
| 266 | + 'suffix' => $suffix, |
| 267 | + ]; |
| 268 | + } |
| 269 | + } |
| 270 | + |
| 271 | + return $templateData; |
| 272 | + } |
| 273 | + |
219 | 274 | /** |
220 | 275 | * @return array<string, mixed> |
221 | 276 | */ |
|
0 commit comments