vendor/shopware/core/Content/Cms/CmsPageEntity.php line 14

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Shopware\Core\Content\Cms;
  3. use Shopware\Core\Content\Category\CategoryCollection;
  4. use Shopware\Core\Content\Cms\Aggregate\CmsSection\CmsSectionCollection;
  5. use Shopware\Core\Content\Cms\Aggregate\CmsSlot\CmsSlotEntity;
  6. use Shopware\Core\Content\Media\MediaEntity;
  7. use Shopware\Core\Content\Product\ProductCollection;
  8. use Shopware\Core\Framework\DataAbstractionLayer\Entity;
  9. use Shopware\Core\Framework\DataAbstractionLayer\EntityCollection;
  10. use Shopware\Core\Framework\DataAbstractionLayer\EntityIdTrait;
  11. class CmsPageEntity extends Entity
  12. {
  13.     use EntityIdTrait;
  14.     /**
  15.      * @var string|null
  16.      */
  17.     protected $name;
  18.     /**
  19.      * @var string
  20.      */
  21.     protected $type;
  22.     /**
  23.      * @var string|null
  24.      */
  25.     protected $entity;
  26.     /**
  27.      * @var CmsSectionCollection|null
  28.      */
  29.     protected $sections;
  30.     /**
  31.      * @var EntityCollection|null
  32.      */
  33.     protected $translations;
  34.     /**
  35.      * @var CategoryCollection|null
  36.      */
  37.     protected $categories;
  38.     /**
  39.      * @internal (flag:FEATURE_NEXT_10078)
  40.      *
  41.      * @var ProductCollection|null
  42.      */
  43.     protected $products;
  44.     /**
  45.      * @var array|null
  46.      */
  47.     protected $config;
  48.     /**
  49.      * @var string|null
  50.      */
  51.     protected $previewMediaId;
  52.     /**
  53.      * @var MediaEntity|null
  54.      */
  55.     protected $previewMedia;
  56.     /**
  57.      * @var array|null
  58.      */
  59.     protected $customFields;
  60.     /**
  61.      * @var bool
  62.      */
  63.     protected $locked;
  64.     public function getName(): string
  65.     {
  66.         return $this->name;
  67.     }
  68.     public function setName(string $name): void
  69.     {
  70.         $this->name $name;
  71.     }
  72.     public function getType(): string
  73.     {
  74.         return $this->type;
  75.     }
  76.     public function setType(string $type): void
  77.     {
  78.         $this->type $type;
  79.     }
  80.     public function getEntity(): ?string
  81.     {
  82.         return $this->entity;
  83.     }
  84.     public function setEntity(?string $entity): void
  85.     {
  86.         $this->entity $entity;
  87.     }
  88.     public function getSections(): ?CmsSectionCollection
  89.     {
  90.         return $this->sections;
  91.     }
  92.     public function setSections(CmsSectionCollection $sections): void
  93.     {
  94.         $this->sections $sections;
  95.     }
  96.     public function getTranslations(): ?EntityCollection
  97.     {
  98.         return $this->translations;
  99.     }
  100.     public function setTranslations(EntityCollection $translations): void
  101.     {
  102.         $this->translations $translations;
  103.     }
  104.     public function getCustomFields(): ?array
  105.     {
  106.         return $this->customFields;
  107.     }
  108.     public function setCustomFields(?array $customFields): void
  109.     {
  110.         $this->customFields $customFields;
  111.     }
  112.     public function getCategories(): ?CategoryCollection
  113.     {
  114.         return $this->categories;
  115.     }
  116.     public function setCategories(CategoryCollection $categories): void
  117.     {
  118.         $this->categories $categories;
  119.     }
  120.     /**
  121.      *@internal (flag:FEATURE_NEXT_10078)
  122.      */
  123.     public function getProducts(): ?ProductCollection
  124.     {
  125.         return $this->products;
  126.     }
  127.     /**
  128.      *@internal (flag:FEATURE_NEXT_10078)
  129.      */
  130.     public function setProducts(ProductCollection $products): void
  131.     {
  132.         $this->products $products;
  133.     }
  134.     public function getConfig(): ?array
  135.     {
  136.         return $this->config;
  137.     }
  138.     public function setConfig(array $config): void
  139.     {
  140.         $this->config $config;
  141.     }
  142.     public function getPreviewMediaId(): ?string
  143.     {
  144.         return $this->previewMediaId;
  145.     }
  146.     public function setPreviewMediaId(string $previewMediaId): void
  147.     {
  148.         $this->previewMediaId $previewMediaId;
  149.     }
  150.     public function getPreviewMedia(): ?MediaEntity
  151.     {
  152.         return $this->previewMedia;
  153.     }
  154.     public function setPreviewMedia(MediaEntity $previewMedia): void
  155.     {
  156.         $this->previewMedia $previewMedia;
  157.     }
  158.     public function getLocked(): bool
  159.     {
  160.         return $this->locked;
  161.     }
  162.     public function setLocked(bool $locked): void
  163.     {
  164.         $this->locked $locked;
  165.     }
  166.     public function getFirstElementOfType(string $type): ?CmsSlotEntity
  167.     {
  168.         $elements $this->getElementsOfType($type);
  169.         return array_shift($elements);
  170.     }
  171.     public function getElementsOfType(string $type): array
  172.     {
  173.         $elements = [];
  174.         if (!$this->getSections()) {
  175.             return $elements;
  176.         }
  177.         foreach ($this->getSections()->getBlocks() as $block) {
  178.             if (!$block->getSlots()) {
  179.                 continue;
  180.             }
  181.             foreach ($block->getSlots() as $slot) {
  182.                 if ($slot->getType() === $type) {
  183.                     $elements[] = $slot;
  184.                 }
  185.             }
  186.         }
  187.         return $elements;
  188.     }
  189. }