![]() Server : Apache System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64 User : corals ( 1002) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /home/corals/old/app/code/Soon/Faq/Block/Adminhtml/Question/Edit/Select/ |
<?php /** * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) * @author Hervé Guétin <[email protected]> <@herveguetin> * @copyright Copyright (c) 2016 Agence Soon (http://www.agence-soon.fr) */ namespace Soon\Faq\Block\Adminhtml\Question\Edit\Select; use Magento\Framework\Option\ArrayInterface; use Magento\Store\Model\StoreManagerInterface; use Soon\Faq\Model\Category as FaqCategory; use Soon\Faq\Helper\Data as FaqHelper; use Soon\Faq\Model\ResourceModel\Category\Collection; use Soon\Faq\Model\ResourceModel\Category\CollectionFactory; /** * Class Category * @package Soon\Faq\Block\Adminhtml\Question\Edit\Select */ class Category implements ArrayInterface { /** * @var CollectionFactory */ private $collectionFactory; /** * @var \Magento\Store\Model\StoreManagerInterface */ protected $storeManager; /** * @var FaqHelper */ protected $faqHelper; /** * Category constructor. * @param CollectionFactory $collectionFactory * @param StoreManagerInterface $storeManager * @param FaqHelper $helper */ public function __construct( CollectionFactory $collectionFactory, StoreManagerInterface $storeManager, FaqHelper $helper ) { $this->collectionFactory = $collectionFactory; $this->storeManager = $storeManager; $this->faqHelper = $helper; } /** * Return array of options as value-label pairs * * @return array Format: array(array('value' => '<value>', 'label' => '<label>'), ...) */ public function toOptionArray() { /** @var Collection $categoryCollection */ $categoryCollection = $this->collectionFactory->create(); $options = array_map(function ($category) { /** @var \Soon\Faq\Model\Category $category */ $stores = $category->getStoreIds(); $prefix = []; foreach ($stores as $storeId) { $prefix[] = $this->faqHelper->getStoreCodePrefix($storeId); } $prefix = array_filter($prefix); $categoryLabel = (count($prefix) ? sprintf($this->faqHelper->getFormat(), join(' / ', $prefix), $category->getData('name')) : $category->getData('name') ); /** @var FaqCategory $category */ return ['value' => $category->getId(), 'label' => $categoryLabel]; }, $categoryCollection->getItems()); return $options; } }