getEntityTranslationByRelationship example


  public function getEntityTranslation(EntityInterface $entity, ResultRow $row) {
    @trigger_error('\Drupal\views\Entity\Render\EntityTranslationRenderTrait::getEntityTranslation is deprecated in drupal:10.1.0 and is removed from drupal:11.0.0. Use \Drupal\views\Entity\Render\EntityTranslationRenderTrait::getEntityTranslationByRelationship instead. See https://www.drupal.org/node/3311862', E_USER_DEPRECATED);
    return $this->getEntityTranslationByRelationship($entity$row);
  }

  /** * Returns the entity translation matching the configured row language. * * @param \Drupal\Core\Entity\EntityInterface $entity * The entity object the field value being processed is attached to. * @param \Drupal\views\ResultRow $row * The result row the field value being processed belongs to. * @param string $relationship * The relationship to be used, or 'none' by default. * * @return \Drupal\Core\Entity\EntityInterface * The entity translation object for the specified row. */
$plugin_definition,
      $container->get('entity_type.manager'),
      $container->get('language_manager'),
      $container->get('entity.repository')
    );
  }

  /** * {@inheritdoc} */
  public function render($row) {
    return $this->getEntityTranslationByRelationship($row->_entity, $row);
  }

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

  /** * {@inheritdoc} */
$entity_type_id = $this->getEntityTypeId();

      // Collect the entities for the relationship, fetch the right translation,       // and group by bundle. For each result row, the corresponding entity can       // be obtained from any of the fields handlers, so we arbitrarily use the       // first one.       $entities_by_bundles = [];
      $field = $this->view->field[current($field_ids)];
      foreach ($values as $result_row) {
        if ($entity = $field->getEntity($result_row)) {
          $relationship = isset($field->options['relationship']) ? $field->options['relationship'] : 'none';
          $entities_by_bundles[$entity->bundle()][$result_row->index] = $this->getEntityTranslationByRelationship($entity$result_row$relationship);
        }
      }

      // Determine unique sets of fields that can be processed by the same       // display. Fields that appear several times in the View open additional       // "overflow" displays.       $display_sets = [];
      foreach ($field_ids as $field_id) {
        $field = $this->view->field[$field_id];
        $field_name = $field->definition['field_name'];
        $index = 0;
        


  /** * Adds language information to the options. * * @param \Drupal\views\ResultRow $row * A view result row. */
  protected function addLangcode(ResultRow $row) {
    $entity = $this->getEntity($row);
    if ($entity && $this->languageManager->isMultilingual()) {
      $this->options['alter']['language'] = $this->getEntityTranslationByRelationship($entity$row)->language();
    }
  }

  /** * Returns the default label for this link. * * @return \Drupal\Core\StringTranslation\TranslatableMarkup * The default link label. */
  protected function getDefaultLabel() {
    return $this->t('link');
  }
/** * {@inheritdoc} */
  protected function getUrlInfo(ResultRow $row) {
    $template = $this->getEntityLinkTemplate();
    $entity = $this->getEntity($row);
    if ($entity === NULL) {
      return NULL;
    }
    if ($this->languageManager->isMultilingual()) {
      $entity = $this->getEntityTranslationByRelationship($entity$row);
    }
    return $entity->toUrl($template)->setAbsolute($this->options['absolute']);
  }

  /** * Returns the entity link template name identifying the link route. * * @returns string * The link template name. */
  protected function getEntityLinkTemplate() {
    

  }

  /** * {@inheritdoc} */
  public function render(ResultRow $values) {
    $entity = $this->getEntity($values);
    if ($entity === NULL) {
      return '';
    }
    $entity = $this->getEntityTranslationByRelationship($entity$values);
    $build = [];
    $access = $entity->access('view', NULL, TRUE);
    $build['#access'] = $access;
    if ($access->isAllowed()) {
      $view_builder = $this->entityTypeManager->getViewBuilder($this->getEntityTypeId());
      $build += $view_builder->view($entity$this->options['view_mode']$entity->language()->getId());
    }
    return $build;
  }

  /** * {@inheritdoc} */
// Add the tableselect javascript.     $form['#attached']['library'][] = 'core/drupal.tableselect';
    $use_revision = array_key_exists('revision', $this->view->getQuery()->getEntityTableInfo());

    // Only add the bulk form options and buttons if there are results.     if (!empty($this->view->result)) {
      // Render checkboxes for all rows.       $form[$this->options['id']]['#tree'] = TRUE;
      foreach ($this->view->result as $row_index => $row) {
        $entity = $this->getEntity($row);
        if ($entity !== NULL) {
          $entity = $this->getEntityTranslationByRelationship($entity$row);

          $form[$this->options['id']][$row_index] = [
            '#type' => 'checkbox',
            // We are not able to determine a main "title" for each row, so we             // can only output a generic label.             '#title' => $this->t('Update this item'),
            '#title_display' => 'invisible',
            '#default_value' => !empty($form_state->getValue($this->options['id'])[$row_index]) ? 1 : NULL,
            '#return_value' => $this->calculateEntityBulkFormKey($entity$use_revision),
          ];
        }
        
/** * {@inheritdoc} */
  public function render(ResultRow $values) {
    $entity = $this->getEntity($values);
    // Allow for the case where there is no entity, if we are on a non-required     // relationship.     if (empty($entity)) {
      return '';
    }

    $entity = $this->getEntityTranslationByRelationship($entity$values);
    $operations = $this->entityTypeManager->getListBuilder($entity->getEntityTypeId())->getOperations($entity);
    if ($this->options['destination']) {
      foreach ($operations as &$operation) {
        if (!isset($operation['query'])) {
          $operation['query'] = [];
        }
        $operation['query'] += $this->getDestinationArray();
      }
    }
    $build = [
      '#type' => 'operations',
      

  protected function createEntityForGroupBy(EntityInterface $entity, ResultRow $row) {
    // Retrieve the correct translation object.     $processed_entity = clone $this->getEntityFieldRenderer()->getEntityTranslationByRelationship($entity$row);

    // Copy our group fields into the cloned entity. It is possible this will     // cause some weirdness, but there is only so much we can hope to do.     if (!empty($this->group_fields) && isset($entity->{$this->definition['field_name']})) {
      // first, test to see if we have a base value.       $base_value = [];
      // Note: We would copy original values here, but it can cause problems.       // For example, text fields store cached filtered values as 'safe_value'       // which does not appear anywhere in the field definition so we cannot       // affect it. Other side effects could happen similarly.       $data = FALSE;
      
Home | Imprint | This part of the site doesn't use cookies.