You are here

entity_hierarchy_microsite.api.php in Entity Reference Hierarchy 8.2

Contains documentation for module APIs.

File

modules/entity_hierarchy_microsite/entity_hierarchy_microsite.api.php
View source
<?php

/**
 * @file
 * Contains documentation for module APIs.
 */

/**
 * Allows modules to alter the URL generated from a microsite menu override.
 *
 * @param \Drupal\Core\Url $url
 *   The default URL.
 * @param \Drupal\entity_hierarchy_microsite\Entity\MicrositeMenuItemOverrideInterface $override
 *   The override entity.
 * @param \Drupal\entity_hierarchy_microsite\Plugin\Menu\MicrositeMenuItem $menu_link
 *   The menu link plugin instance.
 */
function hook_entity_hierarchy_microsite_menu_item_url_alter(\Drupal\Core\Url $url, \Drupal\entity_hierarchy_microsite\Entity\MicrositeMenuItemOverrideInterface $override, \Drupal\entity_hierarchy_microsite\Plugin\Menu\MicrositeMenuItem $menu_link) {
  $attributes = $url
    ->getOption('attributes');
  $attributes['class'] = [
    $override->some_field->value,
  ];
  $url
    ->setOption('attributes', $attributes);
}

/**
 * Allows modules to alter the microsite menu links.
 *
 * @param array $links
 *   The link definitions to be altered.
 */
function hook_entity_hierarchy_microsite_links_alter($links) {

  // Disable all test node links in the microsite menu.
  foreach ($links as $key => $link) {
    if (empty($link['menu_name']) || $link['menu_name'] !== 'entity-hierarchy-microsite') {
      continue;
    }
    if (empty($link['options']['entity']) || !($node = $link['options']['entity']) || !$node instanceof \Drupal\node\NodeInterface || $node
      ->bundle() !== 'test') {
      continue;
    }
    $links[$key]['enabled'] = 0;
  }
}

Functions

Namesort descending Description
hook_entity_hierarchy_microsite_links_alter Allows modules to alter the microsite menu links.
hook_entity_hierarchy_microsite_menu_item_url_alter Allows modules to alter the URL generated from a microsite menu override.