You are here

trait FormWidgetManagerTrait in Typed Data API enhancements 8

Helper to access the form widget manager service.

Hierarchy

3 files declare their use of FormWidgetManagerTrait
FormWidgetBrowserTestBase.php in tests/src/Functional/TypedDataFormWidget/FormWidgetBrowserTestBase.php
FormWidgetExampleController.php in tests/modules/typed_data_widget_test/src/FormWidgetExampleController.php
FormWidgetExampleForm.php in tests/modules/typed_data_widget_test/src/FormWidgetExampleForm.php

File

src/Widget/FormWidgetManagerTrait.php, line 8

Namespace

Drupal\typed_data\Widget
View source
trait FormWidgetManagerTrait {

  /**
   * The widget manager.
   *
   * @var \Drupal\typed_data\Widget\FormWidgetManagerInterface
   */
  protected $widgetManager;

  /**
   * Sets the widget manager.
   *
   * @param \Drupal\typed_data\Widget\FormWidgetManagerInterface $widgetManager
   *   The widget manager.
   *
   * @return $this
   */
  public function setFormWidgetManager(FormWidgetManagerInterface $widgetManager) {
    $this->widgetManager = $widgetManager;
    return $this;
  }

  /**
   * Gets the widget manager.
   *
   * @return \Drupal\typed_data\Widget\FormWidgetManagerInterface
   *   The widget manager.
   */
  public function getFormWidgetManager() {
    if (empty($this->widgetManager)) {
      $this->widgetManager = \Drupal::service('plugin.manager.typed_data_form_widget');
    }
    return $this->widgetManager;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
FormWidgetManagerTrait::$widgetManager protected property The widget manager.
FormWidgetManagerTrait::getFormWidgetManager public function Gets the widget manager.
FormWidgetManagerTrait::setFormWidgetManager public function Sets the widget manager.