我们在项目开发中,经常使用最新的layout builder模块,同时还要使用Bootstrap。
遗憾的是,当前的bootstrap和Layout builder的兼容性并不好,样式比较混乱,为了简单起见,我们为layout builder的配置页面使用单独的主题。
在一个Drupal8站点,为特定页面单独指定主题,这是可行的,以我们这里的需求为例:
class ThemeNegotiator implements ThemeNegotiatorInterface {
/**
* {@inheritdoc}
*/
public function applies(RouteMatchInterface $route_match) {
// Use this theme on a certain route.
$flag = FALSE;
$route_name = $route_match->getRouteName();
$query = "layout_builder.";
if (substr($route_name, 0, strlen($query)) === $query) {
$flag = TRUE;
}
return $flag;
}
/**
* {@inheritdoc}
*/
public function determineActiveTheme(RouteMatchInterface $route_match) {
// Here you return the actual theme name. bartik seven
return 'bartik';
}
}我们开始为layout builder指定seven主题,后来发现没有办法重新配置添加后的区块,后来改为bartik就好了。
Seven主题与layout builder兼容性问题参看:
https://www.drupal.org/project/drupal/issues/3005403
补丁也比较简单:
function seven_preprocess_block(&$variables) {
if (isset($variables['title_suffix']['contextual_links'])) {
- unset($variables['title_suffix']['contextual_links']);
- unset($variables['elements']['#contextual_links']);
+ if (!isset($variables['elements']['#contextual_links']['layout_builder_block'])) {
+ unset($variables['title_suffix']['contextual_links']);
+ unset($variables['elements']['#contextual_links']);
- $variables['attributes']['class'] = array_diff($variables['attributes']['class'], ['contextual-region']);
+ $variables['attributes']['class'] = array_diff($variables['attributes']['class'], ['contextual-region']);
+ }
}
}
随着layout builer应用的广泛,与之相关的模块也会不断丰富完善。

