You are here

public function LocationInputPluginBase::buildConfigurationForm in Search API Location 8

Form constructor.

Plugin forms are embedded in other forms. In order to know where the plugin form is located in the parent form, #parents and #array_parents must be known, but these are not available during the initial build phase. In order to have these properties available when building the plugin form's elements, let this method return a form element that has a #process callback and build the rest of the form in the callback. By the time the callback is executed, the element's #parents and #array_parents properties will have been set by the form API. For more documentation on #parents and #array_parents, see \Drupal\Core\Render\Element\FormElement.

Parameters

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

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form. Calling code should pass on a subform state created through \Drupal\Core\Form\SubformState::createForSubform().

Return value

array The form structure.

Overrides PluginFormInterface::buildConfigurationForm

1 call to LocationInputPluginBase::buildConfigurationForm()
Geocode::buildConfigurationForm in modules/search_api_location_geocoder/src/Plugin/search_api_location/location_input/Geocode.php
Form constructor.
2 methods override LocationInputPluginBase::buildConfigurationForm()
Geocode::buildConfigurationForm in modules/search_api_location_geocoder/src/Plugin/search_api_location/location_input/Geocode.php
Form constructor.
Map::buildConfigurationForm in src/Plugin/search_api_location/location_input/Map.php
Form constructor.

File

src/LocationInput/LocationInputPluginBase.php, line 43

Class

LocationInputPluginBase
Defines a base class from which other data type classes may extend.

Namespace

Drupal\search_api_location\LocationInput

Code

public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
  $form['radius_type'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Type of distance input'),
    '#description' => $this
      ->t('Select the type of input element for the distance option.'),
    '#options' => [
      'select' => $this
        ->t('Select'),
      'textfield' => $this
        ->t('Text field'),
    ],
    '#default_value' => $this->configuration['radius_type'],
  ];
  $form['radius_options'] = [
    '#type' => 'textarea',
    '#title' => $this
      ->t('Distance options'),
    '#description' => $this
      ->t('Add one line per option for “Range” you want to provide. The first part of each line is the distance in kilometres, everything after the first space is the label. "-" as the distance ignores the location for filtering, but will still use it for facets, sorts and distance calculation. Skipping the distance altogether (i.e., starting the line with a space) will provide an option for ignoring the entered location completely.'),
    '#default_value' => $this->configuration['radius_options'],
    '#states' => [
      'visible' => [
        'select[name="options[plugin-' . $this->pluginId . '][radius_type]"]' => [
          'value' => 'select',
        ],
      ],
    ],
  ];
  $form['radius_units'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Distance units'),
    '#description' => $this
      ->t('Choose the units for the distance.'),
    '#default_value' => $this->configuration['radius_units'],
    '#options' => array_column(search_api_location_get_units(), 'label', 'id'),
    '#states' => [
      'visible' => [
        'select[name="options[plugin-' . $this->pluginId . '][radius_type]"]' => [
          'value' => 'textfield',
        ],
      ],
    ],
  ];
  return $form;
}