Score:0

How to hide / modifiy ['operations']['#links'] edit / delete under structure -> menus in D8

ng flag

I am trying to hide the edit and eelete links in the operations menu under structure -> menu for specific roles.

I was just trying to hide the operations dialog at all by this code but it returns an:
Error: Cannot unset string offsets in my_menu_form_menu_edit_form_alter()

/**
 * @Implements hook_form_FORM_ID_alter().
 */
function my_menu_form_menu_edit_form_alter(&$form, FormStateInterface $form_state) {

  dpm($form);

  foreach ($form['links']['links'] as $index => $link) {
if (strpos($index, 'menu_link') !== false){
  dpm($form['links']['links'][$index]['operations']['#links']);
    unset($form['links']['links'][$index]['operations']);

  }
}

I too tried to change just the title of a link but that didn't work either and resulted with the same error.

In D7 you just could do something like $form[$key]['operations']['edit']['#access'] = FALSE;

Help :-)

Score:0
ng flag

Sorry! The code above is actually working. Just have some trouble since a couple of days with code caching in our DEV Environment where changes in code are only whipped from cache by logging in and logging out again. Already disabled all Drupal Caching, drush cr doesn't help - guess this some kind of docker, ddev, opcode mystic stuff.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.