![]() 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/extmag/shiplab/Block/Adminhtml/ShippingMethods/Rules/ |
<?php /** * Copyright © Extmag. All rights reserved. */ namespace Extmag\Shiplab\Block\Adminhtml\ShippingMethods\Rules; use Extmag\Shiplab\Model\ShippingMethods; use Extmag\Shiplab\Model\ShippingMethodsFactory; use Magento\Backend\Block\Template\Context; use Magento\Backend\Block\Widget\Form\Generic; use Magento\Backend\Block\Widget\Form\Renderer\Fieldset; use Magento\Config\Model\Config\Source\Yesno; use Magento\Framework\App\ObjectManager; use Magento\Framework\Data\Form; use Magento\Framework\Data\FormFactory; use Magento\Framework\Exception\LocalizedException; use Magento\Framework\Registry; use Extmag\Core\Helper\Registry as CoreRegistry; use Magento\Rule\Model\Condition\AbstractCondition; use Magento\SalesRule\Model\RegistryConstants; use Magento\Ui\Component\Layout\Tabs\TabInterface; class Actions extends Generic implements TabInterface { /** * @var Fieldset */ protected $_rendererFieldset; /** * @var \Magento\Rule\Block\Actions */ protected $_ruleActions; /** * @var Yesno * @deprecated 100.1.0 */ protected $_sourceYesno; /** * @var string */ protected $_nameInLayout = 'actions_apply_to'; /** * @var ShippingMethodsFactory */ private $ruleFactory; /** * @var CoreRegistry */ private $registry; /** * @param Context $context * @param Registry $registry * @param CoreRegistry $coreRegistry * @param FormFactory $formFactory * @param Yesno $sourceYesno * @param \Magento\Rule\Block\Actions $ruleActions * @param Fieldset $rendererFieldset * @param array $data * @param ShippingMethodsFactory|null $ruleFactory */ public function __construct( Context $context, Registry $registry, CoreRegistry $coreRegistry, FormFactory $formFactory, Yesno $sourceYesno, \Magento\Rule\Block\Actions $ruleActions, Fieldset $rendererFieldset, array $data = [], ShippingMethodsFactory $ruleFactory = null ) { $this->_rendererFieldset = $rendererFieldset; $this->_ruleActions = $ruleActions; $this->_sourceYesno = $sourceYesno; $this->registry = $coreRegistry; $this->ruleFactory = $ruleFactory ?: ObjectManager::getInstance() ->get(ShippingMethodsFactory::class); parent::__construct($context, $registry, $formFactory, $data); } /** * @inheritDoc */ public function getTabClass() { return null; } /** * @inheritDoc */ public function getTabUrl() { return null; } /** * @inheritDoc */ public function isAjaxLoaded() { return false; } /** * @inheritDoc */ public function getTabLabel() { return __('Actions'); } /** * @inheritDoc */ public function getTabTitle() { return __('Actions'); } /** * @inheritDoc */ public function canShowTab() { return true; } /** * @inheritDoc */ public function isHidden() { return false; } /** * Prepare form before rendering HTML * * @return $this * @throws LocalizedException */ protected function _prepareForm() { $this->setForm($this->addTabToForm($this->registry->registry(RegistryConstants::CURRENT_SALES_RULE))); return parent::_prepareForm(); } /** * Handles addition of actions tab to supplied form. * * @param ShippingMethods $model * @param string $fieldsetId * @param string $formName * @return Form * @throws LocalizedException */ protected function addTabToForm( $model, $fieldsetId = 'actions_fieldset', $formName = 'extmag_shiplab_shippingmethods_form' ) { if (!$model) { $model = $this->ruleFactory->create(); $model->load($this->getRequest()->getParam('id')); } $actionsFieldSetId = $model->getActionsFieldSetId($formName); $newChildUrl = $this->getUrl( 'sales_rule/promo_quote/newActionHtml/form/' . $actionsFieldSetId, ['form_namespace' => $formName] ); $form = $this->_formFactory->create(); $form->setHtmlIdPrefix('rule_'); $renderer = $this->getLayout()->createBlock(Fieldset::class); $renderer->setTemplate( 'Magento_CatalogRule::promo/fieldset.phtml' )->setNewChildUrl( $newChildUrl )->setFieldSetId( $actionsFieldSetId ); $fieldset = $form->addFieldset( $fieldsetId, [ 'legend' => __( 'Apply the rule only to cart items matching the following conditions ' . '(leave blank for all items).' ), ] )->setRenderer( $renderer ); $fieldset->addField( 'actions', 'text', [ 'name' => 'apply_to', 'label' => __('Apply To'), 'title' => __('Apply To'), 'required' => true, 'data-form-part' => $formName, ] )->setRule( $model )->setRenderer( $this->_ruleActions ); $form->setValues($model->getData()); $this->setActionFormName($model->getActions(), $formName); if ($model->isReadonly()) { foreach ($fieldset->getElements() as $element) { $element->setReadonly(true, true); } } return $form; } /** * Handles addition of form name to action and its actions. * * @param AbstractCondition $actions * @param string $formName * @return void */ private function setActionFormName(AbstractCondition $actions, $formName) { $actions->setFormName($formName); if ($actions->getActions() && is_array($actions->getActions())) { foreach ($actions->getActions() as $condition) { $this->setActionFormName($condition, $formName); } } } }