我试图通过将选项_maintenance_access添加到路由并将其设置为TRUE,从而使某些路由免于维护模式的限制。
我认为(虽然我不是100%),这是因为在Drupal\Core\Site\维护模式中有以下方法检查_maintenance_access选项,如果它存在,则返回false -
public function applies(RouteMatchInterface $route_match) {
if (!$this->state->get('system.maintenance_mode')) {
return FALSE;
}
if ($route = $route_match->getRouteObject()) {
if ($route->getOption('_maintenance_access')) {
return FALSE;
}
}
return TRUE;
}我遵循了这关于drupal.org关于如何改变现有路线的指南。
这是我的mymodule.services.yml文件
services:
mymodule.route_subscriber:
class: Drupal\mymodule\Routing\MaintenanceModeRouteSubscriber
tags:
- { name: event_subscriber }这是我的MaintenanceModeRouteSubscriber课
get('entity.node.canonical')) {
$route->addOptions(['_maintenance_access' => TRUE]);
}
}
}但是,当查看此路由(任何节点)时,它仍然处于维护模式,这是不起作用的。
发布于 2020-09-30 21:35:21
您需要直接覆盖服务。
mymodule.services.yml
services:
maintenance_mode: # same ID as declared in core.services.yml
class: Drupal\mymodule\Services\CustomMaintenanceMode # point to your class
arguments: ['@state']mymodule/src/Services/CustomMaintenaceMode.php
getParameter('node');
if ($node instanceof \Drupal\node\NodeInterface && $node->getType() == 'article') {
return TRUE;
}
else {
return $account->hasPermission('access site in maintenance mode');
}
}
}https://drupal.stackexchange.com/questions/297115
复制相似问题