function ViewsViewFieldStatusTest::createStatusView

Creates a view of an entity type with a single field with the ID 'status'.

Parameters

string $id: The ID of the view.

string $entity_type_id: The ID of the entity type the view is based on.

string $field_name: The name of the entity field to render.

string|null $rendering_language: (optional) The rendering language of the display.

5 calls to ViewsViewFieldStatusTest::createStatusView()
ViewsViewFieldStatusTest::testNodePublicationState in core/themes/default_admin/tests/src/Kernel/ViewsViewFieldStatusTest.php
Tests the marker of published and unpublished nodes.
ViewsViewFieldStatusTest::testNodeTranslationPublicationState in core/themes/default_admin/tests/src/Kernel/ViewsViewFieldStatusTest.php
Tests that the marker of a node row follows the row translation.
ViewsViewFieldStatusTest::testRelationshipEntityPublicationState in core/themes/default_admin/tests/src/Kernel/ViewsViewFieldStatusTest.php
Tests that the entity is resolved from the configured relationship.
ViewsViewFieldStatusTest::testTermPublicationState in core/themes/default_admin/tests/src/Kernel/ViewsViewFieldStatusTest.php
Tests the marker of a publishable entity type other than the node type.
ViewsViewFieldStatusTest::testTermTranslationPublicationState in core/themes/default_admin/tests/src/Kernel/ViewsViewFieldStatusTest.php
Tests that the marker of a term row follows the row translation.

File

core/themes/default_admin/tests/src/Kernel/ViewsViewFieldStatusTest.php, line 315

Class

ViewsViewFieldStatusTest
Tests the publication status marker of views status fields.

Namespace

Drupal\Tests\default_admin\Kernel

Code

protected function createStatusView(string $id, string $entity_type_id, string $field_name, ?string $rendering_language = NULL) : void {
  $entity_type = \Drupal::entityTypeManager()->getDefinition($entity_type_id);
  $base_table = $entity_type->getDataTable();
  $storage = View::create([
    'id' => $id,
    'label' => $id,
    'module' => 'views',
    'base_table' => $base_table,
    'base_field' => $entity_type->getKey('id'),
  ]);
  $executable = $storage->getExecutable();
  $executable->newDisplay('default', 'Default', 'default');
  $display = $executable->displayHandlers
    ->get('default');
  $display->setOption('pager', [
    'type' => 'none',
    'options' => [
      'offset' => 0,
    ],
  ]);
  // The array key and the 'id' are the views field ID. The theme suggestion
  // is derived from that ID, not from the name of the rendered field.
  $display->setOption('fields', [
    'status' => [
      'id' => 'status',
      'table' => $base_table,
      'field' => $field_name,
      'entity_type' => $entity_type_id,
      'entity_field' => $field_name,
      'plugin_id' => 'field',
      'type' => 'boolean',
      'settings' => [
        'format' => 'custom',
        'format_custom_true' => 'live',
        'format_custom_false' => 'draft',
      ],
    ],
  ]);
  if ($rendering_language !== NULL) {
    $display->setOption('rendering_language', $rendering_language);
  }
  $storage->save();
}

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