/** * 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); }
/** * Return array of available widgets based on configuration * * @param bool $withEmptyElement * @return array */ protected function _getAvailableWidgets($withEmptyElement = false) { if (!$this->hasData('available_widgets')) { $result = []; $allWidgets = $this->_widgetFactory->create()->getWidgetsArray(); $skipped = $this->_getSkippedWidgets(); foreach ($allWidgets as $widget) { if (is_array($skipped) && in_array($widget['type'], $skipped)) { continue; } $result[] = $widget; } if ($withEmptyElement) { array_unshift($result, ['type' => '', 'name' => __('-- Please Select --'), 'description' => '']); } $this->setData('available_widgets', $result); } return $this->_getData('available_widgets'); }