You are here

function domain_menu_access_form_menu_link_content_form_alter in Domain Menu Access 8

Implements hook_form_BASE_FORM_ID_alter() for \Drupal\menu_link_content\MenuLinkContentForm.

Move Domain Access fields to an advanced tab like other node settings.

File

./domain_menu_access.module, line 27
Domain-based access control for menu link.

Code

function domain_menu_access_form_menu_link_content_form_alter(&$form, FormStateInterface $form_state, $form_id) {

  /** @var \Drupal\menu_link_content\Form\MenuLinkContentForm $form_object */
  $form_object = $form_state
    ->getFormObject();

  /** @var \Drupal\menu_link_content\Entity\MenuLinkContent $entity */
  $entity = $form_object
    ->getEntity();
  $config = \Drupal::config('domain_menu_access.settings')
    ->get('menu_enabled');
  if (!empty($config) && in_array($entity
    ->getMenuName(), $config)) {
    $form['domain'] = [
      '#type' => 'details',
      '#title' => t('Domain'),
      '#open' => TRUE,
      '#weight' => 25,
    ];
    $form[DOMAIN_ACCESS_FIELD]['#group'] = 'domain';
    $form[DOMAIN_ACCESS_ALL_FIELD]['#group'] = 'domain';

    // Add the options hidden from the user silently to the form.
    $manager = \Drupal::service('domain.element_manager');
    $form = $manager
      ->setFormOptions($form, $form_state, DOMAIN_ACCESS_FIELD);
  }
  else {
    $form[DOMAIN_ACCESS_FIELD]['#access'] = FALSE;
    $form[DOMAIN_ACCESS_ALL_FIELD]['#access'] = FALSE;
  }
}