![]() 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/vendor/magento/module-store/Ui/Component/Listing/Column/Store/ |
<?php /** * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ declare(strict_types=1); namespace Magento\Store\Ui\Component\Listing\Column\Store; use Magento\Framework\Escaper; use Magento\Framework\Data\OptionSourceInterface; use Magento\Store\Model\System\Store as SystemStore; /** * Ui stores options * * @api */ class Options implements OptionSourceInterface { /** * @var Escaper */ protected $escaper; /** * @var SystemStore */ protected $systemStore; /** * @var array */ protected $options; /** * @var array */ protected $currentOptions = []; /** * Constructor * * @param SystemStore $systemStore * @param Escaper $escaper */ public function __construct(SystemStore $systemStore, Escaper $escaper) { $this->systemStore = $systemStore; $this->escaper = $escaper; } /** * Get options * * @return array */ public function toOptionArray() { if ($this->options !== null) { return $this->options; } $this->generateCurrentOptions(); $this->options = array_values($this->currentOptions); return $this->options; } /** * Sanitize website/store option name * * @param string $name * * @return string */ protected function sanitizeName($name) { $matches = []; preg_match('/\$[:]*{(.)*}/', $name ?: '', $matches); if (count($matches) > 0) { $name = $this->escaper->escapeHtml($this->escaper->escapeJs($name)); } else { $name = $this->escaper->escapeHtml($name); } return $name; } /** * Generate current options * * @return void */ protected function generateCurrentOptions(): void { $websiteCollection = $this->systemStore->getWebsiteCollection(); $groupCollection = $this->systemStore->getGroupCollection(); $storeCollection = $this->systemStore->getStoreCollection(); foreach ($websiteCollection as $website) { $groups = []; foreach ($groupCollection as $group) { if ($group->getWebsiteId() === $website->getId()) { $stores = []; foreach ($storeCollection as $store) { if ($store->getGroupId() === $group->getId()) { $stores[] = [ 'label' => str_repeat(' ', 8) . $this->sanitizeName($store->getName()), 'value' => $store->getId(), ]; } } if (!empty($stores)) { $groups[] = [ 'label' => str_repeat(' ', 4) . $this->sanitizeName($group->getName()), 'value' => array_values($stores), ]; } } } if (!empty($groups)) { $this->currentOptions[] = [ 'label' => $this->sanitizeName($website->getName()), 'value' => array_values($groups), ]; } } } }