You are here

protected function SolrDocument::getFieldValue in Search API Solr 8.2

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. 4.x 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.

4 calls to SolrDocument::getFieldValue()
SolrDocument::getItemId in src/Plugin/search_api/datasource/SolrDocument.php
Retrieves the unique ID of an object from this datasource.
SolrDocument::getItemLabel in src/Plugin/search_api/datasource/SolrDocument.php
Retrieves a human-readable label for an item.
SolrDocument::getItemLanguage in src/Plugin/search_api/datasource/SolrDocument.php
Retrieves the item's language.
SolrDocument::getItemUrl in src/Plugin/search_api/datasource/SolrDocument.php
Retrieves a URL at which the item can be viewed on the web.

File

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

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;
}