Skip to content
Snippets Groups Projects

Resolve #3184181 "Deleting a menu"

Closed Pierre Rudloff requested to merge issue/drupal-3184181:3184181-deleting-a-menu into 11.x
All threads resolved!
Files
6
@@ -16,6 +16,9 @@
@@ -16,6 +16,9 @@
use Drupal\Core\Url;
use Drupal\Core\Url;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Hook\Attribute\Hook;
use Drupal\Core\Hook\Attribute\Hook;
 
use Drupal\menu_link_content\Entity\MenuLinkContent;
 
use Drupal\Core\Access\AccessResultInterface;
 
use Drupal\Core\Entity\EntityTypeManagerInterface;
/**
/**
* Hook implementations for menu_ui.
* Hook implementations for menu_ui.
@@ -24,6 +27,16 @@ class MenuUiHooks {
@@ -24,6 +27,16 @@ class MenuUiHooks {
use StringTranslationTrait;
use StringTranslationTrait;
 
/**
 
* Constructs a new MenuUiHooks object.
 
*
 
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManager
 
* The entity type manager.
 
*/
 
public function __construct(
 
protected EntityTypeManagerInterface $entityTypeManager,
 
) {}
 
/**
/**
* Implements hook_help().
* Implements hook_help().
*/
*/
@@ -86,6 +99,27 @@ public function blockViewSystemMenuBlockAlter(array &$build, BlockPluginInterfac
@@ -86,6 +99,27 @@ public function blockViewSystemMenuBlockAlter(array &$build, BlockPluginInterfac
}
}
}
}
 
/**
 
* Check if user is allowed to use the menu link subform.
 
*
 
* @param array $defaults
 
* An array that contains default values for the menu link form.
 
*
 
* @see menu_ui_get_menu_link_defaults()
 
*/
 
protected function getMenuLinkContentAccess(array $defaults): AccessResultInterface {
 
if (!empty($defaults['entity_id'])) {
 
$entity = MenuLinkContent::load($defaults['entity_id']);
 
 
// The form can be used to edit or delete the menu link.
 
return $entity->access('update', NULL, TRUE)->andIf($entity->access('delete', NULL, TRUE));
 
}
 
else {
 
// If the node has no corresponding menu link, users needs to permission to create one.
 
return $this->entityTypeManager->getAccessControlHandler('menu_link_content')->createAccess(NULL, NULL, [], TRUE);
 
}
 
}
 
/**
/**
* Implements hook_form_BASE_FORM_ID_alter() for \Drupal\node\NodeForm.
* Implements hook_form_BASE_FORM_ID_alter() for \Drupal\node\NodeForm.
*
*
@@ -128,7 +162,7 @@ public function formNodeFormAlter(&$form, FormStateInterface $form_state) : void
@@ -128,7 +162,7 @@ public function formNodeFormAlter(&$form, FormStateInterface $form_state) : void
$form['menu'] = [
$form['menu'] = [
'#type' => 'details',
'#type' => 'details',
'#title' => $this->t('Menu settings'),
'#title' => $this->t('Menu settings'),
'#access' => \Drupal::currentUser()->hasPermission('administer menu'),
'#access' => $this->getMenuLinkContentAccess($defaults),
'#open' => (bool) $defaults['id'],
'#open' => (bool) $defaults['id'],
'#group' => 'advanced',
'#group' => 'advanced',
'#attached' => [
'#attached' => [
Loading