You are here

public static function GeofieldElementBase::elementProcess in Geofield 8

Generates a Geofield generic component based form element.

Parameters

array $element: An associative array containing the properties and children of the element. Note that $element must be taken by reference here, so processed child elements are taken over into $form_state.

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

array $complete_form: The complete form structure.

Return value

array The processed element.

1 call to GeofieldElementBase::elementProcess()
GeofieldLatLon::latlonProcess in src/Element/GeofieldLatLon.php
Generates the Geofield Lat Lon form element.

File

src/Element/GeofieldElementBase.php, line 38

Class

GeofieldElementBase
Provides a base class for Geofield Form elements.

Namespace

Drupal\geofield\Element

Code

public static function elementProcess(array &$element, FormStateInterface $form_state, array &$complete_form) {
  $element['#tree'] = TRUE;
  $element['#input'] = TRUE;
  foreach (static::getComponents() as $name => $component) {
    $element[$name] = [
      '#type' => 'textfield',
      '#title' => $component['title'],
      '#required' => !empty($element['#required']) ? $element['#required'] : FALSE,
      '#default_value' => isset($element['#default_value'][$name]) ? $element['#default_value'][$name] : '',
      '#attributes' => [
        'class' => [
          'geofield-' . $name,
        ],
      ],
    ];
  }
  unset($element['#value']);

  // Set this to false always to prevent notices.
  $element['#required'] = FALSE;
  return $element;
}