/** * Create url for passed item using passed url model * * @param \Magento\Framework\Object $item * @return string */ public function getUrl($item) { if (!empty($this->_path)) { $params = $this->_prepareParameters($item); return $this->_urlModel->getUrl($this->_path, $params); } return ''; }
public function getElementHtml() { $buttonBlock = $this->getForm()->getParent()->getLayout()->createBlock('Magento\\Backend\\Block\\Widget\\Button'); $params = ['website' => $buttonBlock->getRequest()->getParam('website')]; $url = $this->_backendUrl->getUrl("*/*/exportmatrixrate", $params); $data = ['label' => __('Export CSV'), 'onclick' => "setLocation('" . $url . "conditionName/' + \$('carriers_matrixrate_condition_name').value + '/matrixrate.csv' )", 'class' => '']; $html = $buttonBlock->setData($data)->toHtml(); return $html; }
/** * Force admin to change password * * @param EventObserver $observer * @return void */ public function execute(EventObserver $observer) { if (!$this->observerConfig->isPasswordChangeForced()) { return; } if (!$this->authSession->isLoggedIn()) { return; } $actionList = ['adminhtml_system_account_index', 'adminhtml_system_account_save', 'adminhtml_auth_logout']; /** @var \Magento\Framework\App\Action\Action $controller */ $controller = $observer->getEvent()->getControllerAction(); /** @var \Magento\Framework\App\RequestInterface $request */ $request = $observer->getEvent()->getRequest(); if ($this->authSession->getPciAdminUserIsPasswordExpired()) { if (!in_array($request->getFullActionName(), $actionList)) { if ($this->authorization->isAllowed('Magento_Backend::myaccount')) { $controller->getResponse()->setRedirect($this->url->getUrl('adminhtml/system_account/')); $this->actionFlag->set('', \Magento\Framework\App\Action\Action::FLAG_NO_DISPATCH, true); $this->actionFlag->set('', \Magento\Framework\App\Action\Action::FLAG_NO_POST_DISPATCH, true); } else { /* * if admin password is expired and access to 'My Account' page is denied * than we need to do force logout with error message */ $this->authSession->clearStorage(); $this->session->clearStorage(); $this->messageManager->addErrorMessage(__('Your password has expired; please contact your administrator.')); $controller->getRequest()->setDispatched(false); } } } }
/** * Update all attribute-dependant index * * @param \Magento\Framework\Event\Observer $observer * @return \Magento\CatalogSearch\Model\Fulltext\Observer */ public function eavAttributeChange(\Magento\Framework\Event\Observer $observer) { $attribute = $observer->getEvent()->getAttribute(); /* @var $attribute \Magento\Eav\Model\Entity\Attribute */ $entityType = $this->_eavConfig->getEntityType(\Magento\Catalog\Model\Product::ENTITY); /* @var $entityType \Magento\Eav\Model\Entity\Type */ if ($attribute->getEntityTypeId() != $entityType->getId()) { return $this; } $delete = $observer->getEventName() == 'eav_entity_attribute_delete_after'; if (!$delete && !$attribute->dataHasChangedFor('is_searchable')) { return $this; } $showNotice = false; if ($delete) { if ($attribute->getIsSearchable()) { $showNotice = true; } } elseif ($attribute->dataHasChangedFor('is_searchable')) { $showNotice = true; } if ($showNotice) { $url = $this->_backendUrl->getUrl('adminhtml/system_cache'); $this->messageManager->addNotice(__('Attribute setting change related with Search Index. Please run <a href="%1">Rebuild Search Index</a> process.', $url)); } return $this; }
/** * Return Widgets Insertion Plugin Window URL * * @param \Magento\Framework\DataObject $config Editor element config * @return string */ public function getWidgetWindowUrl($config) { $params = []; $skipped = is_array($config->getData('skip_widgets')) ? $config->getData('skip_widgets') : []; if ($config->hasData('widget_filters')) { $all = $this->_widgetFactory->create()->getWidgets(); $filtered = $this->_widgetFactory->create()->getWidgets($config->getData('widget_filters')); foreach ($all as $code => $widget) { if (!isset($filtered[$code])) { $skipped[] = $widget['@']['type']; } } } if (count($skipped) > 0) { $params['skip_widgets'] = $this->encodeWidgetsToQuery($skipped); } return $this->_backendUrl->getUrl('adminhtml/widget/index', $params); }
/** * Check to see if there are any native tax rules created that may affect AvaTax * * @return array */ public function checkNativeTaxRules() { $errors = []; if ($this->avaTaxConfig->isModuleEnabled() && $this->avaTaxConfig->getTaxMode($this->storeManager->getDefaultStoreView()) != Config::TAX_MODE_NO_ESTIMATE_OR_SUBMIT && !$this->avaTaxConfig->isNativeTaxRulesIgnored()) { $taxRules = $this->taxRuleRepository->getList($this->searchCriteriaBuilder->create()); if (count($taxRules->getItems())) { $errors[] = __('You have %1 native Magento Tax Rule(s) configured. ' . 'Please <a href="%2">review the tax rule(s)</a> and delete any that you do not specifically want enabled. ' . 'You should only have rules setup if you want to use them as backup rules in case of AvaTax ' . 'errors (see <a href="#row_tax_avatax_error_handling_header">Error Action setting</a>) ' . 'or if you need to support VAT tax. ' . '<a href="%3">Ignore this notification</a>.', count($taxRules->getItems()), $this->backendUrl->getUrl('tax/rule'), $this->backendUrl->getUrl('avatax/tax/ignoreTaxRuleNotification')); } } return $errors; }
/** * Retrieve the category product sorter load URL. * * @param Category $category Category. * * @return string */ private function getProductSorterLoadUrl(Category $category) { $storeId = $category->getStoreId(); if ($storeId === 0) { $defaultStoreId = $this->storeManager->getDefaultStoreView()->getId(); $storeId = current(array_filter($category->getStoreIds())); if (in_array($defaultStoreId, $category->getStoreIds())) { $storeId = $defaultStoreId; } } $urlParams = ['ajax' => true, 'store' => $storeId]; return $this->urlBuilder->getUrl('virtualcategory/category_virtual/preview', $urlParams); }
/** * Checks, whether Magento requires redirection after successful admin login, and redirects user, if needed * * @param \Magento\Framework\App\RequestInterface $request * @return bool */ protected function _redirectIfNeededAfterLogin(\Magento\Framework\App\RequestInterface $request) { $requestUri = null; // Checks, whether secret key is required for admin access or request uri is explicitly set if ($this->_url->useSecretKey()) { $requestUri = $this->_url->getUrl('*/*/*', ['_current' => true]); } elseif ($request) { $requestUri = $request->getRequestUri(); } if (!$requestUri) { return false; } $this->_response->setRedirect($requestUri); $this->_actionFlag->set('', \Magento\Framework\App\ActionInterface::FLAG_NO_DISPATCH, true); return true; }
/** * Check whether the latest password is expired * Side-effect can be when passwords were changed with different lifetime configuration settings * * @param array $latestPassword * @return void */ private function _checkExpiredPassword($latestPassword) { if ($latestPassword && $this->observerConfig->_isLatestPasswordExpired($latestPassword)) { if ($this->observerConfig->isPasswordChangeForced()) { $message = __('It\'s time to change your password.'); } else { $myAccountUrl = $this->url->getUrl('adminhtml/system_account/'); $message = __('It\'s time to <a href="%1">change your password</a>.', $myAccountUrl); } $this->messageManager->addNoticeMessage($message); $message = $this->messageManager->getMessages()->getLastAddedMessage(); if ($message) { $message->setIdentifier('magento_user_password_expired')->setIsSticky(true); $this->authSession->setPciAdminUserIsPasswordExpired(true); } } }
/** * Iterate over all config tabs, extract sections and its subsections * @param string $itemsSeparator * @param string $itemPrefix * @return array */ public function getConfigSectionsArray($itemsSeparator = ' ', $itemPrefix = '') { $sections = array(); foreach ($this->_configStructure->getTabs() as $tab) { /** @var $tab \Magento\Config\Model\Config\Structure\Element\Tab */ foreach ($tab->getChildren() as $section) { /** @var $section \Magento\Config\Model\Config\Structure\Element\Section */ // We need the label & url again for the sub sections $sectionLabel = $itemPrefix . $tab->getLabel() . $itemsSeparator . $section->getLabel(); $sectionUrl = $this->_url->getUrl('adminhtml/system_config/edit', array('section' => $section->getId())); // First add global section to the launcher items... $sections[] = ['label' => $sectionLabel, 'value' => $sectionUrl]; foreach ($section->getChildren() as $subSection) { /** @var $subSection \Magento\Config\Model\Config\Structure\Element\Section */ // ...then add all sub sections $sections[] = ['label' => $sectionLabel . $itemsSeparator . $subSection->getLabel(), 'value' => $sectionUrl . '#' . $section->getId() . '_' . $subSection->getId() . '-link']; } } } return $sections; }
/** * Return Wysiwyg config as \Magento\Framework\DataObject * * Config options description: * * enabled: Enabled Visual Editor or not * hidden: Show Visual Editor on page load or not * use_container: Wrap Editor contents into div or not * no_display: Hide Editor container or not (related to use_container) * translator: Helper to translate phrases in lib * files_browser_*: Files Browser (media, images) settings * encode_directives: Encode template directives with JS or not * * @param array|\Magento\Framework\DataObject $data Object constructor params to override default config values * @return \Magento\Framework\DataObject */ public function getConfig($data = []) { $config = new \Magento\Framework\DataObject(); $config->setData(['enabled' => $this->isEnabled(), 'hidden' => $this->isHidden(), 'use_container' => false, 'add_variables' => true, 'add_widgets' => true, 'no_display' => false, 'encode_directives' => true, 'baseStaticUrl' => $this->_assetRepo->getStaticViewFileContext()->getBaseUrl(), 'baseStaticDefaultUrl' => str_replace('index.php/', '', $this->_backendUrl->getBaseUrl()) . $this->filesystem->getUri(DirectoryList::STATIC_VIEW) . '/', 'directives_url' => $this->_backendUrl->getUrl('cms/wysiwyg/directive'), 'popup_css' => $this->_assetRepo->getUrl('mage/adminhtml/wysiwyg/tiny_mce/themes/advanced/skins/default/dialog.css'), 'content_css' => $this->_assetRepo->getUrl('mage/adminhtml/wysiwyg/tiny_mce/themes/advanced/skins/default/content.css'), 'width' => '100%', 'height' => '500px', 'plugins' => []]); $config->setData('directives_url_quoted', preg_quote($config->getData('directives_url'))); if ($this->_authorization->isAllowed('Magento_Cms::media_gallery')) { $config->addData(['add_images' => true, 'files_browser_window_url' => $this->_backendUrl->getUrl('cms/wysiwyg_images/index'), 'files_browser_window_width' => $this->_windowSize['width'], 'files_browser_window_height' => $this->_windowSize['height']]); } if (is_array($data)) { $config->addData($data); } if ($config->getData('add_variables')) { $settings = $this->_variableConfig->getWysiwygPluginSettings($config); $config->addData($settings); } if ($config->getData('add_widgets')) { $settings = $this->_widgetConfig->getPluginSettings($config); $config->addData($settings); } return $config; }
/** * Return files * * @param string $path Parent directory path * @param string $type Type of storage, e.g. image, media etc. * @return \Magento\Framework\Data\Collection\Filesystem */ public function getFilesCollection($path, $type = null) { if ($this->_coreFileStorageDb->checkDbUsage()) { $files = $this->_storageDatabaseFactory->create()->getDirectoryFiles($path); /** @var \Magento\MediaStorage\Model\File\Storage\File $fileStorageModel */ $fileStorageModel = $this->_storageFileFactory->create(); foreach ($files as $file) { $fileStorageModel->saveFile($file); } } $collection = $this->getCollection($path)->setCollectDirs(false)->setCollectFiles(true)->setCollectRecursively(false)->setOrder('mtime', \Magento\Framework\Data\Collection::SORT_ORDER_ASC); // Add files extension filter if ($allowed = $this->getAllowedExtensions($type)) { $collection->setFilesFilter('/\\.(' . implode('|', $allowed) . ')$/i'); } // prepare items foreach ($collection as $item) { $item->setId($this->_cmsWysiwygImages->idEncode($item->getBasename())); $item->setName($item->getBasename()); $item->setShortName($this->_cmsWysiwygImages->getShortFilename($item->getBasename())); $item->setUrl($this->_cmsWysiwygImages->getCurrentUrl() . $item->getBasename()); if ($this->isImage($item->getBasename())) { $thumbUrl = $this->getThumbnailUrl($item->getFilename(), true); // generate thumbnail "on the fly" if it does not exists if (!$thumbUrl) { $thumbUrl = $this->_backendUrl->getUrl('cms/*/thumbnail', ['file' => $item->getId()]); } $size = @getimagesize($item->getFilename()); if (is_array($size)) { $item->setWidth($size[0]); $item->setHeight($size[1]); } } else { $thumbUrl = $this->_assetRepo->getUrl(self::THUMB_PLACEHOLDER_PATH_SUFFIX); } $item->setThumbUrl($thumbUrl); } return $collection; }
/** * Get url to upload files * * @return string */ protected function _getUploadUrl() { return $this->_url->getUrl('catalog/product_gallery/upload'); }
/** * Retrieve menu item url * * @return string */ public function getUrl() { if ((bool) $this->_action) { return $this->_urlModel->getUrl((string) $this->_action, array('_cache_secret_key' => true)); } return '#'; }
/** * @param string $path * @param array $params * @return string */ protected function getUrl($path, $params) { $isBackendStore = \Magento\Store\Model\Store::DEFAULT_STORE_ID === $this->getStoreId() || \Magento\Store\Model\Store::ADMIN_CODE === $this->getStoreId(); return $isBackendStore ? $this->backendUrlBuilder->getUrl($path, $params) : $this->_storeManager->getStore($this->getStoreId())->getUrl($path, $params); }
/** * @param string $route * @param array $params * @return string */ public function getUrl($route = '', $params = []) { return $this->_backendUrl->getUrl($route, $params); }
/** * Return url of action to get variables * * @return string * @codeCoverageIgnore */ public function getVariablesWysiwygActionUrl() { return $this->_url->getUrl('adminhtml/system_variable/wysiwygPlugin'); }
/** * App isolation is enabled to protect next tests from polluted registry by getUrl() * * @magentoAppIsolation enabled */ public function testGetUrl() { $url = $this->_model->getUrl('adminhtml/auth/login'); $this->assertContains('admin/auth/login/key/', $url); }
/** * Returns URL to controller action which returns new captcha image * * @return string */ public function getRefreshUrl() { return $this->_url->getUrl('adminhtml/refresh/refresh', ['_secure' => $this->_config->isSetFlag('web/secure/use_in_adminhtml'), '_nosecret' => true]); }
/** * @param string $route * @param array $params * @return string */ public function getBackendUrl($route = '', $params = ['_current' => true]) { return $this->backendUrl->getUrl($route, $params); }
/** * Return "disable checkout" error message based on the current area context * * @param $store * @return \Magento\Framework\Phrase * @throws \Magento\Framework\Exception\LocalizedException */ public function getErrorActionDisableCheckoutMessage($store) { if ($this->appState->getAreaCode() == \Magento\Backend\App\Area\FrontNameResolver::AREA_CODE) { return __($this->getErrorActionDisableCheckoutMessageBackend($store), $this->backendUrl->getUrl('admin/system_config/edit', ['section' => 'tax']), $this->backendUrl->getUrl('avatax/log')); } else { return __($this->getErrorActionDisableCheckoutMessageFrontend($store)); } }
/** * Return Wysiwyg config as \Magento\Framework\Object * * Config options description: * * enabled: Enabled Visual Editor or not * hidden: Show Visual Editor on page load or not * use_container: Wrap Editor contents into div or not * no_display: Hide Editor container or not (related to use_container) * translator: Helper to translate phrases in lib * files_browser_*: Files Browser (media, images) settings * encode_directives: Encode template directives with JS or not * * @param array|\Magento\Framework\Object $data Object constructor params to override default config values * @return \Magento\Framework\Object */ public function getConfig($data = array()) { $config = new \Magento\Framework\Object(); $config->setData(array('enabled' => $this->isEnabled(), 'hidden' => $this->isHidden(), 'use_container' => false, 'add_variables' => true, 'add_widgets' => true, 'no_display' => false, 'encode_directives' => true, 'directives_url' => $this->_backendUrl->getUrl('cms/wysiwyg/directive'), 'popup_css' => $this->_assetRepo->getUrl('mage/adminhtml/wysiwyg/tiny_mce/themes/advanced/skins/default/dialog.css'), 'content_css' => $this->_assetRepo->getUrl('mage/adminhtml/wysiwyg/tiny_mce/themes/advanced/skins/default/content.css'), 'width' => '100%', 'plugins' => array())); $config->setData('directives_url_quoted', preg_quote($config->getData('directives_url'))); if ($this->_authorization->isAllowed('Magento_Cms::media_gallery')) { $config->addData(array('add_images' => true, 'files_browser_window_url' => $this->_backendUrl->getUrl('cms/wysiwyg_images/index'), 'files_browser_window_width' => $this->_windowSize['width'], 'files_browser_window_height' => $this->_windowSize['height'])); } if (is_array($data)) { $config->addData($data); } if ($config->getData('add_variables')) { $settings = $this->_variableConfig->getWysiwygPluginSettings($config); $config->addData($settings); } if ($config->getData('add_widgets')) { $settings = $this->_widgetConfig->getPluginSettings($config); $config->addData($settings); } return $config; }