ModalHelpController.php in Modal 4.1.x
File
src/Controller/ModalHelpController.php
View source
<?php
namespace Drupal\modal_page\Controller;
use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\Extension\ExtensionList;
use Drupal\Core\Routing\RouteMatchInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Core\Config\ConfigFactoryInterface;
class ModalHelpController extends ControllerBase {
protected $routeMatch;
protected $extensionListModule;
protected $configFactory;
public function __construct(RouteMatchInterface $route_match, ExtensionList $extension_list_module, ConfigFactoryInterface $config_factory) {
$this->routeMatch = $route_match;
$this->extensionListModule = $extension_list_module;
$this->configFactory = $config_factory;
}
public static function create(ContainerInterface $container) {
return new static($container
->get('current_route_match'), $container
->get('extension.list.module'), $container
->get('config.factory'));
}
public function index() {
$build = [];
$projectMachineName = 'modal_page';
$projectName = $this
->moduleHandler()
->getName($projectMachineName);
$build['#title'] = 'Modal Page Help';
$helperMarkup = $this
->moduleHandler()
->invoke($projectMachineName, 'help', [
"help.page.{$projectMachineName}",
$this->routeMatch,
]);
if (!is_array($helperMarkup)) {
$helperMarkup = [
'#markup' => $helperMarkup,
];
}
$build['top'] = $helperMarkup;
$adminTasks = system_get_module_admin_tasks($projectMachineName, $this->extensionListModule
->getExtensionInfo($projectMachineName));
if (empty($adminTasks)) {
return $build;
}
$links = [];
foreach ($adminTasks as $adminTask) {
$link['url'] = $adminTask['url'];
$link['title'] = $adminTask['title'];
if ($link['url']
->getRouteName() === 'modal_page.settings') {
$link['title'] = 'Modal Settings';
}
$links[] = $link;
}
$build['links'] = [
'#theme' => 'links__help',
'#heading' => [
'level' => 'h3',
'text' => $this
->t('@project_name administration pages', [
'@project_name' => $projectName,
]),
],
'#links' => $links,
];
return $build;
}
public function enableBootstrapAutomatically() {
$settings = $this->configFactory
->getEditable('modal_page.settings');
$verifyLoadBootstrapAutomatically = $settings
->get('verify_load_bootstrap_automatically');
if (empty($verifyLoadBootstrapAutomatically)) {
echo FALSE;
exit;
}
$settings
->set('load_bootstrap', TRUE);
$settings
->save();
echo TRUE;
exit;
}
}