You are here

domain_menu_access.install in Domain Menu Access 8

Same filename and directory in other branches
  1. 6 domain_menu_access.install
  2. 7 domain_menu_access.install

Install, update and uninstall functions for the Domain Menu Access module.

File

domain_menu_access.install
View source
<?php

/**
 * @file
 * Install, update and uninstall functions for the Domain Menu Access module.
 */

/**
 * Implements hook_install().
 */
function domain_menu_access_install() {
  $text = [];
  $text['menu_link_content'] = [
    'name' => 'menu_link_content',
    'label' => 'Send for all affiliates',
    'description' => 'Make this menu entry available on all domains.',
  ];
  $entity_type = $bundle = 'menu_link_content';

  /** @var \Drupal\Core\Entity\Display\EntityFormDisplayInterface $entity_form_display_storage */
  $entity_form_display_storage = \Drupal::entityTypeManager()
    ->getStorage('entity_form_display');

  // By default, form display for menu_content_link entity doesn't exists.
  // We should create "default" form display for entity type to ensure that's
  // domain access fields will be successfully added.
  if (!$entity_form_display_storage
    ->load($entity_type . '.' . $bundle . '.default')) {
    $display = $entity_form_display_storage
      ->create([
      'targetEntityType' => $entity_type,
      'bundle' => $bundle,
      'mode' => 'default',
      'status' => TRUE,
    ]);
    $display
      ->save();
  }
  domain_access_confirm_fields($entity_type, $bundle, $text);
}

/**
 * Implements hook_uninstall().
 *
 * Removes access control fields on uninstall.
 */
function domain_menu_access_uninstall() {
  $entity_type = $bundle = 'menu_link_content';

  /** @var \Drupal\Core\Entity\Display\EntityFormDisplayInterface $storage */
  $entity_form_display_storage = \Drupal::entityTypeManager()
    ->getStorage('entity_form_display');
  if ($display = $entity_form_display_storage
    ->load($entity_type . '.' . $bundle . '.default')) {
    $display
      ->delete();
  }
  $field_names = [
    $entity_type . '.' . DOMAIN_ACCESS_FIELD,
    $entity_type . '.' . DOMAIN_ACCESS_ALL_FIELD,
  ];
  $field_storage_config = \Drupal::entityTypeManager()
    ->getStorage('field_storage_config');
  $fields = $field_storage_config
    ->loadMultiple($field_names);
  if (!empty($fields)) {
    $field_storage_config
      ->delete($fields);
  }
}

Functions