SolrDocumentDefinition.php in Search API Solr 4.x
File
src/TypedData/SolrDocumentDefinition.php
View source
<?php
namespace Drupal\search_api_solr\TypedData;
use Drupal\Core\TypedData\ComplexDataDefinitionBase;
use Drupal\search_api\Entity\Index;
class SolrDocumentDefinition extends ComplexDataDefinitionBase implements SolrDocumentDefinitionInterface {
protected $server;
public static function create($index_id = NULL) {
$definition['type'] = $index_id ? 'solr_document:' . $index_id : 'solr_document';
$document_definition = new static($definition);
if ($index_id) {
$document_definition
->setIndexId($index_id);
}
return $document_definition;
}
public static function createFromDataType($data_type) {
$parts = explode(':', $data_type, 2);
if (!in_array($parts[0], [
'solr_document',
'solr_multisite_document',
])) {
throw new \InvalidArgumentException('Data type must be in the form of "solr_document:INDEX_ID" or solr_multisite_document:INDEX_ID.');
}
return self::create($parts[1]);
}
public function getIndexId() {
return isset($this->definition['constraints']['Index']) ? $this->definition['constraints']['Index'] : NULL;
}
public function setIndexId(string $index_id) {
return $this
->addConstraint('Index', $index_id);
}
public function getPropertyDefinitions() {
if (!isset($this->propertyDefinitions)) {
$this->propertyDefinitions = [];
if (!empty($this
->getIndexId())) {
$index = Index::load($this
->getIndexId());
$field_manager = \Drupal::getContainer()
->get('solr_field.manager');
$this->propertyDefinitions = $field_manager
->getFieldDefinitions($index);
}
}
return $this->propertyDefinitions;
}
}