You are here

protected function ViewsTest::submitFieldsForm in Search API 8

Submits the field handler config form currently displayed.

Return value

string|null The field ID of the field whose form was submitted. Or NULL if the current page is no field form.

1 call to ViewsTest::submitFieldsForm()
ViewsTest::testViewsAdmin in tests/src/Functional/ViewsTest.php
Tests the Views admin UI and field handlers.

File

tests/src/Functional/ViewsTest.php, line 1010

Class

ViewsTest
Tests the Views integration of the Search API.

Namespace

Drupal\Tests\search_api\Functional

Code

protected function submitFieldsForm() {
  $url_parts = explode('/', $this
    ->getUrl());
  $field = array_pop($url_parts);
  if (array_pop($url_parts) != 'field') {
    return NULL;
  }
  $non_entity_fields = [
    'search_api_datasource',
    'rendered_item',
    'search_api_rendered_item',
  ];

  // The "Fallback options" are only available for fields based on the Field
  // API.
  if (!in_array($field, $non_entity_fields, TRUE)) {
    $edit['options[fallback_options][multi_separator]'] = '|';
  }
  $edit['options[alter][alter_text]'] = TRUE;
  $edit['options[alter][text]'] = "#{{counter}} [{$field}] {{ {$field} }}";
  $edit['options[empty]'] = "#{{counter}} [{$field}] [EMPTY]";
  switch ($field) {
    case 'counter':
      $edit = [
        'options[exclude]' => TRUE,
      ];
      break;
    case 'id':
      $edit['options[field_rendering]'] = FALSE;
      break;
    case 'search_api_datasource':
      break;
    case 'body':
      break;
    case 'category':
      break;
    case 'keywords':
      $edit['options[field_rendering]'] = FALSE;
      break;
    case 'user_id':
      $edit['options[field_rendering]'] = FALSE;
      $edit['options[fallback_options][display_methods][user][display_method]'] = 'id';
      break;
    case 'author':
      break;
    case 'roles':
      $edit['options[field_rendering]'] = FALSE;
      $edit['options[fallback_options][display_methods][user_role][display_method]'] = 'id';
      break;
    case 'rendered_item':
      break;
    case 'search_api_rendered_item':
      $edit['options[view_modes][entity:entity_test_mulrev_changed][article]'] = 'teaser';
      $edit['options[view_modes][entity:entity_test_mulrev_changed][item]'] = 'teaser';
      break;
  }
  $this
    ->submitPluginForm($edit);
  return $field;
}