You are here

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

Fills the array build by buildDefaultFieldValues().

Parameters

array $fields: An array of fields, filled with data from the index.

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

File

src/Form/ManageSortFieldsForm.php, line 315

Class

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

Namespace

Drupal\search_api_sorts_widget\Form

Code

private function fillSearchApiSortsFieldsValues(array &$fields) {
  $search_api_sorts_fields = $this->searchApiSortsFieldStorage
    ->loadByProperties([
    'display_id' => $this
      ->getEscapedConfigId($this->display
      ->getPluginId()),
  ]);
  foreach ($search_api_sorts_fields as $search_api_sorts_field) {
    if (isset($fields[$search_api_sorts_field
      ->getFieldIdentifier()])) {
      $fields[$search_api_sorts_field
        ->getFieldIdentifier()]['status'] = $search_api_sorts_field
        ->getStatus();
      $fields[$search_api_sorts_field
        ->getFieldIdentifier()]['default_sort'] = $search_api_sorts_field
        ->getDefaultSort();
      $fields[$search_api_sorts_field
        ->getFieldIdentifier()]['default_order'] = $search_api_sorts_field
        ->getDefaultOrder();
      $fields[$search_api_sorts_field
        ->getFieldIdentifier()]['label'] = $search_api_sorts_field
        ->getLabel();
      $fields[$search_api_sorts_field
        ->getFieldIdentifier()]['weight'] = $search_api_sorts_field
        ->getWeight();
    }
  }

  // Sort the fields by the weight element.
  uasort($fields, [
    'Drupal\\Component\\Utility\\SortArray',
    'sortByWeightElement',
  ]);
}