You are here

class DoubleField in Double Field 8.3

Same name in this branch
  1. 8.3 src/Feeds/Target/DoubleField.php \Drupal\double_field\Feeds\Target\DoubleField
  2. 8.3 src/Plugin/Field/FieldWidget/DoubleField.php \Drupal\double_field\Plugin\Field\FieldWidget\DoubleField
  3. 8.3 src/Plugin/Field/FieldType/DoubleField.php \Drupal\double_field\Plugin\Field\FieldType\DoubleField

Plugin implementation of the 'double_field' widget.

Plugin annotation


@FieldWidget(
  id = "double_field",
  label = @Translation("Double Field"),
  field_types = {"double_field"}
)

Hierarchy

Expanded class hierarchy of DoubleField

2 files declare their use of DoubleField
TestBase.php in tests/src/Functional/TestBase.php
TestBase.php in tests/src/FunctionalJavascript/TestBase.php

File

src/Plugin/Field/FieldWidget/DoubleField.php, line 23

Namespace

Drupal\double_field\Plugin\Field\FieldWidget
View source
class DoubleField extends WidgetBase {

  /**
   * {@inheritdoc}
   */
  public static function defaultSettings() {
    foreach ([
      'first',
      'second',
    ] as $subfield) {
      $settings[$subfield] = [
        // As this method is static there is no way to set an appropriate type
        // for the subwidget. Let self::getSettings() do it instead.
        'type' => NULL,
        'label_display' => 'block',
        'prefix' => '',
        'suffix' => '',
        'size' => 10,
        'placeholder' => '',
        'label' => t('Ok'),
        'cols' => 10,
        'rows' => 5,
      ];
    }
    $settings['inline'] = FALSE;
    return $settings + parent::defaultSettings();
  }

  /**
   * {@inheritdoc}
   */
  public function settingsForm(array $form, FormStateInterface $form_state) {
    $settings = $this
      ->getSettings();
    $field_settings = $this
      ->getFieldSettings();
    $types = DoubleFieldItem::subfieldTypes();
    $field_name = $this->fieldDefinition
      ->getName();
    $element['inline'] = [
      '#type' => 'checkbox',
      '#title' => $this
        ->t('Display as inline element'),
      '#default_value' => $settings['inline'],
    ];
    foreach ([
      'first',
      'second',
    ] as $subfield) {
      $type = $field_settings['storage'][$subfield]['type'];
      $title = $subfield == 'first' ? $this
        ->t('First subfield') : $this
        ->t('Second subfield');
      $title .= ' - ' . $types[$type];
      $element[$subfield] = [
        '#type' => 'details',
        '#title' => $title,
        '#open' => FALSE,
      ];
      $element[$subfield]['type'] = [
        '#type' => 'select',
        '#title' => $this
          ->t('Widget'),
        '#default_value' => $settings[$subfield]['type'],
        '#required' => TRUE,
        '#options' => $this
          ->getSubwidgets($type, $field_settings[$subfield]['list']),
      ];
      $element[$subfield]['label_display'] = [
        '#type' => 'select',
        '#title' => $this
          ->t('Label display'),
        '#default_value' => $settings[$subfield]['label_display'],
        '#required' => TRUE,
        '#options' => [
          'block' => $this
            ->t('Block'),
          'inline' => $this
            ->t('Inline'),
          'invisible' => $this
            ->t('Invisible'),
          'hidden' => $this
            ->t('Hidden'),
        ],
        '#access' => self::isLabelSupported($settings[$subfield]['type']),
      ];
      $type_selector = "select[name='fields[{$field_name}][settings_edit_form][settings][{$subfield}][type]'";
      $element[$subfield]['size'] = [
        '#type' => 'number',
        '#title' => $this
          ->t('Size'),
        '#default_value' => $settings[$subfield]['size'],
        '#min' => 1,
        '#states' => [
          'visible' => [
            [
              $type_selector => [
                'value' => 'textfield',
              ],
            ],
            [
              $type_selector => [
                'value' => 'email',
              ],
            ],
            [
              $type_selector => [
                'value' => 'tel',
              ],
            ],
            [
              $type_selector => [
                'value' => 'url',
              ],
            ],
          ],
        ],
      ];
      $element[$subfield]['placeholder'] = [
        '#type' => 'textfield',
        '#title' => $this
          ->t('Placeholder'),
        '#default_value' => $settings[$subfield]['placeholder'],
        '#states' => [
          'visible' => [
            [
              $type_selector => [
                'value' => 'textfield',
              ],
            ],
            [
              $type_selector => [
                'value' => 'textarea',
              ],
            ],
            [
              $type_selector => [
                'value' => 'email',
              ],
            ],
            [
              $type_selector => [
                'value' => 'tel',
              ],
            ],
            [
              $type_selector => [
                'value' => 'url',
              ],
            ],
          ],
        ],
      ];
      $element[$subfield]['label'] = [
        '#type' => 'textfield',
        '#title' => $this
          ->t('Label'),
        '#default_value' => $settings[$subfield]['label'],
        '#required' => TRUE,
        '#states' => [
          'visible' => [
            $type_selector => [
              'value' => 'checkbox',
            ],
          ],
        ],
      ];
      $element[$subfield]['cols'] = [
        '#type' => 'number',
        '#title' => $this
          ->t('Columns'),
        '#default_value' => $settings[$subfield]['cols'],
        '#min' => 1,
        '#description' => $this
          ->t('How many columns wide the textarea should be'),
        '#states' => [
          'visible' => [
            $type_selector => [
              'value' => 'textarea',
            ],
          ],
        ],
      ];
      $element[$subfield]['rows'] = [
        '#type' => 'number',
        '#title' => $this
          ->t('Rows'),
        '#default_value' => $settings[$subfield]['rows'],
        '#min' => 1,
        '#description' => $this
          ->t('How many rows high the textarea should be.'),
        '#states' => [
          'visible' => [
            $type_selector => [
              'value' => 'textarea',
            ],
          ],
        ],
      ];
      $element[$subfield]['prefix'] = [
        '#type' => 'textfield',
        '#title' => $this
          ->t('Prefix (deprecated)'),
        '#default_value' => $settings[$subfield]['prefix'],
      ];
      $element[$subfield]['suffix'] = [
        '#type' => 'textfield',
        '#title' => $this
          ->t('Suffix (deprecated)'),
        '#default_value' => $settings[$subfield]['suffix'],
      ];
    }
    return $element;
  }

  /**
   * {@inheritdoc}
   */
  public function settingsSummary() {
    $settings = $this
      ->getSettings();
    $field_settings = $this
      ->getFieldSettings();
    $subfield_types = DoubleFieldItem::subfieldTypes();
    $summary = [];
    if ($settings['inline']) {
      $summary[] = $this
        ->t('Display as inline element');
    }
    foreach ([
      'first',
      'second',
    ] as $subfield) {
      $subfield_type = $subfield_types[$field_settings['storage'][$subfield]['type']];
      $summary[] = new FormattableMarkup('<b>@subfield - @subfield_type</b>', [
        '@subfield' => $subfield == 'first' ? $this
          ->t('First subfield') : $this
          ->t('Second subfield'),
        '@subfield_type' => strtolower($subfield_type),
      ]);
      $summary[] = $this
        ->t('Widget: @type', [
        '@type' => $settings[$subfield]['type'],
      ]);
      if (self::isLabelSupported($settings[$subfield]['type'])) {
        $summary[] = $this
          ->t('Label display: @label', [
          '@label' => $settings[$subfield]['label_display'],
        ]);
      }
      switch ($settings[$subfield]['type']) {
        case 'textfield':
        case 'email':
        case 'tel':
        case 'url':
          $summary[] = $this
            ->t('Size: @size', [
            '@size' => $settings[$subfield]['size'],
          ]);
          if ($settings[$subfield]['placeholder'] != '') {
            $summary[] = $this
              ->t('Placeholder: @placeholder', [
              '@placeholder' => $settings[$subfield]['placeholder'],
            ]);
          }
          break;
        case 'checkbox':
          $summary[] = $this
            ->t('Label: @label', [
            '@label' => $settings[$subfield]['label'],
          ]);
          break;
        case 'select':
          break;
        case 'textarea':
          $summary[] = $this
            ->t('Columns: @cols', [
            '@cols' => $settings[$subfield]['cols'],
          ]);
          $summary[] = $this
            ->t('Rows: @rows', [
            '@rows' => $settings[$subfield]['rows'],
          ]);
          if ($settings[$subfield]['placeholder'] != '') {
            $summary[] = $this
              ->t('Placeholder: @placeholder', [
              '@placeholder' => $settings[$subfield]['placeholder'],
            ]);
          }
          break;
      }
      if ($settings[$subfield]['prefix'] != '') {
        $summary[] = $this
          ->t('Prefix (deprecated): @prefix', [
          '@prefix' => $settings[$subfield]['prefix'],
        ]);
      }
      if ($settings[$subfield]['suffix'] != '') {
        $summary[] = $this
          ->t('Suffix (deprecated): @suffix', [
          '@suffix' => $settings[$subfield]['suffix'],
        ]);
      }
    }
    return $summary;
  }

  /**
   * {@inheritdoc}
   */
  public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state) {
    $field_settings = $this
      ->getFieldSettings();
    $settings = $this
      ->getSettings();
    $widget = [
      '#theme_wrappers' => [
        'container',
        'form_element',
      ],
      '#attributes' => [
        'class' => [
          'double-field-elements',
        ],
      ],
      '#attached' => [
        'library' => [
          'double_field/widget',
        ],
      ],
    ];
    if ($settings['inline']) {
      $widget['#attributes']['class'][] = 'double-field-widget-inline';
    }
    foreach ([
      'first',
      'second',
    ] as $subfield) {

      // @todo Remove this in 4.0.
      if ($settings[$subfield]['prefix']) {
        @trigger_error('Prefix widget setting is deprecated in double_field:8.x-3.4 and will be removed in double_field:8.x-4.0.', E_USER_DEPRECATED);
      }
      if ($settings[$subfield]['suffix']) {
        @trigger_error('Suffix widget setting is deprecated in double_field:8.x-3.4 and will be removed in double_field:8.x-4.0.', E_USER_DEPRECATED);
      }
      $widget[$subfield] = [
        '#type' => $settings[$subfield]['type'],
        '#prefix' => $settings[$subfield]['prefix'],
        '#suffix' => $settings[$subfield]['suffix'],
        '#default_value' => isset($items[$delta]->{$subfield}) ? $items[$delta]->{$subfield} : NULL,
        '#subfield_settings' => $settings[$subfield],
        '#wrapper_attributes' => [
          'class' => [
            'double-field-subfield-form-item',
          ],
        ],
      ];
      $label_display = $settings[$subfield]['label_display'];
      $label = $field_settings[$subfield]['label'];
      $widget_type = $settings[$subfield]['type'];
      if ($label_display != 'hidden' && self::isLabelSupported($widget_type)) {
        $widget[$subfield]['#title'] = $label;
        if ($label_display == 'invisible') {
          $widget[$subfield]['#title_display'] = 'invisible';
        }
        elseif ($label_display == 'inline') {
          $widget[$subfield]['#wrapper_attributes']['class'][] = 'container-inline';
        }
      }
      $storage_type = $field_settings['storage'][$subfield]['type'];
      switch ($widget_type) {
        case 'textfield':
        case 'email':
        case 'tel':
        case 'url':

          // Find out appropriate max length fot the element.
          $max_length_map = [
            'string' => $field_settings['storage'][$subfield]['maxlength'],
            'telephone' => $field_settings['storage'][$subfield]['maxlength'],
            'email' => Email::EMAIL_MAX_LENGTH,
            'uri' => 2048,
          ];
          if (isset($max_length_map[$storage_type])) {
            $widget[$subfield]['#maxlength'] = $max_length_map[$storage_type];
          }
          if ($settings[$subfield]['size']) {
            $widget[$subfield]['#size'] = $settings[$subfield]['size'];
          }
          if ($settings[$subfield]['placeholder']) {
            $widget[$subfield]['#placeholder'] = $settings[$subfield]['placeholder'];
          }
          break;
        case 'checkbox':
          $widget[$subfield]['#title'] = $settings[$subfield]['label'];
          break;
        case 'select':
          $label = $field_settings[$subfield]['required'] ? $this
            ->t('- Select a value -') : $this
            ->t('- None -');
          $widget[$subfield]['#options'] = [
            '' => $label,
          ];
          if ($field_settings[$subfield]['list']) {
            $widget[$subfield]['#options'] += $field_settings[$subfield]['allowed_values'];
          }
          break;
        case 'radios':
          $label = $field_settings[$subfield]['required'] ? $this
            ->t('N/A') : $this
            ->t('- None -');
          $widget[$subfield]['#options'] = [
            '' => $label,
          ];
          if ($field_settings[$subfield]['list']) {
            $widget[$subfield]['#options'] += $field_settings[$subfield]['allowed_values'];
          }
          break;
        case 'textarea':
          if ($settings[$subfield]['cols']) {
            $widget[$subfield]['#cols'] = $settings[$subfield]['cols'];
          }
          if ($settings[$subfield]['rows']) {
            $widget[$subfield]['#rows'] = $settings[$subfield]['rows'];
          }
          if ($settings[$subfield]['placeholder']) {
            $widget[$subfield]['#placeholder'] = $settings[$subfield]['placeholder'];
          }
          break;
        case 'number':
        case 'range':
          if (in_array($storage_type, [
            'integer',
            'float',
            'numeric',
          ])) {
            if ($field_settings[$subfield]['min']) {
              $widget[$subfield]['#min'] = $field_settings[$subfield]['min'];
            }
            if ($field_settings[$subfield]['max']) {
              $widget[$subfield]['#max'] = $field_settings[$subfield]['max'];
            }
            if ($storage_type == 'numeric') {
              $widget[$subfield]['#step'] = pow(0.1, $field_settings['storage'][$subfield]['scale']);
            }
            elseif ($storage_type == 'float') {
              $widget[$subfield]['#step'] = 'any';
            }
          }
          break;
        case 'datetime':
          $widget[$subfield]['#default_value'] = $items[$delta]
            ->createDate($subfield);
          if ($field_settings['storage'][$subfield]['datetime_type'] == 'date') {
            $widget[$subfield]['#date_time_element'] = 'none';
            $widget[$subfield]['#date_time_format'] = '';
          }
          else {
            if ($widget[$subfield]['#default_value']) {
              $widget[$subfield]['#default_value']
                ->setTimezone(new \DateTimezone(date_default_timezone_get()));
            }

            // Ensure that the datetime field processing doesn't set its own
            // time zone here.
            $widget[$subfield]['#date_timezone'] = date_default_timezone_get();
          }
          break;
      }
    }
    return $element + $widget;
  }

  /**
   * {@inheritdoc}
   */
  public function massageFormValues(array $values, array $form, FormStateInterface $form_state) {
    $storage_settings = $this
      ->getFieldSetting('storage');
    foreach ($values as $delta => $value) {
      foreach ([
        'first',
        'second',
      ] as $subfield) {
        if ($value[$subfield] === '') {
          $values[$delta][$subfield] = NULL;
        }
        elseif ($value[$subfield] instanceof DrupalDateTime) {
          $date = $value[$subfield];
          $storage_format = $storage_settings[$subfield]['datetime_type'] == 'datetime' ? DoubleFieldItem::DATETIME_DATETIME_STORAGE_FORMAT : DoubleFieldItem::DATETIME_DATE_STORAGE_FORMAT;

          // Before it can be saved, the time entered by the user must be
          // converted to the storage time zone.
          $storage_timezone = new \DateTimezone(DoubleFieldItem::DATETIME_STORAGE_TIMEZONE);
          $values[$delta][$subfield] = $date
            ->setTimezone($storage_timezone)
            ->format($storage_format);
        }
      }
    }
    return $values;
  }

  /**
   * Returns available subwidgets.
   */
  protected function getSubwidgets($subfield_type, $list) {
    $subwidgets = [];
    if ($list) {
      $subwidgets['select'] = $this
        ->t('Select list');
      $subwidgets['radios'] = $this
        ->t('Radio buttons');
    }
    switch ($subfield_type) {
      case 'boolean':
        $subwidgets['checkbox'] = $this
          ->t('Checkbox');
        break;
      case 'string':
        $subwidgets['textfield'] = $this
          ->t('Textfield');
        $subwidgets['email'] = $this
          ->t('Email');
        $subwidgets['tel'] = $this
          ->t('Telephone');
        $subwidgets['url'] = $this
          ->t('Url');
        $subwidgets['color'] = $this
          ->t('Color');
        break;
      case 'email':
        $subwidgets['email'] = $this
          ->t('Email');
        $subwidgets['textfield'] = $this
          ->t('Textfield');
        break;
      case 'telephone':
        $subwidgets['tel'] = $this
          ->t('Telephone');
        $subwidgets['textfield'] = $this
          ->t('Textfield');
        break;
      case 'uri':
        $subwidgets['url'] = $this
          ->t('Url');
        $subwidgets['textfield'] = $this
          ->t('Textfield');
        break;
      case 'text':
        $subwidgets['textarea'] = $this
          ->t('Text area');
        break;
      case 'integer':
      case 'float':
      case 'numeric':
        $subwidgets['number'] = $this
          ->t('Number');
        $subwidgets['textfield'] = $this
          ->t('Textfield');
        $subwidgets['range'] = $this
          ->t('Range');
        break;
      case 'datetime_iso8601':
        $subwidgets['datetime'] = $this
          ->t('Date');
        break;
    }
    return $subwidgets;
  }

  /**
   * {@inheritdoc}
   */
  public function errorElement(array $element, ConstraintViolationInterface $violation, array $form, FormStateInterface $form_state) {
    return isset($violation->arrayPropertyPath[0]) ? $element[$violation->arrayPropertyPath[0]] : $element;
  }

  /**
   * {@inheritdoc}
   */
  protected function getFieldSettings() {
    $field_settings = parent::getFieldSettings();
    foreach ([
      'first',
      'second',
    ] as $subfield) {
      $subfield_type = $field_settings['storage'][$subfield]['type'];
      if ($field_settings[$subfield]['list'] && !DoubleFieldItem::isListAllowed($subfield_type)) {
        $field_settings[$subfield]['list'] = FALSE;
      }

      // BC Layer. The settings below may not be set if site was updated from
      // version below 3.3.
      // @todo Remove this in 4.0.
      if (!isset($field_settings[$subfield]['label'])) {
        $field_settings[$subfield]['label'] = '';
      }
    }
    return $field_settings;
  }

  /**
   * {@inheritdoc}
   */
  public function getSettings() {
    $settings = parent::getSettings();
    $field_settings = $this
      ->getFieldSettings();
    foreach ([
      'first',
      'second',
    ] as $subfield) {
      $widget_types = $this
        ->getSubwidgets($field_settings['storage'][$subfield]['type'], $field_settings[$subfield]['list']);
      if (!$settings[$subfield]['type']) {
        $settings[$subfield]['type'] = key($widget_types);
      }
      elseif (!array_key_exists($settings[$subfield]['type'], $widget_types)) {
        $settings[$subfield]['type'] = key($widget_types);
      }

      // BC Layer. The settings below may not be set if site was updated from
      // version below 3.4.
      // @todo Remove this in 4.0.
      if (!isset($settings[$subfield]['label_display'])) {
        $settings[$subfield]['label_display'] = 'hidden';
      }
    }
    return $settings;
  }

  /**
   * Determines whether or not widget can render subfield label.
   */
  private static function isLabelSupported($widget_type) {
    return $widget_type != 'checkbox' && $widget_type != 'datetime';
  }

}

Members

Namesort descending Modifiers Type Description Overrides
AllowedTagsXssTrait::allowedTags public function Returns a list of tags allowed by AllowedTagsXssTrait::fieldFilterXss().
AllowedTagsXssTrait::displayAllowedTags public function Returns a human-readable list of allowed tags for display in help texts.
AllowedTagsXssTrait::fieldFilterXss public function Filters an HTML string to prevent XSS vulnerabilities.
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
DoubleField::defaultSettings public static function Defines the default settings for this plugin. Overrides PluginSettingsBase::defaultSettings
DoubleField::errorElement public function Assigns a field-level validation error to the right widget sub-element. Overrides WidgetBase::errorElement
DoubleField::formElement public function Returns the form for a single field widget. Overrides WidgetInterface::formElement
DoubleField::getFieldSettings protected function Returns the array of field settings. Overrides WidgetBase::getFieldSettings
DoubleField::getSettings public function Returns the array of settings, including defaults for missing settings. Overrides PluginSettingsBase::getSettings
DoubleField::getSubwidgets protected function Returns available subwidgets.
DoubleField::isLabelSupported private static function Determines whether or not widget can render subfield label.
DoubleField::massageFormValues public function Massages the form values into the format expected for field values. Overrides WidgetBase::massageFormValues
DoubleField::settingsForm public function Returns a form to configure settings for the widget. Overrides WidgetBase::settingsForm
DoubleField::settingsSummary public function Returns a short summary for the current widget settings. Overrides WidgetBase::settingsSummary
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.
PluginSettingsBase::$defaultSettingsMerged protected property Whether default settings have been merged into the current $settings.
PluginSettingsBase::$thirdPartySettings protected property The plugin settings injected by third party modules.
PluginSettingsBase::calculateDependencies public function Calculates dependencies for the configured plugin. Overrides DependentPluginInterface::calculateDependencies 6
PluginSettingsBase::getSetting public function Returns the value of a setting, or its default value if absent. Overrides PluginSettingsInterface::getSetting
PluginSettingsBase::getThirdPartyProviders public function Gets the list of third parties that store information. Overrides ThirdPartySettingsInterface::getThirdPartyProviders
PluginSettingsBase::getThirdPartySetting public function Gets the value of a third-party setting. Overrides ThirdPartySettingsInterface::getThirdPartySetting
PluginSettingsBase::getThirdPartySettings public function Gets all third-party settings of a given module. Overrides ThirdPartySettingsInterface::getThirdPartySettings
PluginSettingsBase::mergeDefaults protected function Merges default settings values into $settings.
PluginSettingsBase::onDependencyRemoval public function Informs the plugin that some configuration it depends on will be deleted. Overrides PluginSettingsInterface::onDependencyRemoval 3
PluginSettingsBase::setSetting public function Sets the value of a setting for the plugin. Overrides PluginSettingsInterface::setSetting
PluginSettingsBase::setSettings public function Sets the settings for the plugin. Overrides PluginSettingsInterface::setSettings
PluginSettingsBase::setThirdPartySetting public function Sets the value of a third-party setting. Overrides ThirdPartySettingsInterface::setThirdPartySetting
PluginSettingsBase::unsetThirdPartySetting public function Unsets a third-party setting. Overrides ThirdPartySettingsInterface::unsetThirdPartySetting
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.
WidgetBase::$fieldDefinition protected property The field definition.
WidgetBase::$settings protected property The widget settings. Overrides PluginSettingsBase::$settings
WidgetBase::addMoreAjax public static function Ajax callback for the "Add another item" button.
WidgetBase::addMoreSubmit public static function Submission handler for the "Add another item" button.
WidgetBase::afterBuild public static function After-build handler for field elements in a form.
WidgetBase::create public static function Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface::create 5
WidgetBase::extractFormValues public function Extracts field values from submitted form values. Overrides WidgetBaseInterface::extractFormValues 2
WidgetBase::flagErrors public function Reports field-level validation errors against actual form elements. Overrides WidgetBaseInterface::flagErrors 2
WidgetBase::form public function Creates a form element for a field. Overrides WidgetBaseInterface::form 3
WidgetBase::formMultipleElements protected function Special handling to create form elements for multiple values. 1
WidgetBase::formSingleElement protected function Generates the form element for a single copy of the widget.
WidgetBase::getFieldSetting protected function Returns the value of a field setting.
WidgetBase::getFilteredDescription protected function Returns the filtered field description.
WidgetBase::getWidgetState public static function Retrieves processing information about the widget from $form_state. Overrides WidgetBaseInterface::getWidgetState
WidgetBase::getWidgetStateParents protected static function Returns the location of processing information within $form_state.
WidgetBase::handlesMultipleValues protected function Returns whether the widget handles multiple values.
WidgetBase::isApplicable public static function Returns if the widget can be used for the provided field. Overrides WidgetInterface::isApplicable 4
WidgetBase::isDefaultValueWidget protected function Returns whether the widget used for default value form.
WidgetBase::setWidgetState public static function Stores processing information about the widget in $form_state. Overrides WidgetBaseInterface::setWidgetState
WidgetBase::__construct public function Constructs a WidgetBase object. Overrides PluginBase::__construct 5