You are here

protected function WebformCompositeBase::defineDefaultProperties in Webform 8.5

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

Define an element's default properties.

Return value

array An associative array contain an the element's default properties.

Overrides WebformElementBase::defineDefaultProperties

3 calls to WebformCompositeBase::defineDefaultProperties()
WebformCustomComposite::defineDefaultProperties in src/Plugin/WebformElement/WebformCustomComposite.php
Define an element's default properties.
WebformLink::defineDefaultProperties in src/Plugin/WebformElement/WebformLink.php
Define an element's default properties.
WebformTelephone::defineDefaultProperties in src/Plugin/WebformElement/WebformTelephone.php
Define an element's default properties.
5 methods override WebformCompositeBase::defineDefaultProperties()
Address::defineDefaultProperties in src/Plugin/WebformElement/Address.php
Define an element's default properties.
WebformCustomComposite::defineDefaultProperties in src/Plugin/WebformElement/WebformCustomComposite.php
Define an element's default properties.
WebformLink::defineDefaultProperties in src/Plugin/WebformElement/WebformLink.php
Define an element's default properties.
WebformLocationBase::defineDefaultProperties in src/Plugin/WebformElement/WebformLocationBase.php
Define an element's default properties.
WebformTelephone::defineDefaultProperties in src/Plugin/WebformElement/WebformTelephone.php
Define an element's default properties.

File

src/Plugin/WebformElement/WebformCompositeBase.php, line 42

Class

WebformCompositeBase
Provides a base for composite elements.

Namespace

Drupal\webform\Plugin\WebformElement

Code

protected function defineDefaultProperties() {
  $properties = [
    'default_value' => [],
    'title_display' => 'invisible',
    'disabled' => FALSE,
    'flexbox' => '',
    // Enhancements.
    'select2' => FALSE,
    'choices' => FALSE,
    'chosen' => FALSE,
    // Wrapper.
    'wrapper_type' => 'fieldset',
  ] + parent::defineDefaultProperties() + $this
    ->defineDefaultMultipleProperties();
  unset($properties['required_error']);
  $composite_elements = $this
    ->getCompositeElements();
  foreach ($composite_elements as $composite_key => $composite_element) {

    // Get #type, #title, and #option from composite elements.
    foreach ($composite_element as $composite_property_key => $composite_property_value) {
      if (in_array($composite_property_key, [
        '#type',
        '#title',
        '#options',
      ])) {
        $property_key = str_replace('#', $composite_key . '__', $composite_property_key);
        if ($composite_property_value instanceof TranslatableMarkup) {
          $properties[$property_key] = (string) $composite_property_value;
        }
        else {
          $properties[$property_key] = $composite_property_value;
        }
      }
    }
    if (isset($properties[$composite_key . '__type'])) {
      $properties[$composite_key . '__title_display'] = '';
      $properties[$composite_key . '__description'] = '';
      $properties[$composite_key . '__help'] = '';
      $properties[$composite_key . '__required'] = FALSE;
      $properties[$composite_key . '__placeholder'] = '';
    }
    $properties[$composite_key . '__access'] = TRUE;
  }
  return $properties;
}