You are here

private function ManageSortFieldsForm::buildSearchApiSortsFieldsDefaultValues in Search API Sorts Widget 1.x

An array of sortable fields with default values.

Return value

array An array of fields.

1 call to ManageSortFieldsForm::buildSearchApiSortsFieldsDefaultValues()
ManageSortFieldsForm::getSearchApiSortsFieldsValues in src/Form/ManageSortFieldsForm.php
Returns an array of all saved search api sorts fields.

File

src/Form/ManageSortFieldsForm.php, line 275

Class

ManageSortFieldsForm
Provides a form for managing sort fields for a search api display.

Namespace

Drupal\search_api_sorts_widget\Form

Code

private function buildSearchApiSortsFieldsDefaultValues() {

  // Add our dummy relevance field.
  $fields = [
    'search_api_relevance' => [
      'status' => FALSE,
      'default_sort' => FALSE,
      'default_order' => 'desc',
      'field' => 'Relevance',
      'type' => 'decimal',
      'label' => $this
        ->t('Relevance'),
      'weight' => 0,
    ],
  ];
  foreach ($this->index
    ->getFields() as $field) {

    // Skip fulltext or multi-value, you cannot sort them.
    if ($field
      ->getType() == 'text' || strpos($field
      ->getType(), 'list<') !== FALSE) {
      continue;
    }
    $fields[$field
      ->getFieldIdentifier()] = [
      'status' => FALSE,
      'default_sort' => FALSE,
      'default_order' => 'asc',
      'field' => $field
        ->getLabel(),
      'type' => $field
        ->getType(),
      'label' => $field
        ->getLabel(),
      'weight' => 0,
    ];
  }
  return $fields;
}