domain_menu_access.module in Domain Menu Access 8
Same filename and directory in other branches
Domain-based access control for menu link.
File
domain_menu_access.moduleView source
<?php
/**
* @file
* Domain-based access control for menu link.
*/
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Form\FormStateInterface;
/**
* Implements hook_ENTITY_TYPE_presave().
*
* Fires only if Devel Generate module is present, to assign test menu
* link content to domains.
*/
function domain_menu_access_menu_link_content_presave(EntityInterface $node) {
domain_access_presave_generate($node);
}
/**
* 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.
*/
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;
}
}
Functions
Name | Description |
---|---|
domain_menu_access_form_menu_link_content_form_alter | Implements hook_form_BASE_FORM_ID_alter() for \Drupal\menu_link_content\MenuLinkContentForm. |
domain_menu_access_menu_link_content_presave | Implements hook_ENTITY_TYPE_presave(). |