我为我的网站上的视图制作了一些自定义代码,用于查看服务器上显示的节点并获取其标题,然后更改视图的标题。这对于自定义元标记非常有效,但如何调整代码以获得描述以及标题?
//News Page Title Code
if ($arg['1'] == 'news-page' && $arg['2'] == 'news-display') {
$nid = $arg['3'];
$values = \Drupal::entityQuery('node')->condition('nid', $nid)->execute();
if ($values) {
$node = \Drupal::entityTypeManager()->getStorage('node')->load($nid);
$title = $node->getTitle();
$request = \Drupal::request();
if ($route = $request->attributes->get(\Symfony\Cmf\Component\Routing\RouteObjectInterface::ROUTE_OBJECT)) {
$route->setDefault('_title', $title);
}
}
}