SolrDocumentDefinition.php in Search API Solr 8.2
File
src/TypedData/SolrDocumentDefinition.php
View source
<?php
namespace Drupal\search_api_solr\TypedData;
use Drupal\Core\TypedData\ComplexDataDefinitionBase;
class SolrDocumentDefinition extends ComplexDataDefinitionBase implements SolrDocumentDefinitionInterface {
protected $server;
public static function create($server_id) {
$definition['type'] = 'solr_document:' . $server_id;
$document_definition = new static($definition);
$document_definition
->setServerId($server_id);
return $document_definition;
}
public static function createFromDataType($data_type) {
$parts = explode(':', $data_type, 2);
if ($parts[0] != 'solr_document') {
throw new \InvalidArgumentException('Data type must be in the form of "solr_document:SERVER_ID".');
}
if (empty($parts[1])) {
throw new \InvalidArgumentException('A Search API Server must be specified.');
}
return self::create($parts[1]);
}
public function getServerId() {
return isset($this->definition['constraints']['Server']) ? $this->definition['constraints']['Server'] : NULL;
}
public function setServerId($server_id) {
return $this
->addConstraint('Server', $server_id);
}
public function getPropertyDefinitions() {
if (!isset($this->propertyDefinitions)) {
$this->propertyDefinitions = [];
if (!empty($this
->getServerId())) {
$field_manager = \Drupal::getContainer()
->get('solr_field.manager');
$this->propertyDefinitions = $field_manager
->getFieldDefinitions($this
->getServerId());
}
}
return $this->propertyDefinitions;
}
}