![]() 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/Ecombricks/InventoryBackend/Block/Source/ |
<?php /** * Copyright © eComBricks. All rights reserved. * See LICENSE.txt for license details. */ namespace Ecombricks\InventoryBackend\Block\Source; /** * Source switcher block */ class Switcher extends \Magento\Backend\Block\Template { use \Ecombricks\Inventory\Framework\SourceTrait; /** * Template * * @var string */ protected $_template = 'Ecombricks_InventoryBackend::source/switcher.phtml'; /** * Source management * * @var \Ecombricks\Inventory\Model\SourceManagement */ protected $sourceManagement; /** * Constructor * * @param \Magento\Backend\Block\Template\Context $context * @param \Ecombricks\Inventory\Model\SourceManagement $sourceManagement * @param array $data * @return void */ public function __construct( \Magento\Backend\Block\Template\Context $context, \Ecombricks\Inventory\Model\SourceManagement $sourceManagement, array $data = [] ) { parent::__construct($context, $data); $this->sourceManagement = $sourceManagement; } /** * Initialize * * @return void */ protected function _construct() { parent::_construct(); $this->setUseConfirm(true); $this->setUseAjax(true); $this->setDefaultOptionLabel(__('All Sources')); } /** * Get sources * * @return \Magento\InventoryApi\Api\Data\SourceInterface[] */ public function getSources() { return $this->sourceManagement->getAllSources(); } /** * Get source * * @return \Magento\InventoryApi\Api\Data\SourceInterface */ public function getSource() { return $this->sourceManagement->getSource($this->getSourceCode()); } /** * Check if default option is available * * @return bool */ public function isDefaultOptionAvailable() { return true; } /** * Get current option label * * @return string */ public function getCurrentOptionLabel() { $label = $this->getDefaultOptionLabel(); if ($this->getSourceCode()) { $source = $this->getSource(); if ($source) { $label = $source->getName(); } } return $label; } /** * Get switch URL * * @return string */ public function getSwitchUrl() { $switchUrl = $this->getData('switch_url'); if ($switchUrl) { return $switchUrl; } return $this->getUrl('*/*/*', ['_current' => true, '_exclude_source' => true ]); } }