EntityTestViewBuilderOverriddenView.php

Same filename and directory in other branches
  1. 9 core/modules/system/tests/modules/entity_test/src/EntityTestViewBuilderOverriddenView.php
  2. 8.9.x core/modules/system/tests/modules/entity_test/src/EntityTestViewBuilderOverriddenView.php
  3. 10 core/modules/system/tests/modules/entity_test/src/EntityTestViewBuilderOverriddenView.php

Namespace

Drupal\entity_test

File

core/modules/system/tests/modules/entity_test/src/EntityTestViewBuilderOverriddenView.php

View source
<?php

namespace Drupal\entity_test;

use Drupal\Core\Entity\EntityInterface;

/**
 * Provides a view builder that overrides ::view() and ::viewMultiple().
 */
class EntityTestViewBuilderOverriddenView extends EntityTestViewBuilder {
    
    /**
     * {@inheritdoc}
     */
    public function view(EntityInterface $entity, $view_mode = 'full', $langcode = NULL) {
        $build = [];
        $build[$entity->id()]['#plain_text'] = $entity->label();
        return $build;
    }
    
    /**
     * {@inheritdoc}
     */
    public function viewMultiple(array $entities = [], $view_mode = 'full', $langcode = NULL) {
        $build = [];
        foreach ($entities as $key => $entity) {
            $build[$key] = $this->view($entity, $view_mode, $langcode);
        }
        return $build;
    }

}

Classes

Title Deprecated Summary
EntityTestViewBuilderOverriddenView Provides a view builder that overrides ::view() and ::viewMultiple().

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.