getEntityTranslationRenderer example

return $build;
  }

  /** * {@inheritdoc} */
  public function query() {
    // We purposefully do not call parent::query() because we do not want the     // default query behavior for Views fields. Instead, let the entity     // translation renderer provide the correct query behavior.     if ($this->languageManager->isMultilingual()) {
      $this->getEntityTranslationRenderer()->query($this->query, $this->relationship);
    }
  }

  /** * {@inheritdoc} */
  public function getEntityTypeId() {
    return $this->getEntityType();
  }

  /** * {@inheritdoc} */
return Cache::PERMANENT;
  }

  /** * {@inheritdoc} */
  public function query() {
    // We purposefully do not call parent::query() because we do not want the     // default query behavior for Views fields. Instead, let the entity     // translation renderer provide the correct query behavior.     if ($this->languageManager->isMultilingual()) {
      $this->getEntityTranslationRenderer()->query($this->query, $this->relationship);
    }
  }

  /** * {@inheritdoc} */
  public function getEntityTypeId() {
    return $this->getEntityType();
  }

  /** * {@inheritdoc} */

  public function usesGroupBy() {
    return FALSE;
  }

  /** * {@inheritdoc} */
  public function query() {
    if ($this->languageManager->isMultilingual()) {
      $this->getEntityTranslationRenderer()->query($this->query, $this->relationship);
    }
    $this->addAdditionalFields();
  }

  /** * {@inheritdoc} */
  public function render(ResultRow $row) {
    $access = $this->checkUrlAccess($row);
    if ($access) {
      $build = ['#markup' => $access->isAllowed() ? $this->renderLink($row) : ''];
      


  /** * {@inheritdoc} */
  public function query() {
    parent::query();
    $relationship_table = NULL;
    if (isset($this->options['relationship']$this->view->relationship[$this->options['relationship']])) {
      $relationship_table = $this->view->relationship[$this->options['relationship']]->alias;
    }
    $this->getEntityTranslationRenderer()->query($this->view->getQuery()$relationship_table);
  }

  /** * {@inheritdoc} */
  public function preRender($result) {
    parent::preRender($result);
    if ($result) {
      $this->getEntityTranslationRenderer()->preRenderByRelationship($resultisset($this->options['relationship']) ? $this->options['relationship'] : 'none');
    }
  }

  
public function __construct(ViewExecutable $view$relationship, LanguageManagerInterface $language_manager, EntityTypeInterface $entity_type, EntityTypeManagerInterface $entity_type_manager, EntityRepositoryInterface $entity_repository) {
    parent::__construct($view$language_manager$entity_type);
    $this->relationship = $relationship;
    $this->entityTypeManager = $entity_type_manager;
    $this->entityRepository = $entity_repository;
  }

  /** * {@inheritdoc} */
  public function getCacheContexts() {
    return $this->getEntityTranslationRenderer()->getCacheContexts();
  }

  /** * {@inheritdoc} */
  public function getEntityTypeId() {
    return $this->entityType->id();
  }

  /** * {@inheritdoc} */

  public function getEntityTranslationByRelationship(EntityInterface $entity, ResultRow $row, string $relationship = 'none'): EntityInterface {
    // We assume the same language should be used for all entity fields     // belonging to a single row, even if they are attached to different entity     // types. Below we apply language fallback to ensure a valid value is always     // picked.     if ($entity instanceof TranslatableInterface && count($entity->getTranslationLanguages()) > 1) {
      $langcode = $this->getEntityTranslationRenderer()->getLangcodeByRelationship($row$relationship);
      $translation = $this->getEntityRepository()->getTranslationFromContext($entity$langcode);
    }
    return $translation ?? $entity;
  }

  /** * Returns the entity type identifier. * * @return string * The entity type identifier. */
  

  public function getCacheMaxAge() {
    // @todo Consider making the bulk operation form cacheable. See     // https://www.drupal.org/node/2503009.     return 0;
  }

  /** * {@inheritdoc} */
  public function getCacheContexts() {
    return $this->languageManager->isMultilingual() ? $this->getEntityTranslationRenderer()->getCacheContexts() : [];
  }

  /** * {@inheritdoc} */
  public function getCacheTags() {
    return [];
  }

  /** * {@inheritdoc} */

  protected function getView() {
    return $this->view;
  }

  /** * {@inheritdoc} */
  public function query() {
    parent::query();
    $this->getEntityTranslationRenderer()->query($this->view->getQuery());
  }

}
Home | Imprint | This part of the site doesn't use cookies.