crocheteer-8.x-1.0/crocheteer_example/src/Plugin/crocheteer/Hook/HookEntityBaseFieldInfoAlterExample.php

crocheteer_example/src/Plugin/crocheteer/Hook/HookEntityBaseFieldInfoAlterExample.php
<?php

namespace Drupal\crocheteer_example\Plugin\crocheteer\Hook;

use Drupal\Core\Logger\LoggerChannelFactoryInterface;
use Drupal\Core\Logger\LoggerChannelInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\crocheteer\Plugin\Hook\EntityType\HookEntityBaseFieldInfoAlterPlugin;
use Drupal\crocheteer\Plugin\Hook\HookPluginInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
 * Example class for Hook Entity Base Field Info Alter.
 *
 * @HookEntityBaseFieldInfoAlter(
 *   id = "crocheteer_example_entity_base_field_info_alter",
 *   title = @Translation("Crocheteer Example: Entity Base Field Info Alter"),
 * )
 */
final class HookEntityBaseFieldInfoAlterExample extends HookEntityBaseFieldInfoAlterPlugin implements ContainerFactoryPluginInterface {

  /**
   * The injected Drupal Logger Channel dependency.
   *
   * @var \Drupal\Core\Logger\LoggerChannelInterface
   */
  private LoggerChannelInterface $loggerChannel;

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container, array $configuration, $pluginId, $pluginDefinition) : HookPluginInterface {
    return new static(
      $configuration,
      $pluginId,
      $pluginDefinition,
      $container->get('logger.factory')
    );
  }

  /**
   * HookEntityBaseFieldInfoAlterExample constructor.
   *
   * @param array $configuration
   *   A configuration array containing information about the plugin instance.
   * @param string $pluginId
   *   The plugin ID for the plugin instance.
   * @param mixed $pluginDefinition
   *   The plugin implementation definition.
   * @param \Drupal\Core\Logger\LoggerChannelFactoryInterface $loggerChannelFactory
   *   The Drupal Logger Channel Factory.
   */
  public function __construct(array $configuration, $pluginId, $pluginDefinition, LoggerChannelFactoryInterface $loggerChannelFactory) {
    parent::__construct($configuration, $pluginId, $pluginDefinition);
    $this->loggerChannel = $loggerChannelFactory->get($this->pluginDefinition['id']);
  }

  /**
   * {@inheritdoc}
   */
  public function hook() : void {
    if ($this->event->getEntityType()->id() === 'node') {
      $this->loggerChannel->info('Crocheteer Example: Entity Base Field Info Alter executed for the ' . $this->event->getEntityType()->id() . ' entity type!');
    }
  }

}

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

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