You are here

public static function SolrDocumentDefinition::createFromDataType in Search API Solr 8.2

Same name and namespace in other branches
  1. 8.3 src/TypedData/SolrDocumentDefinition.php \Drupal\search_api_solr\TypedData\SolrDocumentDefinition::createFromDataType()
  2. 4.x src/TypedData/SolrDocumentDefinition.php \Drupal\search_api_solr\TypedData\SolrDocumentDefinition::createFromDataType()

Creates a new data definition object.

This method is typically used by \Drupal\Core\TypedData\TypedDataManager::createDataDefinition() to build a definition object for an arbitrary data type. When the definition class is known, it is recommended to directly use the static create() method on that class instead; e.g.:

$map_definition = \Drupal\Core\TypedData\MapDataDefinition::create();

Parameters

string $data_type: The data type, for which a data definition should be created.

Return value

static

Throws

\InvalidArgumentException If an unsupported data type gets passed to the class; e.g., 'string' to a definition class handling 'entity:* data types.

Overrides DataDefinition::createFromDataType

File

src/TypedData/SolrDocumentDefinition.php, line 37

Class

SolrDocumentDefinition
A typed data definition class for describing Solr documents.

Namespace

Drupal\search_api_solr\TypedData

Code

public static function createFromDataType($data_type) {

  // The data type should be in the form of "solr_document:$server_id".
  $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]);
}