getLangcodeByRelationship example

/** * {@inheritdoc} */
  public function preRenderByRelationship(array $result, string $relationship): void {
    $view_builder = \Drupal::entityTypeManager()->getViewBuilder($this->entityType->id());

    /** @var \Drupal\views\ResultRow $row */
    foreach ($result as $row) {
      if ($entity = $this->getEntity($row$relationship)) {
        $entity->view = $this->view;
        $langcode = $this->getLangcodeByRelationship($row$relationship);
        $this->build[$entity->id()][$langcode] = $view_builder->view($entity$this->view->rowPlugin->options['view_mode']$langcode);
      }
    }
  }

  /** * {@inheritdoc} */
  public function renderByRelationship(ResultRow $row, string $relationship): array {
    if ($entity = $this->getEntity($row$relationship)) {
      $entity_id = $entity->id();
      

  public function preRenderByRelationship(array $result, string $relationship): void {
    $view_builder = \Drupal::entityTypeManager()->getViewBuilder($this->entityType->id());

    foreach ($result as $row) {
      if ($entity = $this->getEntity($row$relationship)) {
        $entity->view = $this->view;
        $this->build[$entity->id()] = $view_builder->view($entity$this->view->rowPlugin->options['view_mode']$this->getLangcodeByRelationship($row$relationship));
      }
    }
  }

  /** * {@inheritdoc} */
  public function render(ResultRow $row) {
    return $this->renderByRelationship($row, 'none');
  }

  

  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. */
  
Home | Imprint | This part of the site doesn't use cookies.