You are here

public function EntityArgument::buildOptionsForm in Geolocation Field 8.3

Same name and namespace in other branches
  1. 8.2 src/Plugin/views/argument/EntityArgument.php \Drupal\geolocation\Plugin\views\argument\EntityArgument::buildOptionsForm()

Provide a form to edit options for this plugin.

Overrides ProximityArgument::buildOptionsForm

File

src/Plugin/views/argument/EntityArgument.php, line 81

Class

EntityArgument
Argument handler for geolocation.

Namespace

Drupal\geolocation\Plugin\views\argument

Code

public function buildOptionsForm(&$form, FormStateInterface $form_state) {
  parent::buildOptionsForm($form, $form_state);
  $bundle_info = \Drupal::service("entity_type.bundle.info")
    ->getAllBundleInfo();
  unset($form['description']);
  $options = [];
  foreach ($this->entityFieldManager
    ->getFieldMapByFieldType('geolocation') as $entity_type => $fields) {
    $entity_type_definition = $this->entityTypeManager
      ->getDefinition($entity_type);
    foreach ($fields as $field_name => $field) {
      foreach ($field['bundles'] as $bundle) {
        $bundle_label = empty($bundle_info[$entity_type][$bundle]['label']) ? $entity_type_definition
          ->getBundleLabel() : $bundle_info[$entity_type][$bundle]['label'];
        $field_definitions = $this->entityFieldManager
          ->getFieldDefinitions($entity_type, $bundle);
        $options[$entity_type . ':' . $bundle . ':' . $field_name] = $entity_type_definition
          ->getLabel() . ' - ' . $bundle_label . ' - ' . $field_definitions[$field_name]
          ->getLabel();
      }
    }
  }
  $form['geolocation_entity_argument_source'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Geolocation Entity Argument Source'),
    '#options' => $options,
    '#weight' => -10,
    '#default_value' => $this->options['geolocation_entity_argument_source'],
    '#description' => $this
      ->t('Format should be in the following format: <strong>"654<=5mi"</strong> (defaults to km). Alternatively, just a valid entity ID, for use as reference location in other fields.'),
  ];
}