You are here

protected function SolrDocument::getFieldValue in Search API Solr 4.x

Same name and namespace in other branches
  1. 8.3 src/Plugin/search_api/datasource/SolrDocument.php \Drupal\search_api_solr\Plugin\search_api\datasource\SolrDocument::getFieldValue()
  2. 8.2 src/Plugin/search_api/datasource/SolrDocument.php \Drupal\search_api_solr\Plugin\search_api\datasource\SolrDocument::getFieldValue()

Retrieves a scalar field value from a result item.

Parameters

\Drupal\Core\TypedData\ComplexDataInterface $item: The result item.

string $config_key: The key in the configuration.

Return value

mixed|null The scalar value of the specified field (first value for multi-valued fields), if it exists; NULL otherwise.

Throws

\Drupal\Core\TypedData\Exception\MissingDataException

4 calls to SolrDocument::getFieldValue()
SolrDocument::getItemId in src/Plugin/search_api/datasource/SolrDocument.php
SolrDocument::getItemLabel in src/Plugin/search_api/datasource/SolrDocument.php
SolrDocument::getItemLanguage in src/Plugin/search_api/datasource/SolrDocument.php
SolrDocument::getItemUrl in src/Plugin/search_api/datasource/SolrDocument.php

File

src/Plugin/search_api/datasource/SolrDocument.php, line 152

Class

SolrDocument
Represents a datasource which exposes external Solr Documents.

Namespace

Drupal\search_api_solr\Plugin\search_api\datasource

Code

protected function getFieldValue(ComplexDataInterface $item, $config_key) {
  if (empty($this->configuration[$config_key])) {
    return NULL;
  }
  $values = $item
    ->get($this->configuration[$config_key])
    ->getValue();
  if (is_array($values)) {
    $values = $values ? reset($values) : NULL;
  }
  return $values ?: NULL;
}