Show selected domains for each menulink on the menu edit page

Created on 16 March 2020, over 4 years ago
Updated 1 February 2023, over 1 year ago

Hi,

It would be very handy to see the assigned domains for each menulink straight in the edit menu overview page where all the menulinks of that menu are shown, like in the screenshot provided, but a little bit better (not as last column, and maybe domain links clickable).

I have provided a sample code to get started on this but I think it could be greatly imrpoved. However, this is what works for me for the moment to show the assigned domains on the menu edit page:

/**
 * Implements hook_preprocess_HOOK().
 *
 * Show selected domains for each menulink on the menu edit page.
 */
function MYMODULE_preprocess_table__menu_overview(&$variables) {
  $variables['header'][] = [
    'tag' => 'th',
    'content' => t('Domains'),
  ];

  foreach ($variables['rows'] as $index => $row) {

    $uuid = $variables['rows'][$index]['attributes']->storage()['data-drupal-selector']->value();
    $uuid = str_replace('edit-links-menu-plugin-idmenu-link-content', '', $uuid);
    $entity = \Drupal::service('entity.repository')->loadEntityByUuid('menu_link_content', $uuid);
    $domains = $entity->field_domain_access->getValue();
    $selected_domains = [];
    foreach ($domains as $key => $value) {
      $selected_domains[] = $entity->field_domain_access[$key]->entity->get('name');
    }
    $selected_domains = implode(', ', $selected_domains);
    $variables['rows'][$index]['cells'][] = [
      'tag' => 'td',
      'content' => $selected_domains,
    ];
  }
}

✨ Feature request
Status

Fixed

Version

2.0

Component

Code

Created by

πŸ‡§πŸ‡ͺBelgium flyke

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.69.0 2024