vendor/sulu/headless-bundle/Content/ContentTypeResolver/SinglePageSelectionResolver.php line 36

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. /*
  4.  * This file is part of Sulu.
  5.  *
  6.  * (c) Sulu GmbH
  7.  *
  8.  * This source file is subject to the MIT license that is bundled
  9.  * with this source code in the file LICENSE.
  10.  */
  11. namespace Sulu\Bundle\HeadlessBundle\Content\ContentTypeResolver;
  12. use Sulu\Bundle\HeadlessBundle\Content\ContentView;
  13. use Sulu\Component\Content\Compat\PropertyInterface;
  14. class SinglePageSelectionResolver implements ContentTypeResolverInterface
  15. {
  16.     public static function getContentType(): string
  17.     {
  18.         return 'single_page_selection';
  19.     }
  20.     /**
  21.      * @var ContentTypeResolverInterface
  22.      */
  23.     private $pageSelectionResolver;
  24.     public function __construct(ContentTypeResolverInterface $pageSelectionResolver)
  25.     {
  26.         $this->pageSelectionResolver $pageSelectionResolver;
  27.     }
  28.     public function resolve($dataPropertyInterface $propertystring $locale, array $attributes = []): ContentView
  29.     {
  30.         if (empty($data)) {
  31.             return new ContentView(null, ['id' => null]);
  32.         }
  33.         $content $this->pageSelectionResolver->resolve([$data], $property$locale$attributes);
  34.         return new ContentView($content->getContent()[0] ?? null, ['id' => $data]);
  35.     }
  36. }