class WeMegaMenuAdminController in Drupal Mega Menu 8
Same name and namespace in other branches
- 8.x src/Controller/WeMegaMenuAdminController.php \Drupal\we_megamenu\Controller\WeMegaMenuAdminController
Controller routines for block example routes.
Hierarchy
- class \Drupal\Core\Controller\ControllerBase implements ContainerInjectionInterface uses LoggerChannelTrait, MessengerTrait, LinkGeneratorTrait, RedirectDestinationTrait, UrlGeneratorTrait, StringTranslationTrait
- class \Drupal\we_megamenu\Controller\WeMegaMenuAdminController
Expanded class hierarchy of WeMegaMenuAdminController
File
- src/
Controller/ WeMegaMenuAdminController.php, line 16
Namespace
Drupal\we_megamenu\ControllerView source
class WeMegaMenuAdminController extends ControllerBase {
/**
* The config factory.
*
* @var \Drupal\Core\Config\ConfigFactoryInterface
*/
protected $configFactory;
/**
* @param \Drupal\Core\Extension\ModuleHandlerInterface
* The module handler.
*/
protected $moduleHandler;
/**
* Constructs the WeMegaMenuAdminController.
*
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* The config factory.
*
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
* The module handler.
*/
public function __construct(ConfigFactoryInterface $config_factory, ModuleHandlerInterface $module_handler) {
$this->configFactory = $config_factory;
$this->moduleHandler = $module_handler;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container
->get('config.factory'), $container
->get('module_handler'));
}
/**
* A function build page backend.
*
* @param string $menu_name
* Public function configWeMegaMenu menu_name.
*
* @return array[markup]
* Public function configWeMegaMenu string.
*/
public function configWeMegaMenu($menu_name) {
// $tree = WeMegaMenuBuilder::getMenuTreeOrder($menu_name);
$build = [];
$build['we_megamenu'] = [
'#theme' => 'we_megamenu_backend',
'#menu_name' => $menu_name,
// '#items' => $tree,
'#blocks' => WeMegaMenuBuilder::getAllBlocks(),
'#block_theme' => $this->configFactory
->get('system.theme')
->get('default'),
];
$build['we_megamenu']['#attached']['library'][] = 'we_megamenu/form.we-mega-menu-backend';
$abs_url_save_config = Url::fromRoute('we_megamenu.admin.save', [], [
'absolute' => TRUE,
])
->toString();
$abs_url_reset_config = Url::fromRoute('we_megamenu.admin.reset', [], [
'absolute' => TRUE,
])
->toString();
$abs_url_icons_config = Url::fromRoute('we_megamenu.geticons', [], [
'absolute' => TRUE,
])
->toString();
$build['#attached']['drupalSettings']['WeMegaMenu']['saveConfigWeMegaMenuURL'] = $abs_url_save_config;
$build['#attached']['drupalSettings']['WeMegaMenu']['resetConfigWeMegaMenuURL'] = $abs_url_reset_config;
$build['#attached']['drupalSettings']['WeMegaMenu']['iconsWeMegaMenuURL'] = $abs_url_icons_config;
return $build;
}
/**
* A function ajax save menu config.
*/
public function saveConfigWeMegaMenu() {
if (isset($_POST['action']) && $_POST['action'] == 'save') {
$data_config = $_POST['data_config'];
$theme = $_POST['theme'];
$menu_name = $_POST['menu_name'];
WeMegaMenuBuilder::saveConfig($menu_name, $theme, $data_config);
we_megamenu_flush_render_cache();
}
exit;
}
/**
* A function reset menu config.
*/
public function resetConfigWeMegaMenu() {
if (isset($_POST['action']) && $_POST['action'] == 'reset' && isset($_POST['menu_name']) && isset($_POST['theme'])) {
$theme_array = WeMegaMenuBuilder::renderWeMegaMenuBlock($_POST['menu_name'], $_POST['theme']);
$markup = render($theme_array);
echo $markup;
we_megamenu_flush_render_cache();
exit;
}
if (isset($_POST['action']) && $_POST['action'] == 'reset-to-default' && isset($_POST['menu_name']) && isset($_POST['theme'])) {
$query = \Drupal::database()
->delete('we_megamenu');
$query
->condition('menu_name', $_POST['menu_name']);
$query
->condition('theme', $_POST['theme']);
$result = $query
->execute();
WeMegaMenuBuilder::initMegamenu($_POST['menu_name'], $_POST['theme']);
$theme_array = WeMegaMenuBuilder::renderWeMegaMenuBlock($_POST['menu_name'], $_POST['theme']);
$markup = render($theme_array);
echo $markup;
we_megamenu_flush_render_cache();
exit;
}
exit;
}
/**
* A function set style backend.
*/
public function styleOfBackendWeMegaMenu() {
if (isset($_POST['type'])) {
\Drupal::state()
->set('we_megamenu_backend_style', $_POST['type']);
we_megamenu_flush_render_cache();
}
exit;
}
/**
* Render block from post variable ajax.
*/
public function renderBlock() {
$title = TRUE;
if ($_POST['title'] == 0) {
$title = FALSE;
}
if (isset($_POST['bid']) && isset($_POST['section']) && !empty($_POST['bid'])) {
echo WeMegaMenuBuilder::renderBlock($_POST['bid'], $title, isset($_POST['section']));
}
else {
echo '';
}
exit;
}
/**
* Render page list menu backend.
*/
public function listWeMegaMenus() {
$menus = menu_ui_get_menus();
$rows = [];
foreach ($menus as $name => $title) {
$row = [
'menu-name' => $name,
'menu-title' => $title,
];
$dropbuttons = [
'#type' => 'operations',
'#links' => [
'config' => [
'url' => new Url('we_megamenu.admin.configure', [
'menu_name' => $name,
]),
'title' => 'Config',
],
'edit' => [
'url' => new Url('entity.menu.edit_form', [
'menu' => $name,
]),
'title' => 'Edit links',
],
],
];
$row['menu-operations'] = [
'data' => $dropbuttons,
];
$rows[] = $row;
}
$header = [
'menu-machine-name' => t('Machine Name'),
'menu-name' => t('Menu Name'),
'menu-options' => t('Options'),
];
return [
'#theme' => 'table',
'#header' => $header,
'#rows' => $rows,
'#empty' => t('No Drupal 8 Mega Menu block available. <a href="@link">Add Menu</a>.', [
'@link' => Url::fromRoute('entity.menu.add_form')
->toString(),
]),
'#attributes' => [
'id' => 'we_megamenu',
],
];
}
/**
* Render list icon font awesome.
*/
public function getIcons() {
$file = DRUPAL_ROOT . '/' . $this->moduleHandler
->getModule('we_megamenu')
->getPath() . '/assets/resources/icon.wemegamenu';
$fh = fopen($file, 'r');
$result = [];
while ($line = fgets($fh)) {
$result[] = trim($line);
}
fclose($fh);
echo json_encode($result);
exit;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ControllerBase:: |
protected | property | The current user service. | 1 |
ControllerBase:: |
protected | property | The entity form builder. | |
ControllerBase:: |
protected | property | The entity manager. | |
ControllerBase:: |
protected | property | The entity type manager. | |
ControllerBase:: |
protected | property | The form builder. | 2 |
ControllerBase:: |
protected | property | The key-value storage. | 1 |
ControllerBase:: |
protected | property | The language manager. | 1 |
ControllerBase:: |
protected | property | The state service. | |
ControllerBase:: |
protected | function | Returns the requested cache bin. | |
ControllerBase:: |
protected | function | Retrieves a configuration object. | |
ControllerBase:: |
private | function | Returns the service container. | |
ControllerBase:: |
protected | function | Returns the current user. | 1 |
ControllerBase:: |
protected | function | Retrieves the entity form builder. | |
ControllerBase:: |
protected | function | Retrieves the entity manager service. | |
ControllerBase:: |
protected | function | Retrieves the entity type manager. | |
ControllerBase:: |
protected | function | Returns the form builder service. | 2 |
ControllerBase:: |
protected | function | Returns a key/value storage collection. | 1 |
ControllerBase:: |
protected | function | Returns the language manager service. | 1 |
ControllerBase:: |
protected | function | Returns the module handler. | 2 |
ControllerBase:: |
protected | function |
Returns a redirect response object for the specified route. Overrides UrlGeneratorTrait:: |
|
ControllerBase:: |
protected | function | Returns the state storage service. | |
LinkGeneratorTrait:: |
protected | property | The link generator. | 1 |
LinkGeneratorTrait:: |
protected | function | Returns the link generator. | |
LinkGeneratorTrait:: |
protected | function | Renders a link to a route given a route name and its parameters. | |
LinkGeneratorTrait:: |
public | function | Sets the link generator service. | |
LoggerChannelTrait:: |
protected | property | The logger channel factory service. | |
LoggerChannelTrait:: |
protected | function | Gets the logger for a specific channel. | |
LoggerChannelTrait:: |
public | function | Injects the logger channel factory. | |
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
RedirectDestinationTrait:: |
protected | property | The redirect destination service. | 1 |
RedirectDestinationTrait:: |
protected | function | Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url. | |
RedirectDestinationTrait:: |
protected | function | Returns the redirect destination service. | |
RedirectDestinationTrait:: |
public | function | Sets the redirect destination service. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. | |
UrlGeneratorTrait:: |
protected | property | The url generator. | |
UrlGeneratorTrait:: |
protected | function | Returns the URL generator service. | |
UrlGeneratorTrait:: |
public | function | Sets the URL generator service. | |
UrlGeneratorTrait:: |
protected | function | Generates a URL or path for a specific route based on the given parameters. | |
WeMegaMenuAdminController:: |
protected | property |
The config factory. Overrides ControllerBase:: |
|
WeMegaMenuAdminController:: |
protected | property |
The module handler. Overrides ControllerBase:: |
|
WeMegaMenuAdminController:: |
public | function | A function build page backend. | |
WeMegaMenuAdminController:: |
public static | function |
Instantiates a new instance of this class. Overrides ControllerBase:: |
|
WeMegaMenuAdminController:: |
public | function | Render list icon font awesome. | |
WeMegaMenuAdminController:: |
public | function | Render page list menu backend. | |
WeMegaMenuAdminController:: |
public | function | Render block from post variable ajax. | |
WeMegaMenuAdminController:: |
public | function | A function reset menu config. | |
WeMegaMenuAdminController:: |
public | function | A function ajax save menu config. | |
WeMegaMenuAdminController:: |
public | function | A function set style backend. | |
WeMegaMenuAdminController:: |
public | function | Constructs the WeMegaMenuAdminController. |