当您想在 Drupal 8 中添加指向菜单的链接时,您可以输入 a并从字段小部件Menu link title
的自动完成列表中选择一个选项 。Link
默认情况下,所有内容类型(文章、横幅、基本页面)的所有内容都在此自动完成选择列表中可用。
如何在自动完成选择字段小部件中设置内容类型Banner
和Basic page
不可用的所有内容?我只想显示内容类型的内容(已检查发布)Article
。
以下是我一一尝试的尝试,但它不起作用。
function my_module_entity_base_field_info_alter(&$fields, EntityTypeInterface $entity_type) {
if ($entity_type->id() == 'menu_link_content' && !empty($fields['link'])) {
// Attempt 1
$fields['link']->setTargetBundle('article');
// Attempt 2
$fields['link']->setSetting('handler_settings', ['target_bundles' => ['article' => 'article']]);
// Attempt 3
$fields['link']->setSetting('selection_settings', ['target_bundles' => ['article' => 'article']]);
// Attempt 4
$fields['link']->setSettings(['selection_settings' => ['target_bundles' => ['article' => 'article']]]);
// Attempt 5
$fields['link']->setSettings(['handler_settings' => ['target_bundles' => ['article' => 'article']]]);
}
}