0

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 :-)

1 Answer 1

0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.