function EntityCacheTagsTestBase::selectViewMode

Same name in other branches
  1. 8.9.x core/modules/system/src/Tests/Entity/EntityCacheTagsTestBase.php \Drupal\system\Tests\Entity\EntityCacheTagsTestBase::selectViewMode()
  2. 8.9.x core/modules/system/tests/src/Functional/Entity/EntityCacheTagsTestBase.php \Drupal\Tests\system\Functional\Entity\EntityCacheTagsTestBase::selectViewMode()
  3. 10 core/modules/system/tests/src/Functional/Entity/EntityCacheTagsTestBase.php \Drupal\Tests\system\Functional\Entity\EntityCacheTagsTestBase::selectViewMode()
  4. 11.x core/modules/system/tests/src/Functional/Entity/EntityCacheTagsTestBase.php \Drupal\Tests\system\Functional\Entity\EntityCacheTagsTestBase::selectViewMode()

Selects the preferred view mode for the given entity type.

Prefers 'full', picks the first one otherwise, and if none are available, chooses 'default'.

3 calls to EntityCacheTagsTestBase::selectViewMode()
EntityCacheTagsTestBase::createReferenceTestEntities in core/modules/system/tests/src/Functional/Entity/EntityCacheTagsTestBase.php
Creates a referencing and a non-referencing entity for testing purposes.
EntityCacheTagsTestBase::testReferencedEntity in core/modules/system/tests/src/Functional/Entity/EntityCacheTagsTestBase.php
Tests cache tags presence and invalidation of the entity when referenced.
EntityWithUriCacheTagsTestBase::testEntityUri in core/modules/system/tests/src/Functional/Entity/EntityWithUriCacheTagsTestBase.php
Tests cache tags presence and invalidation of the entity at its URI.

File

core/modules/system/tests/src/Functional/Entity/EntityCacheTagsTestBase.php, line 206

Class

EntityCacheTagsTestBase
Provides helper methods for Entity cache tags tests.

Namespace

Drupal\Tests\system\Functional\Entity

Code

protected function selectViewMode($entity_type) {
    $view_modes = \Drupal::entityTypeManager()->getStorage('entity_view_mode')
        ->loadByProperties([
        'targetEntityType' => $entity_type,
    ]);
    if (empty($view_modes)) {
        return 'default';
    }
    else {
        // Prefer the "full" display mode.
        if (isset($view_modes[$entity_type . '.full'])) {
            return 'full';
        }
        else {
            $view_modes = array_keys($view_modes);
            return substr($view_modes[0], strlen($entity_type) + 1);
        }
    }
}

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