You are here

public function SolrFieldManager::getFieldDefinitions in Search API Solr 4.x

Same name and namespace in other branches
  1. 8.3 src/SolrFieldManager.php \Drupal\search_api_solr\SolrFieldManager::getFieldDefinitions()
  2. 8.2 src/SolrFieldManager.php \Drupal\search_api_solr\SolrFieldManager::getFieldDefinitions()

Throws

\Drupal\search_api\SearchApiException

Overrides SolrFieldManagerInterface::getFieldDefinitions

File

src/SolrFieldManager.php, line 63

Class

SolrFieldManager
Manages the discovery of Solr fields.

Namespace

Drupal\search_api_solr

Code

public function getFieldDefinitions(IndexInterface $index) {

  // We need to prevent the use of the field definition cache when we are
  // about to save changes, or the property check in Index::presave will work
  // with stale cached data and remove newly added property definitions.
  // We take the presence of $index->original as indicator that the config
  // entity is being saved.
  if (!empty($index->original)) {
    return $this
      ->buildFieldDefinitions($index);
  }
  $index_id = $index
    ->id();
  if (!isset($this->fieldDefinitions[$index_id])) {

    // Not prepared, try to load from cache.
    $cid = 'solr_field_definitions:' . $index_id;
    if ($cache = $this
      ->cacheGet($cid)) {
      $field_definitions = $cache->data;
    }
    else {
      $field_definitions = $this
        ->buildFieldDefinitions($index);
      $this
        ->cacheSet($cid, $field_definitions, Cache::PERMANENT, $index
        ->getCacheTagsToInvalidate());
    }
    $this->fieldDefinitions[$index_id] = $field_definitions;
  }
  return $this->fieldDefinitions[$index_id];
}