You are here

protected function EntityViewsDataTest::setupBaseFields in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/views/tests/src/Unit/EntityViewsDataTest.php \Drupal\Tests\views\Unit\EntityViewsDataTest::setupBaseFields()

Helper method to setup base fields.

Parameters

\Drupal\Core\Field\BaseFieldDefinition[] $base_fields: The base fields which are adapted.

Return value

\Drupal\Core\Field\BaseFieldDefinition[] The setup base fields.

3 calls to EntityViewsDataTest::setupBaseFields()
EntityViewsDataTest::testBaseTableFields in core/modules/views/tests/src/Unit/EntityViewsDataTest.php
Tests fields on the base table.
EntityViewsDataTest::testDataTableFields in core/modules/views/tests/src/Unit/EntityViewsDataTest.php
Tests fields on the data table.
EntityViewsDataTest::testRevisionTableFields in core/modules/views/tests/src/Unit/EntityViewsDataTest.php
Tests fields on the revision table.

File

core/modules/views/tests/src/Unit/EntityViewsDataTest.php, line 164
Contains \Drupal\Tests\views\Unit\EntityViewsDataTest.

Class

EntityViewsDataTest
@coversDefaultClass \Drupal\views\EntityViewsData @group Views

Namespace

Drupal\Tests\views\Unit

Code

protected function setupBaseFields(array $base_fields) {

  // Add a description field to the fields supplied by the EntityTest
  // classes. This example comes from the taxonomy Term entity.
  $base_fields['description'] = BaseFieldDefinition::create('text_long')
    ->setLabel('Description')
    ->setDescription('A description of the term.')
    ->setTranslatable(TRUE)
    ->setDisplayOptions('view', [
    'label' => 'hidden',
    'type' => 'text_default',
    'weight' => 0,
  ])
    ->setDisplayConfigurable('view', TRUE)
    ->setDisplayOptions('form', [
    'type' => 'text_textfield',
    'weight' => 0,
  ])
    ->setDisplayConfigurable('form', TRUE);

  // Add a URL field; this example is from the Comment entity.
  $base_fields['homepage'] = BaseFieldDefinition::create('uri')
    ->setLabel('Homepage')
    ->setDescription("The comment author's home page address.")
    ->setTranslatable(TRUE)
    ->setSetting('max_length', 255);

  // A base field with cardinality > 1
  $base_fields['string'] = BaseFieldDefinition::create('string')
    ->setLabel('Strong')
    ->setTranslatable(TRUE)
    ->setCardinality(2);
  foreach ($base_fields as $name => $base_field) {
    $base_field
      ->setName($name);
  }
  return $base_fields;
}