association-1.0.0-alpha2/modules/association_menu/association_menu.module

modules/association_menu/association_menu.module
<?php

/**
 * @file
 * Provides the Drupal hooks and global module include for association_nav.
 */

use Drupal\association\Entity\AssociatedEntityInterface;
use Drupal\association\Entity\AssociationInterface;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Url;

/**
 * Implements hook_entity_operation().
 */
function association_menu_entity_operation(EntityInterface $entity) {
  $operations = [];

  if ($entity instanceof AssociationInterface && $entity->access('manage')) {
    if (\Drupal::currentUser()->hasPermission('access association menu management')) {
      $operations['menu'] = [
        'title' => t('Manage menu'),
        'url' => Url::fromRoute('association_menu.entity.menu_form', [
          'association' => $entity->id(),
        ]),
        'weight' => 25,
      ];
    }
  }
  return $operations;
}

/**
 * Implements hook_entity_insert().
 */
function association_menu_entity_insert(EntityInterface $entity) {
  if ($entity instanceof AssociatedEntityInterface) {
    \Drupal::service('association_menu.storage')
      ->addAssociated($entity);
  }
}

/**
 * Implements hook_ENTITY_TYPE_delete() for association_link.
 */
function association_menu_association_link_delete(EntityInterface $entity) {
  /** @var \Drupal\association\Entity\AssociationLink $entity */
  if (!$entity->isAssociationPurging()) {
    \Drupal::service('association_menu.storage')
      ->removeAssociated($entity);
  }
}

/**
 * Implements hook_ENTITY_TYPE_delete() for association.
 */
function association_menu_association_delete(AssociationInterface $entity) {
  \Drupal::service('association_menu.storage')
    ->deleteMenu($entity);
}

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc