You are here

class WidgetFormAlterEvent in Hook Event Dispatcher 8

Class WidgetFormAlterEvent.

Hierarchy

Expanded class hierarchy of WidgetFormAlterEvent

2 files declare their use of WidgetFormAlterEvent
ExampleFormEventSubscribers.php in src/Example/ExampleFormEventSubscribers.php
hook_event_dispatcher.module in ./hook_event_dispatcher.module
Hook event dispatcher module.

File

src/Event/Form/WidgetFormAlterEvent.php, line 13

Namespace

Drupal\hook_event_dispatcher\Event\Form
View source
class WidgetFormAlterEvent extends Event implements EventInterface {

  /**
   * The field widget form element.
   *
   * @var array
   */
  protected $element;

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

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

  /**
   * WidgetFormAlterEvent constructor.
   *
   * @param array $element
   *   The field widget form element as constructed by hook_field_widget_form().
   * @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 widgets are being attached. This may
   *     be a full form structure, or a sub-element of a larger form.
   *   - widget: The widget plugin instance.
   *   - items: The field values, as a
   *     \Drupal\Core\Field\FieldItemListInterface object.
   *   - delta: The order of this item in the array of subelements (0, 1, etc).
   *   - default: A boolean indicating whether the form is being shown as a
   *     dummy form to set default values.
   */
  public function __construct(array &$element, FormStateInterface $formState, array $context) {
    $this->element =& $element;
    $this->formState = $formState;
    $this->context = $context;
  }

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

  /**
   * Set the element.
   *
   * @param array $element
   *   The element.
   *
   * @deprecated This is not needed anymore, use the element by reference.
   */
  public function setElement(array $element) {
    $this->element = $element;
  }

  /**
   * 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::WIDGET_FORM_ALTER;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
WidgetFormAlterEvent::$context protected property The context.
WidgetFormAlterEvent::$element protected property The field widget form element.
WidgetFormAlterEvent::$formState protected property The form state.
WidgetFormAlterEvent::getContext public function Get the context.
WidgetFormAlterEvent::getDispatcherType public function Get the dispatcher type. Overrides EventInterface::getDispatcherType 1
WidgetFormAlterEvent::getElement public function Get the element.
WidgetFormAlterEvent::getFormState public function Get the form state.
WidgetFormAlterEvent::setElement Deprecated public function Set the element.
WidgetFormAlterEvent::__construct public function WidgetFormAlterEvent constructor.