entity_abuse-1.1.x-dev/entity_abuse.module

entity_abuse.module
<?php

/**
 * @file
 * Main file with hooks implementations for a Entity Abuse module.
 */

use Drupal\Core\Entity\Display\EntityViewDisplayInterface;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Url;
use Drupal\user\UserInterface;

/**
 * Entity URI callback.
 */
function entity_abuse_report_uri($report) {
  return new Url(
    'entity.entity_abuse_report.canonical',
    [
      'entity_abuse_report' => $report->id(),
    ]
  );
}

/**
 * Implements hook_theme().
 */
function entity_abuse_theme() {
  return [
    'entity_abuse_report_links' => [
      'variables' => [
        'create' => FALSE,
        'create_label' => NULL,
        'create_attributes' => NULL,
        'update' => FALSE,
        'update_label' => NULL,
        'update_attributes' => NULL,
        'cancel' => FALSE,
        'cancel_label' => NULL,
        'cancel_attributes' => NULL,
        'no_access' => FALSE,
        'no_access_label' => NULL,
        'no_access_attributes' => NULL,
      ],
    ],
  ];
}

/**
 * Implements hook_entity_extra_field_info().
 */
function entity_abuse_entity_extra_field_info() {
  $extra = [];

  $entity_types = \Drupal::service('entity_abuse.service')->getEnabledEntityTypes();

  foreach ($entity_types as $entity_type_id => $bundles) {
    foreach ($bundles as $bundle) {

      $extra[$entity_type_id][$bundle]['display']['entity_abuse_report_link'] = [
        'label' => t('Abuse report link'),
        'description' => t('Provide post Abuse report link.'),
        'weight' => 100,
        'visible' => TRUE,
      ];
    }
  }

  return $extra;
}

/**
 * Implements hook_entity_view().
 */
function entity_abuse_entity_view(array &$build, EntityInterface $entity, EntityViewDisplayInterface $display, $view_mode) {

  if ($display->getComponent('entity_abuse_report_link')) {
    $build['entity_abuse_report_link'] = [
      '#lazy_builder' => [
        'entity_abuse.report_link_lazy_builder:getLink',
        [
          $entity->id(),
          $entity->getEntityTypeId(),
          Url::fromRoute('<current>')->toString(),
        ],
      ],
      '#create_placeholder' => TRUE,
    ];
  }

}

/**
 * Implements hook_user_cancel().
 */
function entity_abuse_user_cancel($edit, UserInterface $account, $method) {
  /** @var \Drupal\entity_abuse\EntityAbuseServiceInterface $service */
  $service = \Drupal::service('entity_abuse.service');
  $service->userDelete($account);
}

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

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