protected function PbfBaseTest::attachPbfTermFields in Permissions by field 8
Attach Pbf fields which reference taxonomy terms.
Parameters
\Drupal\taxonomy\VocabularyInterface $vocabulary: The vocabulary of term referenced.
string $field_name: The field name to create.
1 call to PbfBaseTest::attachPbfTermFields()
- PbfAccessByTermRefTest::setUp in tests/
src/ Functional/ PbfAccessByTermRefTest.php - Setup and create content with Pbf field.
File
- tests/
src/ Functional/ PbfBaseTest.php, line 491
Class
- PbfBaseTest
- General setup and helper function for testing pbf module.
Namespace
Drupal\Tests\pbf\FunctionalCode
protected function attachPbfTermFields(VocabularyInterface $vocabulary, $field_name) {
$handler_settings = array(
'target_bundles' => array(
$vocabulary
->id() => $vocabulary
->id(),
),
'auto_create' => FALSE,
);
// Add a pbf field to the article content type which reference term.
$this
->createPbfField('node', 'article', $field_name, 'Content related to term', 'taxonomy_term', 'default', $handler_settings, -1);
// Add a pbf field to user entity which reference term.
$this
->createPbfField('user', 'user', $field_name, 'User related to term', 'taxonomy_term', 'default', $handler_settings, -1);
// Set the form display.
$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);
}