You are here

protected function PbfBaseTest::attachPbfNodeFields in Permissions by field 8

Helper function to create and attach a Pbf Node field.

Parameters

string $field_name: The field name to create and attach.

array $widget_settings: The widget form settings.

2 calls to PbfBaseTest::attachPbfNodeFields()
PbfAccessByNodeRefTest::setUp in tests/src/Functional/PbfAccessByNodeRefTest.php
Setup and create content whith Pbf field.
PbfAccessWithFormWidgetValueTest::setUp in tests/src/Functional/PbfAccessWithFormWidgetValueTest.php
Setup and create content whith Pbf field.

File

tests/src/Functional/PbfBaseTest.php, line 402

Class

PbfBaseTest
General setup and helper function for testing pbf module.

Namespace

Drupal\Tests\pbf\Functional

Code

protected function attachPbfNodeFields($field_name, $widget_settings = []) {

  // Add a pbf field to the article content type which reference group.
  $handler_settings = array(
    'target_bundles' => array(
      'group' => 'group',
    ),
    'auto_create' => FALSE,
  );
  $this
    ->createPbfField('node', 'article', $field_name, 'Content of group', 'node', 'default', $handler_settings, -1);

  // Add a pbf field to user entity which reference group.
  $this
    ->createPbfField('user', 'user', $field_name, 'Member of group', 'node', 'default', $handler_settings, -1);

  // Set the form display.
  $settings = $widget_settings + [
    'match_operator' => 'CONTAINS',
    'size' => 30,
    'placeholder' => '',
  ];
  $this
    ->setFormDisplay('node.article.default', 'node', 'article', 'default', $field_name, 'pbf_widget', $settings);
  $this
    ->setFormDisplay('user.user.default', 'user', 'user', 'default', $field_name, 'pbf_widget', $settings);

  // Set the view display.
  $settings = [
    'link' => TRUE,
  ];
  $this
    ->setViewDisplay('node.article.default', 'node', 'article', 'default', $field_name, 'pbf_formatter_default', $settings);
  $this
    ->setViewDisplay('user.user.default', 'user', 'user', 'default', $field_name, 'pbf_formatter_default', $settings);
}