简体   繁体   English

如何在 Drupal 9 中以编程方式添加快捷链接?

[英]How to add a shortcut link programmatically in Drupal 9?

Trying to add some shortcut link I get this error尝试添加一些快捷链接我收到此错误

Fatal error: InvalidArgumentException: The URI '' is invalid.致命错误:InvalidArgumentException:URI“”无效。 You must use a valid URI scheme.您必须使用有效的 URI 方案。 in../core/lib/Drupal/Core/Url.php:293在../core/lib/Drupal/Core/Url.php:293

use Drupal\shortcut\Entity\Shortcut;
$taxo_shorcut = Shortcut::create([
    'shortcut_set' =>'default',
    'title' =>  'Test',
    'link' =>  'admin/structure/taxonomy',
]);
$taxo_shorcut->save();

Any help?有什么帮助吗?

Build the URI structure correctly with a uri key value using the internal: scheme:使用internal:方案使用uri键值正确构建 URI 结构:

$taxo_shorcut = Shortcut::create([
  'shortcut_set' => 'default',
  'title' => 'Test',
  'link' => [
    'uri' => 'internal:/admin/structure/taxonomy',
  ],
]);
$taxo_shorcut->save();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 C# 中以编程方式创建桌面快捷方式(链接),但使用自己的快捷方式文件扩展名(例如 .appfolder)而不是 .lnk? - How to create a desktop shortcut (link), but with own shortcut file extension (e.g. .appfolder) instead of .lnk programmatically in C#? 如何在 JavaFX 中添加快捷键? - How to add a key shortcut in JavaFX? 以编程方式在Windows中创建快捷方式 - Create shortcut in windows programmatically 以编程方式在ios上创建快捷方式 - Create Shortcut on ios programmatically 如何使用Win32以编程方式创建快捷方式 - How to programmatically create a shortcut using Win32 如何以编程方式生成图标并使用它代替快捷方式图标? - How to generate icon programmatically and use it instead of a shortcut icon? 如何通过JS在android / ios上以编程方式为网站创建桌面快捷方式? - how to programmatically create a desktop shortcut for a website on android/ios with js? Android:如何以编程方式用新项目更新应用程序快捷方式图标 - Android: How to update application shortcut icon with a new items count programmatically 如何为Wix引导程序添加卸载快捷方式? - How to add uninstall shortcut to Wix bootstrap? 如何在桌面的应用程序快捷方式中添加图标 - how to add icon to application's shortcut in desktop
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM