class EntityFieldRenderer in Search API 8
Renders entity fields.
This is used to build render arrays for all entity field values of a view result set sharing the same relationship. An entity translation renderer is used internally to handle entity language properly.
Overridden in the Search API since we also need to take the datasource into account, not only the relationship.
Hierarchy
- class \Drupal\views\Entity\Render\RendererBase implements CacheableDependencyInterface
- class \Drupal\views\Entity\Render\EntityFieldRenderer uses DependencySerializationTrait, DeprecatedServicePropertyTrait, EntityTranslationRenderTrait
- class \Drupal\search_api\Plugin\views\EntityFieldRenderer
- class \Drupal\views\Entity\Render\EntityFieldRenderer uses DependencySerializationTrait, DeprecatedServicePropertyTrait, EntityTranslationRenderTrait
Expanded class hierarchy of EntityFieldRenderer
1 file declares its use of EntityFieldRenderer
- SearchApiEntityField.php in src/
Plugin/ views/ field/ SearchApiEntityField.php
File
- src/
Plugin/ views/ EntityFieldRenderer.php, line 19
Namespace
Drupal\search_api\Plugin\viewsView source
class EntityFieldRenderer extends ViewsEntityFieldRenderer {
/**
* The datasource ID of this renderer.
*
* @var string|null
*/
protected $datasourceId;
/**
* The property path to the entities rendered by this renderer.
*
* @var string|null
*/
protected $parentPath;
/**
* Retrieves the datasource ID.
*
* @return string|null
* The datasource ID.
*/
public function getDatasourceId() {
return $this->datasourceId;
}
/**
* Sets the datasource ID.
*
* @param string|null $datasource_id
* The new datasource ID.
*
* @return $this
*/
public function setDatasourceId($datasource_id) {
$this->datasourceId = $datasource_id;
return $this;
}
/**
* Retrieves the parent path.
*
* @return string|null
* The property path to the entities rendered by this renderer.
*/
public function getParentPath() {
return $this->parentPath;
}
/**
* Sets the parent path.
*
* @param string|null $parent_path
* The property path to the entities rendered by this renderer.
*
* @return $this
*/
public function setParentPath($parent_path) {
$this->parentPath = $parent_path;
return $this;
}
/**
* Determines whether this renderer can handle the given field.
*
* @param \Drupal\views\Plugin\views\field\FieldHandlerInterface $field
* The field for which to check compatibility.
*
* @return bool
* TRUE if this renderer can handle the given field, FALSE otherwise.
*
* @see EntityFieldRenderer::getRenderableFieldIds()
*/
public function compatibleWithField(FieldHandlerInterface $field) {
if ($field instanceof SearchApiEntityField && $field->options['field_rendering'] && $field->relationship === $this->relationship && $field
->getDatasourceId() === $this->datasourceId && $field
->getParentPath() === $this->parentPath && ($field->definition['entity_type'] ?? '') === $this
->getEntityTypeId()) {
return TRUE;
}
return FALSE;
}
/**
* {@inheritdoc}
*/
protected function getEntityTranslationRenderer() {
if (!isset($this->entityTranslationRenderer)) {
$entity_type = $this
->getEntityTypeManager()
->getDefinition($this
->getEntityTypeId());
$this->entityTranslationRenderer = new EntityTranslationRenderer($this->view, $this
->getLanguageManager(), $entity_type);
}
return $this->entityTranslationRenderer;
}
/**
* {@inheritdoc}
*/
protected function getRenderableFieldIds() {
$field_ids = [];
foreach ($this->view->field as $field_id => $field) {
if ($this
->compatibleWithField($field)) {
$field_ids[] = $field_id;
}
}
return $field_ids;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
DeprecatedServicePropertyTrait:: |
public | function | Allows to access deprecated/removed properties. | |
EntityFieldRenderer:: |
protected | property | The datasource ID of this renderer. | |
EntityFieldRenderer:: |
protected | property | ||
EntityFieldRenderer:: |
protected | property | The entity repository service. | |
EntityFieldRenderer:: |
protected | property | The entity type manager. | |
EntityFieldRenderer:: |
protected | property | The property path to the entities rendered by this renderer. | |
EntityFieldRenderer:: |
protected | property | A list of indexes of rows whose fields have already been rendered. | |
EntityFieldRenderer:: |
protected | property | The relationship being handled. | |
EntityFieldRenderer:: |
protected | function | Builds the render arrays for all fields of all result rows. | |
EntityFieldRenderer:: |
public | function | Determines whether this renderer can handle the given field. | |
EntityFieldRenderer:: |
public | function |
The cache contexts associated with this object. Overrides RendererBase:: |
|
EntityFieldRenderer:: |
public | function | Retrieves the datasource ID. | |
EntityFieldRenderer:: |
protected | function | ||
EntityFieldRenderer:: |
protected | function |
Returns the entity repository. Overrides EntityTranslationRenderTrait:: |
|
EntityFieldRenderer:: |
protected | function |
Returns the current renderer. Overrides EntityTranslationRenderTrait:: |
|
EntityFieldRenderer:: |
public | function |
Returns the entity type identifier. Overrides EntityTranslationRenderTrait:: |
|
EntityFieldRenderer:: |
protected | function |
Returns the entity type manager. Overrides EntityTranslationRenderTrait:: |
|
EntityFieldRenderer:: |
protected | function |
Returns the language manager. Overrides EntityTranslationRenderTrait:: |
|
EntityFieldRenderer:: |
public | function | Retrieves the parent path. | |
EntityFieldRenderer:: |
protected | function |
Returns a list of names of entity fields to be rendered. Overrides EntityFieldRenderer:: |
|
EntityFieldRenderer:: |
protected | function |
Returns the top object of a view. Overrides EntityTranslationRenderTrait:: |
|
EntityFieldRenderer:: |
public | function |
Alters the query if needed. Overrides RendererBase:: |
|
EntityFieldRenderer:: |
public | function |
Renders entity field data. Overrides RendererBase:: |
|
EntityFieldRenderer:: |
public | function | Sets the datasource ID. | |
EntityFieldRenderer:: |
public | function | Sets the parent path. | |
EntityFieldRenderer:: |
public | function |
Constructs an EntityFieldRenderer object. Overrides RendererBase:: |
|
EntityTranslationRenderTrait:: |
protected | property | The renderer to be used to render the entity row. | |
EntityTranslationRenderTrait:: |
public | function | Returns the entity translation matching the configured row language. | |
RendererBase:: |
protected | property | Contains an array of render arrays, one for each rendered entity. | |
RendererBase:: |
protected | property | The type of the entity being rendered. | |
RendererBase:: |
protected | property | The language manager. | |
RendererBase:: |
public | property | The view executable wrapping the view storage entity. | |
RendererBase:: |
public | function |
The maximum age for which this object may be cached. Overrides CacheableDependencyInterface:: |
|
RendererBase:: |
public | function |
The cache tags associated with this object. Overrides CacheableDependencyInterface:: |
|
RendererBase:: |
public | function | Runs before each entity is rendered. | 1 |