Skip to content
Snippets Groups Projects
Select Git revision
  • 11b2efcce9556b7999fd328fb93d2ed10d0cfb5b
  • develop default protected
  • 1.3 protected
  • 1.1
  • 1.2 protected
  • 1.0
  • 13-export-cli-command
  • 1.7.0
  • 1.6.0
  • 1.5.0
  • 1.4.3
  • 1.4.2
  • 1.4.1
  • 1.4.0
  • 1.3.7
  • 1.3.6
  • 1.3.5
  • 1.3.4
  • 1.3.3
  • 1.3.2
  • 1.3.1
  • 1.3.0
  • 1.1.4
  • 1.2.5
  • 1.2.4
  • 1.2.3
  • 1.0.6
27 results

NormalizeData.php

Blame
  • NormalizeData.php 1.21 KiB
    <?php
    declare(strict_types=1);
    
    namespace Firegento\ContentProvisioning\Model\Command;
    
    use Firegento\ContentProvisioning\Api\Data\EntryInterface;
    use Magento\Framework\Exception\NoSuchEntityException;
    use Magento\Store\Model\StoreManagerInterface;
    
    class NormalizeData
    {
        /**
         * @var StoreManagerInterface
         */
        private $storeManager;
    
        /**
         * @param StoreManagerInterface $storeManager
         */
        public function __construct(
            StoreManagerInterface $storeManager
        ) {
            $this->storeManager = $storeManager;
        }
    
        /**
         * Normalize entry data in order to pass them to
         * CMS entity model like Block or Page
         *
         * @param array $data
         * @return array
         * @throws NoSuchEntityException
         */
        public function execute(array $data): array
        {
            $storeIds = [];
            $storeCodes = $data[EntryInterface::STORES] ?? [];
            foreach ($storeCodes as $code) {
                $storeIds[] = $this->storeManager->getStore($code)->getId();
            }
            $data[EntryInterface::STORES] = $storeIds;
            $data['store_id'] = $storeIds;
    
            unset($data[EntryInterface::IS_MAINTAINED]);
            unset($data[EntryInterface::KEY]);
    
            return $data;
        }
    }