diff -u b/core/modules/media_library/media_library.module b/core/modules/media_library/media_library.module --- b/core/modules/media_library/media_library.module +++ b/core/modules/media_library/media_library.module @@ -140,11 +140,13 @@ $view = $form['output'][0]['#view']; foreach (Element::getVisibleChildren($form['media_bulk_form']) as $key) { if (isset($view->result[$key])) { - $media = $view->field['media_bulk_form']->getEntity($view->result[$key]); - $title = $media ? t('Select @label', [ + if (!$media = $view->field['media_bulk_form']->getEntity($view->result[$key])) { + $form['media_bulk_form'][$key]['#title'] = ''; + continue; + } + $form['media_bulk_form'][$key]['#title'] = t('Select @label', [ '@label' => $media->label(), - ]) : ''; - $form['media_bulk_form'][$key]['#title'] = $title; + ]); } } } diff -u b/core/modules/media_library/src/Plugin/views/field/MediaLibrarySelectForm.php b/core/modules/media_library/src/Plugin/views/field/MediaLibrarySelectForm.php --- b/core/modules/media_library/src/Plugin/views/field/MediaLibrarySelectForm.php +++ b/core/modules/media_library/src/Plugin/views/field/MediaLibrarySelectForm.php @@ -53,16 +53,18 @@ // Render checkboxes for all rows. $form[$this->options['id']]['#tree'] = TRUE; foreach ($this->view->result as $row_index => $row) { - $entity = $this->getEntity($row); - $checkbox = $entity ? [ + if (!$entity = $this->getEntity($row)) { + $form[$this->options['id']][$row_index] = []; + continue; + } + $form[$this->options['id']][$row_index] = [ '#type' => 'checkbox', '#title' => $this->t('Select @label', [ '@label' => $entity->label(), ]), '#title_display' => 'invisible', '#return_value' => $entity->id(), - ] : []; - $form[$this->options['id']][$row_index] = $checkbox; + ]; } // @todo Remove in https://www.drupal.org/project/drupal/issues/2504115 reverted: --- b/core/modules/views/src/Entity/Render/EntityTranslationRenderTrait.php +++ a/core/modules/views/src/Entity/Render/EntityTranslationRenderTrait.php @@ -58,7 +58,7 @@ /** * Returns the entity translation matching the configured row language. * + * @param \Drupal\Core\Entity\EntityInterface $entity - * @param \Drupal\Core\Entity\EntityInterface|null $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. @@ -66,7 +66,7 @@ * @return \Drupal\Core\Entity\FieldableEntityInterface * The entity translation object for the specified row. */ + public function getEntityTranslation(EntityInterface $entity, ResultRow $row) { - public function getEntityTranslation(EntityInterface $entity = NULL, ResultRow $row) { // 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 diff -u b/core/modules/views/src/Plugin/views/field/BulkForm.php b/core/modules/views/src/Plugin/views/field/BulkForm.php --- b/core/modules/views/src/Plugin/views/field/BulkForm.php +++ b/core/modules/views/src/Plugin/views/field/BulkForm.php @@ -269,11 +269,11 @@ // Render checkboxes for all rows. $form[$this->options['id']]['#tree'] = TRUE; foreach ($this->view->result as $row_index => $row) { - $entity = $this->getEntityTranslation($this->getEntity($row), $row); - if (!$entity) { + if (!$entity = $this->getEntity($row)) { $form[$this->options['id']][$row_index] = []; continue; } + $entity = $this->getEntityTranslation($entity, $row); $form[$this->options['id']][$row_index] = [ '#type' => 'checkbox', diff -u b/core/modules/views/src/Plugin/views/field/EntityLink.php b/core/modules/views/src/Plugin/views/field/EntityLink.php --- b/core/modules/views/src/Plugin/views/field/EntityLink.php +++ b/core/modules/views/src/Plugin/views/field/EntityLink.php @@ -26,6 +26,9 @@ */ protected function renderLink(ResultRow $row) { if ($this->options['output_url_as_text']) { + if (!$urlInfo = $this->getUrlInfo($row)) { + return ''; + } return $this->getUrlInfo($row)->toString(); } return parent::renderLink($row); diff -u b/core/modules/views/src/Plugin/views/field/EntityOperations.php b/core/modules/views/src/Plugin/views/field/EntityOperations.php --- b/core/modules/views/src/Plugin/views/field/EntityOperations.php +++ b/core/modules/views/src/Plugin/views/field/EntityOperations.php @@ -108,10 +108,10 @@ * {@inheritdoc} */ public function render(ResultRow $values) { - $entity = $this->getEntityTranslation($this->getEntity($values), $values); - if (!$entity) { + if (!$entity = $this->getEntity($values)) { return []; } + $entity = $this->getEntityTranslation($entity, $values); $operations = $this->entityManager->getListBuilder($entity->getEntityTypeId())->getOperations($entity); if ($this->options['destination']) { foreach ($operations as &$operation) { diff -u b/core/modules/views/src/Plugin/views/field/LinkBase.php b/core/modules/views/src/Plugin/views/field/LinkBase.php --- b/core/modules/views/src/Plugin/views/field/LinkBase.php +++ b/core/modules/views/src/Plugin/views/field/LinkBase.php @@ -123,10 +123,11 @@ */ public function render(ResultRow $row) { $access = $this->checkUrlAccess($row); - $build = ['#markup' => $access->isAllowed() ? $this->renderLink($row) : '']; - if ($access) { - BubbleableMetadata::createFromObject($access)->applyTo($build); + if ($access === NULL) { + return ''; } + $build = ['#markup' => $access->isAllowed() ? $this->renderLink($row) : '']; + BubbleableMetadata::createFromObject($access)->applyTo($build); return $build; } @@ -169,7 +170,9 @@ */ protected function renderLink(ResultRow $row) { $this->options['alter']['make_link'] = TRUE; - $this->options['alter']['url'] = $this->getUrlInfo($row); + if ($urlInfo = $this->getUrlInfo($row)) { + $this->options['alter']['url'] = $this->getUrlInfo($row); + } $text = !empty($this->options['text']) ? $this->sanitizeValue($this->options['text']) : $this->getDefaultLabel(); $this->addLangcode($row); return $text; diff -u b/core/modules/views/src/Plugin/views/field/RenderedEntity.php b/core/modules/views/src/Plugin/views/field/RenderedEntity.php --- b/core/modules/views/src/Plugin/views/field/RenderedEntity.php +++ b/core/modules/views/src/Plugin/views/field/RenderedEntity.php @@ -105,18 +105,16 @@ * {@inheritdoc} */ public function render(ResultRow $values) { - $entity = $this->getEntityTranslation($this->getEntity($values), $values); - if (!$entity) { + if (!$entity = $this->getEntity($values)) { return []; } + $entity = $this->getEntityTranslation($entity, $values); $build = []; - if (isset($entity)) { - $access = $entity->access('view', NULL, TRUE); - $build['#access'] = $access; - if ($access->isAllowed()) { - $view_builder = $this->entityManager->getViewBuilder($this->getEntityTypeId()); - $build += $view_builder->view($entity, $this->options['view_mode']); - } + $access = $entity->access('view', NULL, TRUE); + $build['#access'] = $access; + if ($access->isAllowed()) { + $view_builder = $this->entityManager->getViewBuilder($this->getEntityTypeId()); + $build += $view_builder->view($entity, $this->options['view_mode']); } return $build; }