Skip to content
Snippets Groups Projects
Commit 13b7706a authored by Julian Pustkuchen's avatar Julian Pustkuchen
Browse files

Extracted fixes from Issue #3205706 by skilip, Anybody: Port to D9

parent bc498546
Branches
Tags
No related merge requests found
front_page.admin_index:
title: 'Front Page'
description: 'Configure front page.'
parent: system.admin_config
parent: system.admin_config_system
route_name: front_page.admin_index
front_page.settings:
......
front_page.admin_index:
path: '/admin/config/front'
path: '/admin/config/system/front'
defaults:
_controller: '\Drupal\system\Controller\SystemController::systemAdminMenuBlockPage'
requirements:
_permission: 'administer front page'
front_page.settings:
path: '/admin/config/front/settings'
path: '/admin/config/system/front/settings'
defaults:
_form: 'Drupal\front_page\Form\FrontPageSettingsForm'
_title: 'Settings'
......@@ -14,7 +14,7 @@ front_page.settings:
_permission: 'administer front page'
front_page.home_links:
path: '/admin/config/front/home-links'
path: '/admin/config/system/front/home-links'
defaults:
_form: 'Drupal\front_page\Form\FrontPageHomeLinksForm'
_title: 'Home links'
......
......@@ -65,8 +65,6 @@ class FrontPageSubscriber implements EventSubscriberInterface {
* Managed event.
*/
public function initData(RequestEvent $event) {
global $base_path;
// Make sure front page module is not run when using cli (drush).
// Make sure front page module does not run when installing Drupal either.
if (PHP_SAPI === 'cli' || InstallerKernel::installationAttempted()) {
......@@ -102,7 +100,6 @@ class FrontPageSubscriber implements EventSubscriberInterface {
&& (($role_config['weight'] < $current_weight) || $current_weight === NULL)) {
// $base_path can contain a / at the end, strip to avoid double slash.
$path = rtrim($base_path, '/');
$front_page = $role_config['path'];
$current_weight = $role_config['weight'];
}
......@@ -110,6 +107,10 @@ class FrontPageSubscriber implements EventSubscriberInterface {
}
if ($front_page) {
// Add '/' to the beginning of url if url not begin with with a '/', '?', or '#'.
if (!str_starts_with($front_page, '/') && !str_starts_with($front_page, '#') && !str_starts_with($front_page, '?')) {
$front_page = '/' . $front_page;
}
$current_language = \Drupal::languageManager()->getCurrentLanguage();
$request = $event->getRequest();
$url = Url::fromUserInput($front_page, ['language' => $current_language, 'query' => $request->query->all()]);
......
......@@ -4,6 +4,7 @@ namespace Drupal\front_page\Form;
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\user\Entity\Role;
/**
* Configure site information settings for this site.
......@@ -33,7 +34,7 @@ class FrontPageSettingsForm extends ConfigFormBase {
$form['front_page_enable'] = [
'#type' => 'checkbox',
'#title' => $this->t('Front Page Override'),
'#title' => $this->t('Enable Front page override'),
'#description' => $this->t('Enable this if you want the front page module to manage the home page.'),
'#default_value' => $config->get('enabled') ?: FALSE,
];
......@@ -53,7 +54,7 @@ class FrontPageSettingsForm extends ConfigFormBase {
];
// Build the form for roles.
$roles = user_roles();
$roles = Role::loadMultiple();
// Iterate each role.
foreach ($roles as $rid => $role) {
......@@ -62,7 +63,7 @@ class FrontPageSettingsForm extends ConfigFormBase {
$form['roles'][$rid] = [
'#type' => 'details',
'#open' => FALSE,
'#title' => $this->t('Front Page for @rolename', ['@rolename' => $role->label()]),
'#title' => $this->t('Front page for @rolename', ['@rolename' => $role->label()]),
];
$form['roles'][$rid]['enabled'] = [
......
......@@ -2,6 +2,7 @@
namespace Drupal\front_page;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Config\ImmutableConfig;
use Drupal\Core\PathProcessor\OutboundPathProcessorInterface;
use Drupal\Core\Render\BubbleableMetadata;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment