You are here

class WebformElementAlterEvent in Hook Event Dispatcher 8

Same name and namespace in other branches
  1. 8.2 modules/webform_event_dispatcher/src/Event/WebformElement/WebformElementAlterEvent.php \Drupal\webform_event_dispatcher\Event\WebformElement\WebformElementAlterEvent
  2. 3.x modules/webform_event_dispatcher/src/Event/WebformElement/WebformElementAlterEvent.php \Drupal\webform_event_dispatcher\Event\WebformElement\WebformElementAlterEvent

Class WebformElementAlterEvent.

@package Drupal\webform_event_dispatcher\Event\Element

Hierarchy

Expanded class hierarchy of WebformElementAlterEvent

2 files declare their use of WebformElementAlterEvent
WebformElementEventTest.php in modules/webform_event_dispatcher/tests/src/Unit/WebformElement/WebformElementEventTest.php
webform_event_dispatcher.module in modules/webform_event_dispatcher/webform_event_dispatcher.module
Webform event dispatcher submodule.

File

modules/webform_event_dispatcher/src/Event/WebformElement/WebformElementAlterEvent.php, line 15

Namespace

Drupal\webform_event_dispatcher\Event\WebformElement
View source
class WebformElementAlterEvent extends Event implements EventInterface {

  /**
   * The webform element.
   *
   * @var array
   */
  private $element;

  /**
   * The form state.
   *
   * @var \Drupal\Core\Form\FormStateInterface
   */
  private $formState;

  /**
   * The context.
   *
   * @var array
   */
  private $context;

  /**
   * WebformElementAlterEvent constructor.
   *
   * @param array $element
   *   The webform element.
   * @param \Drupal\Core\Form\FormStateInterface $formState
   *   The current state of the form.
   * @param array $context
   *   An associative array containing the following key-value pairs:
   *   - form: The form structure to which elements is being attached.
   */
  public function __construct(array &$element, FormStateInterface $formState, array $context) {
    $this->element =& $element;
    $this->formState = $formState;
    $this->context = $context;
  }

  /**
   * Get the webform element.
   *
   * @return array
   *   The element.
   */
  public function &getElement() {
    return $this->element;
  }

  /**
   * Get the webform element type.
   *
   * @return string
   *   The webform element type.
   */
  public function getElementType() {
    return $this
      ->getElement()['#type'];
  }

  /**
   * Get the form state.
   *
   * @return \Drupal\Core\Form\FormStateInterface
   *   The form state.
   */
  public function getFormState() {
    return $this->formState;
  }

  /**
   * Get the context.
   *
   * @return array
   *   The context.
   */
  public function getContext() {
    return $this->context;
  }

  /**
   * {@inheritdoc}
   */
  public function getDispatcherType() {
    return HookEventDispatcherInterface::WEBFORM_ELEMENT_ALTER;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
WebformElementAlterEvent::$context private property The context.
WebformElementAlterEvent::$element private property The webform element.
WebformElementAlterEvent::$formState private property The form state.
WebformElementAlterEvent::getContext public function Get the context.
WebformElementAlterEvent::getDispatcherType public function Get the dispatcher type. Overrides EventInterface::getDispatcherType 1
WebformElementAlterEvent::getElement public function Get the webform element.
WebformElementAlterEvent::getElementType public function Get the webform element type.
WebformElementAlterEvent::getFormState public function Get the form state.
WebformElementAlterEvent::__construct public function WebformElementAlterEvent constructor.