You are here

public function SearchApiFederatedSolrField::configurationForm in Search API Federated Solr 7

Same name and namespace in other branches
  1. 7.3 src/SearchApiFederatedSolrField.php \SearchApiFederatedSolrField::configurationForm()
  2. 7.2 src/SearchApiFederatedSolrField.php \SearchApiFederatedSolrField::configurationForm()

Implements SearchApiAlterCallbackInterface::configurationForm().

Overrides SearchApiAbstractAlterCallback::configurationForm

File

src/SearchApiFederatedSolrField.php, line 42

Class

SearchApiFederatedSolrField

Code

public function configurationForm() {
  $form['fields'] = [
    '#type' => 'container',
    '#prefix' => '<div id="search-api-federated-solr-add-field-settings">',
    '#suffix' => '</div>',
  ];
  foreach ($this->options['fields'] as $key => $field) {
    $item = [
      '#type' => 'fieldset',
      '#title' => !isset($field['is_new']) ? t("@label (%machine_name)", [
        '@label' => $field['label'],
        '%machine_name' => $field['machine_name'],
      ]) : t('New field'),
      '#collapsible' => TRUE,
      '#collapsed' => !isset($field['is_new']),
    ];
    $item['label'] = [
      '#type' => 'textfield',
      '#title' => t('Label'),
      '#default_value' => $field['label'],
      '#maxlength' => 255,
    ];
    $item['machine_name'] = [
      '#type' => 'textfield',
      '#title' => t('Machine Name'),
      '#required' => TRUE,
      '#default_value' => $field['machine_name'],
      '#maxlength' => 32,
    ];
    $item['type'] = [
      '#type' => 'select',
      '#title' => t('Data type'),
      '#options' => search_api_default_field_types(),
      '#default_value' => TRUE === isset($field['type']) ? $field['type'] : 'string',
      '#required' => TRUE,
      '#description' => t('Data type to save field as'),
    ];
    $item['bundle'] = [
      '#type' => 'fieldset',
      '#title' => t('Value to index for each type'),
      '#description' => t('Enter a token or plain text in the field for each type of indexed item.'),
      '#collapsible' => TRUE,
    ];
    $entity_info = entity_get_info($this->index
      ->getEntityType());
    foreach ($entity_info['bundles'] as $bundle => $bundle_info) {
      $item['bundle'][$bundle] = [
        '#type' => 'textfield',
        '#title' => t('@label (%machine_name)', [
          '@label' => $bundle_info['label'],
          '%machine_name' => $bundle,
        ]),
        '#default_value' => $field['bundle'][$bundle],
      ];
    }
    $item['actions'] = array(
      '#type' => 'actions',
      'remove' => array(
        '#type' => 'submit',
        '#value' => t('Remove field'),
        '#submit' => array(
          '_search_api_federated_solr_add_field_submit',
        ),
        '#limit_validation_errors' => array(),
        '#name' => '_search_api_federated_solr_remove_' . $key,
        '#ajax' => array(
          'callback' => '_search_api_federated_solr_add_field_ajax',
          'wrapper' => 'search-api-federated-solr-add-field-settings',
        ),
      ),
    );
    $form['fields'][$key] = $item;
  }
  $form['tokens'] = [
    '#type' => 'fieldset',
    '#title' => t('Tokens'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  ];
  $form['tokens']['tokens'] = [
    '#theme' => 'token_tree',
    '#token_types' => [
      $this->index
        ->getEntityType(),
    ],
    '#global_types' => FALSE,
    '#recursion_limit' => 2,
  ];
  $form['actions']['#type'] = 'actions';
  $form['actions']['add_field_federated'] = array(
    '#type' => 'submit',
    '#value' => t('Add new federated field'),
    '#submit' => array(
      '_search_api_federated_solr_add_field_submit',
    ),
    '#limit_validation_errors' => array(),
    '#ajax' => array(
      'callback' => '_search_api_federated_solr_add_field_ajax',
      'wrapper' => 'search-api-federated-solr-add-field-settings',
    ),
  );
  return $form;
}