public static function SolrField::createFromField in Search API Solr 4.x
Same name and namespace in other branches
- 8.3 src/Plugin/DataType/SolrField.php \Drupal\search_api_solr\Plugin\DataType\SolrField::createFromField()
- 8.2 src/Plugin/DataType/SolrField.php \Drupal\search_api_solr\Plugin\DataType\SolrField::createFromField()
Creates an instance wrapping the given Field.
Parameters
\Drupal\search_api\Item\FieldInterface $field: The Field object to wrap.
string $name: The name of the wrapped field.
\Drupal\Core\TypedData\TypedDataInterface $parent: The parent object of the wrapped field, which should be a Solr document.
Return value
static
File
- src/
Plugin/ DataType/ SolrField.php, line 50
Class
- SolrField
- Defines the "Solr field" data type.
Namespace
Drupal\search_api_solr\Plugin\DataTypeCode
public static function createFromField(FieldInterface $field, $name, TypedDataInterface $parent) {
// Get the Solr field definition from the SolrFieldManager.
/** @var \Drupal\search_api_solr\SolrFieldManagerInterface $field_manager */
$field_manager = \Drupal::getContainer()
->get(static::$solrField . 'solr_field.manager');
$field_id = $field
->getPropertyPath();
$definition = $field_manager
->getFieldDefinitions($field
->getIndex())[$field_id];
$instance = new static($definition, $name, $parent);
$instance
->setValue($field
->getValues());
return $instance;
}