ShortcutController.php in Drupal 9
File
core/modules/shortcut/src/Controller/ShortcutController.php
View source
<?php
namespace Drupal\shortcut\Controller;
use Drupal\Core\Controller\ControllerBase;
use Drupal\shortcut\ShortcutSetInterface;
use Drupal\shortcut\ShortcutInterface;
class ShortcutController extends ControllerBase {
public function addForm(ShortcutSetInterface $shortcut_set) {
$shortcut = $this
->entityTypeManager()
->getStorage('shortcut')
->create([
'shortcut_set' => $shortcut_set
->id(),
]);
return $this
->entityFormBuilder()
->getForm($shortcut, 'add');
}
public function deleteShortcutLinkInline(ShortcutInterface $shortcut) {
$label = $shortcut
->label();
try {
$shortcut
->delete();
$this
->messenger()
->addStatus($this
->t('The shortcut %title has been deleted.', [
'%title' => $label,
]));
} catch (\Exception $e) {
$this
->messenger()
->addStatus($this
->t('Unable to delete the shortcut for %title.', [
'%title' => $label,
]), 'error');
}
return $this
->redirect('<front>');
}
}