You are here

abstract class FormWidgetBase in Typed Data API enhancements 8

Base class for 'form widget' plugin implementations.

Hierarchy

Expanded class hierarchy of FormWidgetBase

6 files declare their use of FormWidgetBase
BrokenWidget.php in src/Plugin/TypedDataFormWidget/BrokenWidget.php
DatetimeRangeWidget.php in src/Plugin/TypedDataFormWidget/DatetimeRangeWidget.php
DatetimeWidget.php in src/Plugin/TypedDataFormWidget/DatetimeWidget.php
SelectWidget.php in src/Plugin/TypedDataFormWidget/SelectWidget.php
TextareaWidget.php in src/Plugin/TypedDataFormWidget/TextareaWidget.php

... See full list

File

src/Widget/FormWidgetBase.php, line 15

Namespace

Drupal\typed_data\Widget
View source
abstract class FormWidgetBase extends PluginBase implements FormWidgetInterface, ContainerFactoryPluginInterface {

  /**
   * The typed data plugin manager.
   *
   * @var \Drupal\Core\TypedData\TypedDataManagerInterface
   */
  protected $typedDataManager;

  /**
   * Constructs a FormWidgetBase object.
   *
   * @param array $configuration
   *   A configuration array containing information about the plugin instance.
   * @param string $plugin_id
   *   The plugin ID for the plugin instance.
   * @param mixed $plugin_definition
   *   The plugin implementation definition.
   * @param \Drupal\Core\TypedData\TypedDataManagerInterface $typed_data_manager
   *   The typed data plugin manager.
   */
  public function __construct(array $configuration, $plugin_id, $plugin_definition, TypedDataManagerInterface $typed_data_manager) {
    parent::__construct($configuration + $this
      ->defaultConfiguration(), $plugin_id, $plugin_definition);
    $this->typedDataManager = $typed_data_manager;
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
    return new static($configuration, $plugin_id, $plugin_definition, $container
      ->get('typed_data_manager'));
  }

  /**
   * {@inheritdoc}
   */
  public function defaultConfiguration() {
    return [];
  }

  /**
   * {@inheritdoc}
   */
  public function getConfiguration() {
    return $this->configuration;
  }

  /**
   * {@inheritdoc}
   */
  public function setConfiguration(array $configuration) {
    $this->configuration = NestedArray::mergeDeep($this
      ->defaultConfiguration(), $configuration);
  }

  /**
   * Create a default DrupalDateTime object.
   *
   * This is used in the DateTimeWidget and DateTimeRangeWidget forms.
   *
   * @param string $date
   *   (optional) A formatted date string as stored by the widgets. If no value
   *   is given an empty date with time 12:00 noon is created.
   *
   * @return object
   *   A DrupalDateTime object with the required date and time values.
   */
  public function createDefaultDateTime($date) {
    if (!empty($date)) {
      $default = new DrupalDateTime($date);
    }
    else {

      // The DrupalDateTime object is created first with no parameters so that
      // it has the current users timezone. Then setDate with year 0 has the
      // effect that the widget date remains empty but allows a default time to
      // be set using setTime(). This is done in setDefaultDateTime().
      $default = new DrupalDateTime();
      $default
        ->setDate(0, 1, 1);
      $default
        ->setDefaultDateTime();
    }
    return $default;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DependencySerializationTrait::$_entityStorages protected property An array of entity type IDs keyed by the property name of their storages.
DependencySerializationTrait::$_serviceIds protected property An array of service IDs keyed by property name used for serialization.
DependencySerializationTrait::__sleep public function 1
DependencySerializationTrait::__wakeup public function 2
FormWidgetBase::$typedDataManager protected property The typed data plugin manager.
FormWidgetBase::create public static function Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface::create
FormWidgetBase::createDefaultDateTime public function Create a default DrupalDateTime object.
FormWidgetBase::defaultConfiguration public function Gets default configuration for this plugin. Overrides ConfigurableInterface::defaultConfiguration 6
FormWidgetBase::getConfiguration public function Gets this plugin's configuration. Overrides ConfigurableInterface::getConfiguration
FormWidgetBase::setConfiguration public function Sets the configuration for this plugin instance. Overrides ConfigurableInterface::setConfiguration
FormWidgetBase::__construct public function Constructs a FormWidgetBase object. Overrides PluginBase::__construct
FormWidgetInterface::extractFormValues public function Extracts the data value from submitted form values. 6
FormWidgetInterface::flagViolations public function Reports validation errors against actual form elements. 6
FormWidgetInterface::form public function Creates the widget's form elements for editing the given data. 6
FormWidgetInterface::getConfigurationDefinitions public function Defines the supported configuration settings. 6
FormWidgetInterface::isApplicable public function Returns if the widget can be used for the provided data. 6
MessengerTrait::$messenger protected property The messenger. 29
MessengerTrait::messenger public function Gets the messenger. 29
MessengerTrait::setMessenger public function Sets the messenger.
PluginBase::$configuration protected property Configuration information passed into the plugin. 1
PluginBase::$pluginDefinition protected property The plugin implementation definition. 1
PluginBase::$pluginId protected property The plugin_id.
PluginBase::DERIVATIVE_SEPARATOR constant A string which is used to separate base plugin IDs from the derivative ID.
PluginBase::getBaseId public function Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface::getBaseId
PluginBase::getDerivativeId public function Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface::getDerivativeId
PluginBase::getPluginDefinition public function Gets the definition of the plugin implementation. Overrides PluginInspectionInterface::getPluginDefinition 3
PluginBase::getPluginId public function Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface::getPluginId
PluginBase::isConfigurable public function Determines if the plugin is configurable.
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.