You are here

public function WebformElementBase::getConfigurationFormProperties in Webform 8.5

Same name and namespace in other branches
  1. 6.x src/Plugin/WebformElementBase.php \Drupal\webform\Plugin\WebformElementBase::getConfigurationFormProperties()

Get an associative array of element properties from configuration webform.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Return value

array An associative array of element properties.

Overrides WebformElementInterface::getConfigurationFormProperties

7 calls to WebformElementBase::getConfigurationFormProperties()
DateBase::validateConfigurationForm in src/Plugin/WebformElement/DateBase.php
Form validation handler.
DateTime::getConfigurationFormProperties in src/Plugin/WebformElement/DateTime.php
Get an associative array of element properties from configuration webform.
TextBase::validateConfigurationForm in src/Plugin/WebformElement/TextBase.php
Form validation handler.
View::validateConfigurationForm in src/Plugin/WebformElement/View.php
Form validation handler.
WebformCompositeBase::getConfigurationFormProperties in src/Plugin/WebformElement/WebformCompositeBase.php
Get an associative array of element properties from configuration webform.

... See full list

3 methods override WebformElementBase::getConfigurationFormProperties()
DateTime::getConfigurationFormProperties in src/Plugin/WebformElement/DateTime.php
Get an associative array of element properties from configuration webform.
WebformCompositeBase::getConfigurationFormProperties in src/Plugin/WebformElement/WebformCompositeBase.php
Get an associative array of element properties from configuration webform.
WebformTableRow::getConfigurationFormProperties in src/Plugin/WebformElement/WebformTableRow.php
Get an associative array of element properties from configuration webform.

File

src/Plugin/WebformElementBase.php, line 3702

Class

WebformElementBase
Provides a base class for a webform element.

Namespace

Drupal\webform\Plugin

Code

public function getConfigurationFormProperties(array &$form, FormStateInterface $form_state) {
  $element_properties = $form_state
    ->getValues();

  // Get default properties so that they can be unset below.
  $default_properties = $form_state
    ->get('default_properties');

  // Get custom properties.
  if (isset($element_properties['custom'])) {
    if (is_array($element_properties['custom'])) {
      $element_properties += $element_properties['custom'];
    }
    unset($element_properties['custom']);
  }

  // Remove all hash prefixes so that we can filter out any default
  // properties.
  WebformArrayHelper::removePrefix($element_properties);

  // Build a temp element used to see if multiple value and/or composite
  // elements need to be supported.
  $element = WebformArrayHelper::addPrefix($element_properties);
  foreach ($element_properties as $property_name => $property_value) {
    if (!array_key_exists($property_name, $default_properties)) {
      continue;
    }
    $this
      ->getConfigurationFormProperty($element_properties, $property_name, $property_value, $element);

    // Unset element property that matched the default property.
    switch ($property_name) {
      case 'multiple':

        // The #multiple property element is converted to the correct datatype
        // so we are looking for 'strict equality' (===).
        // This prevents #multiple: 2 from being interpeted as TRUE.
        // @see \Drupal\webform\Element\WebformElementMultiple::validateWebformElementMultiple
        // @see \Drupal\webform\Plugin\WebformElement\Checkboxes::defaultProperties
        if ($default_properties[$property_name] === $element_properties[$property_name]) {
          unset($element_properties[$property_name]);
        }
        break;
      default:

        // Most elements properties are strings or numbers and we need to use
        // 'type-converting equality' (==) because all numbers are posted
        // back to the server as strings.
        if ($default_properties[$property_name] == $element_properties[$property_name]) {
          unset($element_properties[$property_name]);
        }

        // Cast data types (except #multiple).
        if (isset($element_properties[$property_name])) {
          if (is_bool($default_properties[$property_name])) {
            $element_properties[$property_name] = (bool) $element_properties[$property_name];
          }
          elseif (is_null($default_properties[$property_name]) || is_numeric($default_properties[$property_name])) {
            $value = $element_properties[$property_name];
            $cast_value = $value == (int) $value ? (int) $value : (double) $value;
            if ($value == $cast_value) {
              $element_properties[$property_name] = $cast_value;
            }
          }
        }
        break;
    }
  }

  // Make sure #type is always first.
  if (isset($element_properties['type'])) {
    $element_properties = [
      'type' => $element_properties['type'],
    ] + $element_properties;
  }
  return WebformArrayHelper::addPrefix($element_properties);
}