function FieldApiDataTest::getViewsData

Same name in other branches
  1. 8.9.x core/modules/views/tests/src/Kernel/FieldApiDataTest.php \Drupal\Tests\views\Kernel\FieldApiDataTest::getViewsData()
  2. 10 core/modules/views/tests/src/Kernel/FieldApiDataTest.php \Drupal\Tests\views\Kernel\FieldApiDataTest::getViewsData()
  3. 11.x core/modules/views/tests/src/Kernel/FieldApiDataTest.php \Drupal\Tests\views\Kernel\FieldApiDataTest::getViewsData()

Gets the views data for the field created in setUp().

Parameters

string $field_storage_key: (optional) The optional field name.

Return value

array Views data.

1 call to FieldApiDataTest::getViewsData()
FieldApiDataTest::testViewsData in core/modules/views/tests/src/Kernel/FieldApiDataTest.php
Unit testing the views data structure.

File

core/modules/views/tests/src/Kernel/FieldApiDataTest.php, line 185

Class

FieldApiDataTest
Tests the Field Views data.

Namespace

Drupal\Tests\views\Kernel

Code

protected function getViewsData($field_storage_key = 'field_string') {
    $views_data = $this->container
        ->get('views.views_data');
    $data = [];
    // Check the table and the joins of the first field. Attached to node only.
    
    /** @var \Drupal\Core\Entity\Sql\DefaultTableMapping $table_mapping */
    $table_mapping = $this->container
        ->get('entity_type.manager')
        ->getStorage('node')
        ->getTableMapping();
    $field_storage = FieldStorageConfig::loadByName('node', $field_storage_key);
    $current_table = $table_mapping->getDedicatedDataTableName($field_storage);
    $revision_table = $table_mapping->getDedicatedRevisionTableName($field_storage);
    $data[$current_table] = $views_data->get($current_table);
    $data[$revision_table] = $views_data->get($revision_table);
    return $data;
}

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