/** * Render block HTML * * @return string */ protected function _toHtml() { if ($this->_moduleManager->isOutputEnabled('Magento_Checkout')) { return ''; } return parent::_toHtml(); }
/** * Remove grouped product from list of visible product types * * @param \Magento\Catalog\Model\Product\Type $subject * @param array $result * @return array * * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function afterGetOptionArray(\Magento\Catalog\Model\Product\Type $subject, array $result) { if (!$this->moduleManager->isOutputEnabled('Magento_ConfigurableProduct')) { unset($result[Configurable::TYPE_CODE]); } return $result; }
/** * Render block HTML * * @return string */ protected function _toHtml() { if (!$this->_checkoutHelper->canOnepageCheckout() || !$this->_moduleManager->isOutputEnabled('Magento_Checkout')) { return ''; } return parent::_toHtml(); }
/** * @param \Magento\Framework\Event $event * @return void */ public function observe($event) { if (!$this->moduleManager->isOutputEnabled('Magento_LayeredNavigation')) { return; } /** @var \Magento\Catalog\Block\Adminhtml\Product\Attribute\Grid $grid */ $grid = $event->getGrid(); $grid->addColumnAfter('is_filterable', array('header' => __('Use in Layered Navigation'), 'sortable' => true, 'index' => 'is_filterable', 'type' => 'options', 'options' => array('1' => __('Filterable (with results)'), '2' => __('Filterable (no results)'), '0' => __('No')), 'align' => 'center'), 'is_searchable'); }
/** * Retrieve files * * Filter out theme files that belong to inactive modules or ones explicitly configured to not produce any output * * @param ThemeInterface $theme * @param string $filePath * @return array|\Magento\Framework\View\File[] */ public function getFiles(ThemeInterface $theme, $filePath) { $result = array(); foreach ($this->subject->getFiles($theme, $filePath) as $file) { if ($this->moduleManager->isOutputEnabled($file->getModule())) { $result[] = $file; } } return $result; }
/** * @param \Magento\Catalog\Block\Adminhtml\Product\Edit\Tabs $subject * @param \Magento\Eav\Model\Resource\Entity\Attribute\Group\Collection $result * * @return \Magento\Eav\Model\Resource\Entity\Attribute\Group\Collection * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function afterGetGroupCollection(\Magento\Catalog\Block\Adminhtml\Product\Edit\Tabs $subject, $result) { if (!$this->_moduleManager->isOutputEnabled('Magento_RecurringPayment')) { foreach ($result as $key => $group) { if ($group->getAttributeGroupCode() === 'recurring-payment') { $result->removeItemByKey($key); } } } return $result; }
/** * @param \Magento\Framework\Event\Observer $observer * @return void */ public function execute(\Magento\Framework\Event\Observer $observer) { if (!$this->moduleManager->isOutputEnabled('Magento_LayeredNavigation')) { return; } /** @var \Magento\Framework\Data\Form\AbstractForm $form */ $form = $observer->getForm(); $fieldset = $form->getElement('front_fieldset'); $fieldset->addField('is_filterable', 'select', ['name' => 'is_filterable', 'label' => __("Use in Layered Navigation"), 'title' => __('Can be used only with catalog input type Dropdown, Multiple Select and Price'), 'note' => __('Can be used only with catalog input type Dropdown, Multiple Select and Price.'), 'values' => [['value' => '0', 'label' => __('No')], ['value' => '1', 'label' => __('Filterable (with results)')], ['value' => '2', 'label' => __('Filterable (no results)')]]]); $fieldset->addField('is_filterable_in_search', 'select', ['name' => 'is_filterable_in_search', 'label' => __("Use in Search Results Layered Navigation"), 'title' => __('Can be used only with catalog input type Dropdown, Multiple Select and Price'), 'note' => __('Can be used only with catalog input type Dropdown, Multiple Select and Price.'), 'values' => $this->optionList->toOptionArray()]); $fieldset->addField('position', 'text', ['name' => 'position', 'label' => __('Position'), 'title' => __('Position in Layered Navigation'), 'note' => __('Position of attribute in layered navigation block.'), 'class' => 'validate-digits']); }
/** * @param \Magento\Framework\Event\Observer $observer * @return void */ public function execute(EventObserver $observer) { if (!$this->moduleManager->isOutputEnabled('Magento_Swatches')) { return; } /** @var \Magento\Framework\DataObject $response */ $response = $observer->getEvent()->getResponse(); $types = $response->getTypes(); $types[] = ['value' => \Magento\Swatches\Model\Swatch::SWATCH_TYPE_VISUAL_ATTRIBUTE_FRONTEND_INPUT, 'label' => __('Visual Swatch'), 'hide_fields' => ['is_unique', 'is_required', 'frontend_class', '_scope', '_default_value', '_front_fieldset']]; $types[] = ['value' => \Magento\Swatches\Model\Swatch::SWATCH_TYPE_TEXTUAL_ATTRIBUTE_FRONTEND_INPUT, 'label' => __('Text Swatch'), 'hide_fields' => ['is_unique', 'is_required', 'frontend_class', '_scope', '_default_value', '_front_fieldset']]; $response->setTypes($types); }
/** * Check a configuration element visibility * * @param \Magento\Config\Model\Config\Structure\AbstractElement $element The config composite element * @param string $scope The element scope * * @return bool */ public function isVisible(\Magento\Config\Model\Config\Structure\AbstractElement $element, $scope) { if ($element->getAttribute('if_module_enabled') && !$this->moduleManager->isOutputEnabled($element->getAttribute('if_module_enabled'))) { return false; } $showInScope = [ContainerScopeInterface::SCOPE_DEFAULT => $element->getAttribute('showInDefault'), ContainerScopeInterface::SCOPE_CONTAINERS => $element->getAttribute('showInContainer'), ContainerScopeInterface::SCOPE_STORE_CONTAINERS => $element->getAttribute('showInStore')]; if ($this->storeManager->isSingleStoreMode()) { $result = !$element->getAttribute('hide_in_single_store_mode') && array_sum($showInScope); return $result; } return !empty($showInScope[$scope]); }
/** * @param \Magento\Framework\Event\Observer $observer * @return void */ public function execute(EventObserver $observer) { if (!$this->moduleManager->isOutputEnabled('Magento_Swatches')) { return; } /** @var \Magento\Framework\Data\Form $form */ $form = $observer->getForm(); $fieldset = $form->getElement('base_fieldset'); $yesnoSource = $this->yesNo->toOptionArray(); $fieldset->addField('update_product_preview_image', 'select', ['name' => 'update_product_preview_image', 'label' => __('Update Product Preview Image'), 'title' => __('Update Product Preview Image'), 'note' => __('Filtering by this attribute will update the product image on catalog page'), 'values' => $yesnoSource], 'is_filterable'); $fieldset->addField('use_product_image_for_swatch', 'select', ['name' => 'use_product_image_for_swatch', 'label' => __('Use Product Image for Swatch if Possible'), 'title' => __('Use Product Image for Swatch if Possible'), 'note' => __('Allows use fallback logic for replacing swatch image with product swatch or base image'), 'values' => $yesnoSource], 'is_filterable'); }
/** * Check whether or not the module output is enabled in Configuration * * @param string $moduleName Full module name * @return boolean * @deprecated use \Magento\Framework\Module\Manager::isOutputEnabled() */ public function isModuleOutputEnabled($moduleName = null) { if ($moduleName === null) { $moduleName = $this->_getModuleName(); } return $this->_moduleManager->isOutputEnabled($moduleName); }
/** * Convert dom node tree to array * * @param \DOMDocument $source * @return array * @throws \InvalidArgumentException */ public function convert($source) { $output = ['entities' => []]; /** @var \DOMNodeList $entities */ $entities = $source->getElementsByTagName('entity'); /** @var \DOMNode $entityConfig */ foreach ($entities as $entityConfig) { $attributes = $entityConfig->attributes; $name = $attributes->getNamedItem('name')->nodeValue; $label = $attributes->getNamedItem('label')->nodeValue; $behaviorModel = $attributes->getNamedItem('behaviorModel')->nodeValue; $model = $attributes->getNamedItem('model')->nodeValue; if (!$this->moduleManager->isOutputEnabled(Classes::getClassModuleName($model))) { continue; } $output['entities'][$name] = ['name' => $name, 'label' => $label, 'behaviorModel' => $behaviorModel, 'model' => $model, 'types' => [], 'relatedIndexers' => []]; } /** @var \DOMNodeList $entityTypes */ $entityTypes = $source->getElementsByTagName('entityType'); /** @var \DOMNode $entityTypeConfig */ foreach ($entityTypes as $entityTypeConfig) { $attributes = $entityTypeConfig->attributes; $name = $attributes->getNamedItem('name')->nodeValue; $model = $attributes->getNamedItem('model')->nodeValue; $entity = $attributes->getNamedItem('entity')->nodeValue; if (isset($output['entities'][$entity])) { $output['entities'][$entity]['types'][$name] = ['name' => $name, 'model' => $model]; } } /** @var \DOMNodeList $relatedIndexers */ $relatedIndexers = $source->getElementsByTagName('relatedIndexer'); /** @var \DOMNode $relatedIndexerConfig */ foreach ($relatedIndexers as $relatedIndexerConfig) { $attributes = $relatedIndexerConfig->attributes; $name = $attributes->getNamedItem('name')->nodeValue; $entity = $attributes->getNamedItem('entity')->nodeValue; if (isset($output['entities'][$entity])) { $output['entities'][$entity]['relatedIndexers'][$name] = ['name' => $name]; } } return $output; }
/** * Convert dom node tree to array * * @param \DOMDocument $source * @return array * @throws \InvalidArgumentException */ public function convert($source) { $output = ['entities' => [], 'fileFormats' => []]; /** @var \DOMNodeList $entities */ $entities = $source->getElementsByTagName('entity'); /** @var \DOMNode $entityConfig */ foreach ($entities as $entityConfig) { $attributes = $entityConfig->attributes; $name = $attributes->getNamedItem('name')->nodeValue; $label = $attributes->getNamedItem('label')->nodeValue; $model = $attributes->getNamedItem('model')->nodeValue; if (!$this->moduleManager->isOutputEnabled(Classes::getClassModuleName($model))) { continue; } $entityAttributeFilterType = $attributes->getNamedItem('entityAttributeFilterType')->nodeValue; $output['entities'][$name] = ['name' => $name, 'label' => $label, 'model' => $model, 'types' => [], 'entityAttributeFilterType' => $entityAttributeFilterType]; } /** @var \DOMNodeList $entityTypes */ $entityTypes = $source->getElementsByTagName('entityType'); /** @var \DOMNode $entityTypeConfig */ foreach ($entityTypes as $entityTypeConfig) { $attributes = $entityTypeConfig->attributes; $model = $attributes->getNamedItem('model')->nodeValue; $name = $attributes->getNamedItem('name')->nodeValue; $entity = $attributes->getNamedItem('entity')->nodeValue; if (isset($output['entities'][$entity])) { $output['entities'][$entity]['types'][$name] = ['name' => $name, 'model' => $model]; } } /** @var \DOMNodeList $fileFormats */ $fileFormats = $source->getElementsByTagName('fileFormat'); /** @var \DOMNode $fileFormatConfig */ foreach ($fileFormats as $fileFormatConfig) { $attributes = $fileFormatConfig->attributes; $name = $attributes->getNamedItem('name')->nodeValue; $model = $attributes->getNamedItem('model')->nodeValue; $label = $attributes->getNamedItem('label')->nodeValue; $output['fileFormats'][$name] = ['name' => $name, 'model' => $model, 'label' => $label]; } return $output; }
/** * Check whether element should be displayed * * @return bool */ public function isVisible() { if (isset($this->_data['if_module_enabled']) && !$this->moduleManager->isOutputEnabled($this->_data['if_module_enabled'])) { return false; } $showInScope = [\Magento\Store\Model\ScopeInterface::SCOPE_STORE => $this->_hasVisibilityValue('showInStore'), \Magento\Store\Model\ScopeInterface::SCOPE_WEBSITE => $this->_hasVisibilityValue('showInWebsite'), ScopeConfigInterface::SCOPE_TYPE_DEFAULT => $this->_hasVisibilityValue('showInDefault')]; if ($this->_storeManager->isSingleStoreMode()) { $result = !$this->_hasVisibilityValue('hide_in_single_store_mode') && array_sum($showInScope); return $result; } return !empty($showInScope[$this->_scope]); }
/** * Get Filtered Modules by Options selected * @param $moduleList * @param $inputEnabled * @return array */ protected function getModulesByCriteria($moduleList, $inputEnabled) { $moduleInfo = array(); $modules = array_intersect_key($this->fullModuleList->getAll(), $moduleList); foreach ($modules as $module) { $vendor = current(explode("_", $module['name'])); $title = $module['name']; $version = $module['setup_version']; $enabled = $this->moduleManager->isEnabled($title) ? 'Y' : 'N'; $outputEnabled = $this->moduleManager->isOutputEnabled($title) ? 'Y' : 'N'; if ($inputEnabled) { if ($inputEnabled == strtolower($enabled)) { $moduleInfo[] = array($vendor, $title, $version, $enabled, $outputEnabled); } } else { $moduleInfo[] = array($vendor, $title, $version, $enabled, $outputEnabled); } } return $moduleInfo; }
/** * Collects required data about the modules * * @param bool $refresh * @return array */ public function getModuleData($refresh = true) { $callback = function (Module $value) { return $value->getName(); }; $configModules = $this->getAllModules(); /** @var Module[] $dbModuleArray */ $dbModuleArray = $this->moduleCollectionFactory->create()->getItems(); $nameValues = array_map($callback, $dbModuleArray); $moduleChanges = []; foreach ($configModules as $moduleName => $module) { unset($module['sequence']); $state = $this->getState($moduleName); $active = $this->getActive($moduleName); $module['state'] = $state; $module['active'] = $active; if (!in_array($moduleName, $nameValues)) { $moduleChanges[] = $this->getNewModuleChanges($moduleName, $active, $module['setup_version'], $state); } else { $dbModule = $dbModuleArray[array_search($moduleName, $nameValues)]; $changeTest = $dbModule->getData(); $changes = array_diff($module, $changeTest); $changesCleanArray = $this->getCleanChangesArray($changes); if (count($changesCleanArray) > 0 || $this->moduleManager->isOutputEnabled($changeTest['name']) && $module['setup_version'] != null) { $data = ['entity_id' => $changeTest['entity_id'], 'name' => $changeTest['name'], 'active' => $active, 'setup_version' => $module['setup_version'], 'state' => $state]; if ($refresh) { $dbModule->setData($data); $dbModule->save(); } $moduleChanges[] = ['name' => $data['name'], 'setup_version' => $data['setup_version'], 'type' => $state]; } } } $arrayModuleNames = array_keys($configModules); $uninstalledModuleChanges = $this->setUninstalledModuleChanges($dbModuleArray, $arrayModuleNames); if (is_array($uninstalledModuleChanges)) { $moduleChanges[] = $uninstalledModuleChanges; } $finalObject = $this->getFinalCounts($moduleChanges); return $finalObject; }
/** * Check whether item is disabled. Disabled items are not shown to user * * @return bool */ public function isDisabled() { return !$this->_moduleManager->isOutputEnabled($this->_moduleName) || !$this->_isModuleDependenciesAvailable() || !$this->_isConfigDependenciesAvailable(); }
/** * Newsletter module availability * * @return bool */ public function isNewsletterEnabled() { return $this->_moduleManager->isOutputEnabled('Magento_Newsletter'); }
/** * @param bool $configValue * @param string $moduleName * @param bool $expectedResult * @dataProvider isOutputEnabledCustomConfigPathDataProvider */ public function testIsOutputEnabledCustomConfigPath($configValue, $moduleName, $expectedResult) { $this->_moduleList->expects($this->any())->method('getModule')->will($this->returnValue(array('name' => $moduleName))); $this->_outputConfig->expects($this->at(0))->method('isSetFlag')->with(self::XML_PATH_OUTPUT_ENABLED)->will($this->returnValue($configValue)); $this->assertEquals($expectedResult, $this->_model->isOutputEnabled($moduleName)); }
/** * @param bool $configValue * @param bool $expectedResult * @dataProvider isOutputEnabledCustomConfigPathDataProvider */ public function testIsOutputEnabledCustomConfigPath($configValue, $expectedResult) { $this->_moduleList->expects($this->once())->method('has')->will($this->returnValue(true)); $this->_outputConfig->expects($this->at(0))->method('isSetFlag')->with(self::XML_PATH_OUTPUT_ENABLED)->will($this->returnValue($configValue)); $this->assertEquals($expectedResult, $this->_model->isOutputEnabled('Module_Two')); }