You are here

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

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\views
View 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

Namesort descending Modifiers Type Description Overrides
DependencySerializationTrait::$_entityStorages protected property An array of entity type IDs keyed by the property name of their storages.
DependencySerializationTrait::$_serviceIds protected property An array of service IDs keyed by property name used for serialization.
DependencySerializationTrait::__sleep public function 1
DependencySerializationTrait::__wakeup public function 2
DeprecatedServicePropertyTrait::__get public function Allows to access deprecated/removed properties.
EntityFieldRenderer::$datasourceId protected property The datasource ID of this renderer.
EntityFieldRenderer::$deprecatedProperties protected property
EntityFieldRenderer::$entityRepository protected property The entity repository service.
EntityFieldRenderer::$entityTypeManager protected property The entity type manager.
EntityFieldRenderer::$parentPath protected property The property path to the entities rendered by this renderer.
EntityFieldRenderer::$processedRows protected property A list of indexes of rows whose fields have already been rendered.
EntityFieldRenderer::$relationship protected property The relationship being handled.
EntityFieldRenderer::buildFields protected function Builds the render arrays for all fields of all result rows.
EntityFieldRenderer::compatibleWithField public function Determines whether this renderer can handle the given field.
EntityFieldRenderer::getCacheContexts public function The cache contexts associated with this object. Overrides RendererBase::getCacheContexts
EntityFieldRenderer::getDatasourceId public function Retrieves the datasource ID.
EntityFieldRenderer::getEntityManager protected function
EntityFieldRenderer::getEntityRepository protected function Returns the entity repository. Overrides EntityTranslationRenderTrait::getEntityRepository
EntityFieldRenderer::getEntityTranslationRenderer protected function Returns the current renderer. Overrides EntityTranslationRenderTrait::getEntityTranslationRenderer
EntityFieldRenderer::getEntityTypeId public function Returns the entity type identifier. Overrides EntityTranslationRenderTrait::getEntityTypeId
EntityFieldRenderer::getEntityTypeManager protected function Returns the entity type manager. Overrides EntityTranslationRenderTrait::getEntityTypeManager
EntityFieldRenderer::getLanguageManager protected function Returns the language manager. Overrides EntityTranslationRenderTrait::getLanguageManager
EntityFieldRenderer::getParentPath public function Retrieves the parent path.
EntityFieldRenderer::getRenderableFieldIds protected function Returns a list of names of entity fields to be rendered. Overrides EntityFieldRenderer::getRenderableFieldIds
EntityFieldRenderer::getView protected function Returns the top object of a view. Overrides EntityTranslationRenderTrait::getView
EntityFieldRenderer::query public function Alters the query if needed. Overrides RendererBase::query
EntityFieldRenderer::render public function Renders entity field data. Overrides RendererBase::render
EntityFieldRenderer::setDatasourceId public function Sets the datasource ID.
EntityFieldRenderer::setParentPath public function Sets the parent path.
EntityFieldRenderer::__construct public function Constructs an EntityFieldRenderer object. Overrides RendererBase::__construct
EntityTranslationRenderTrait::$entityTranslationRenderer protected property The renderer to be used to render the entity row.
EntityTranslationRenderTrait::getEntityTranslation public function Returns the entity translation matching the configured row language.
RendererBase::$build protected property Contains an array of render arrays, one for each rendered entity.
RendererBase::$entityType protected property The type of the entity being rendered.
RendererBase::$languageManager protected property The language manager.
RendererBase::$view public property The view executable wrapping the view storage entity.
RendererBase::getCacheMaxAge public function The maximum age for which this object may be cached. Overrides CacheableDependencyInterface::getCacheMaxAge
RendererBase::getCacheTags public function The cache tags associated with this object. Overrides CacheableDependencyInterface::getCacheTags
RendererBase::preRender public function Runs before each entity is rendered. 1