You are here

public static function WebformLocationBase::processWebformComposite in Webform 6.x

Same name and namespace in other branches
  1. 8.5 src/Element/WebformLocationBase.php \Drupal\webform\Element\WebformLocationBase::processWebformComposite()

Processes a composite webform element.

Overrides WebformCompositeBase::processWebformComposite

2 calls to WebformLocationBase::processWebformComposite()
WebformLocationGeocomplete::processWebformComposite in modules/webform_location_geocomplete/src/Element/WebformLocationGeocomplete.php
Processes a composite webform element.
WebformLocationPlaces::processWebformComposite in src/Element/WebformLocationPlaces.php
Processes a composite webform element.
2 methods override WebformLocationBase::processWebformComposite()
WebformLocationGeocomplete::processWebformComposite in modules/webform_location_geocomplete/src/Element/WebformLocationGeocomplete.php
Processes a composite webform element.
WebformLocationPlaces::processWebformComposite in src/Element/WebformLocationPlaces.php
Processes a composite webform element.

File

src/Element/WebformLocationBase.php, line 88

Class

WebformLocationBase
Provides a webform base element for a location element.

Namespace

Drupal\webform\Element

Code

public static function processWebformComposite(&$element, FormStateInterface $form_state, &$complete_form) {
  $element = parent::processWebformComposite($element, $form_state, $complete_form);

  // Composite elements should always be displayed and rendered so that
  // location data can be populated, so #access is really just converting the
  // readonly elements to hidden elements.
  $composite_elements = static::getCompositeElements($element);
  foreach ($composite_elements as $composite_key => $composite_element) {
    if ($composite_key !== 'value') {
      if (!Element::isVisibleElement($element[$composite_key])) {
        unset($element[$composite_key]['#access']);
        unset($element[$composite_key]['#pre_render']);
        $element[$composite_key]['#type'] = 'hidden';
      }
      elseif (!empty($element['#hidden']) && !empty($element['#geolocation'])) {
        unset($element[$composite_key]['#pre_render']);
        $element[$composite_key]['#type'] = 'hidden';
      }
      else {
        $element[$composite_key]['#wrapper_attributes']['class'][] = 'webform-readonly';
        $element[$composite_key]['#readonly'] = 'readonly';
      }
    }
  }

  // Get shared properties.
  $shared_properties = [
    '#required',
    '#placeholder',
  ];
  $element['value'] += array_intersect_key($element, array_combine($shared_properties, $shared_properties));

  // Set Geolocation detection attribute.
  if (!empty($element['#geolocation'])) {
    $element['value']['#attributes']['data-webform-location-' . static::$name . '-geolocation'] = 'data-webform-location-' . static::$name . '-geolocation';
  }

  // Set Map attribute.
  if (!empty($element['#map']) && empty($element['#hidden'])) {
    $element['value']['#attributes']['data-webform-location-' . static::$name . '-map'] = 'data-webform-location-' . static::$name . '-map';
  }
  $element += [
    '#element_validate' => [],
  ];
  array_unshift($element['#element_validate'], [
    get_called_class(),
    'validateWebformLocation',
  ]);
  return $element;
}