sites_group_overrides-1.x-dev/src/Event/FieldOverrideEvent.php

src/Event/FieldOverrideEvent.php
<?php

declare(strict_types=1);

namespace Drupal\sites_group_overrides\Event;

use Drupal\Component\EventDispatcher\Event;
use Drupal\Core\Entity\FieldableEntityInterface;

/**
 * Event that is dispatched on field overrides.
 */
class FieldOverrideEvent extends Event {

  /**
   * The event name.
   */
  const EVENT_NAME = 'sites_grout_overrides.field_override';

  /**
   * The overidden value for the field.
   */
  protected mixed $value = NULL;

  public function __construct(
    protected FieldableEntityInterface $orignalEntity,
    protected FieldableEntityInterface $entity,
    protected string $fieldName,
  ) {}

  /**
   * Get the entity with overrides.
   *
   * @return \Drupal\Core\Entity\FieldableEntityInterface
   *   The entity with overrides
   */
  public function getEntity(): FieldableEntityInterface {
    return $this->entity;
  }

  /**
   * Get the original entity without overrides.
   *
   * @return \Drupal\Core\Entity\FieldableEntityInterface
   *   The original entity without overrides
   */
  public function getOriginalEntity(): FieldableEntityInterface {
    return $this->orignalEntity;
  }

  /**
   * Get the field name that we are overring.
   *
   * @return string
   *   The field name
   */
  public function getFieldName(): string {
    return $this->fieldName;
  }

  /**
   * Set the override value for the field.
   *
   * @param mixed $value
   *   The field value.
   */
  public function setValue(mixed $value): void {
    $this->value = $value;
  }

  /**
   * Get the override value for the field.
   *
   * @return mixed
   *   The field value.
   */
  public function getValue(): mixed {
    return $this->value;
  }

}

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

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