protected function BlazyCreationTestTrait::setUpContentWithEntityReference in Blazy 8
Same name and namespace in other branches
- 8.2 tests/src/Traits/BlazyCreationTestTrait.php \Drupal\Tests\blazy\Traits\BlazyCreationTestTrait::setUpContentWithEntityReference()
Build dummy contents with entity references.
Parameters
array $settings: (Optional) configurable settings.
2 calls to BlazyCreationTestTrait::setUpContentWithEntityReference()
- BlazyEntityReferenceFormatterTest::buildContents in tests/
src/ Kernel/ BlazyEntityReferenceFormatterTest.php - Build contents.
- BlazyViewsFileTest::buildContents in tests/
src/ Kernel/ Views/ BlazyViewsFileTest.php - Build contents.
File
- tests/
src/ Traits/ BlazyCreationTestTrait.php, line 409
Class
- BlazyCreationTestTrait
- A Trait common for Blazy tests.
Namespace
Drupal\Tests\blazy\TraitsCode
protected function setUpContentWithEntityReference(array $settings = []) {
$target_bundle = $this->targetBundle;
$bundle = $this->bundle;
$fields = empty($settings['fields']) ? [] : $settings['fields'];
$image_settings = empty($settings['image_settings']) ? [] : $settings['image_settings'];
$entity_settings = empty($settings['entity_settings']) ? [] : $settings['entity_settings'];
$er_field_name = empty($settings['entity_field_name']) ? $this->entityFieldName : $settings['entity_field_name'];
$er_plugin_id = empty($settings['entity_plugin_id']) ? $this->entityPluginId : $settings['entity_plugin_id'];
// Create referenced entity.
$referenced_data['title'] = 'Referenced ' . $this->testPluginId;
// Create dummy fields.
$referenced_data['fields'] = array_merge($this
->getDefaultFields(), $fields);
// Create referenced entity type.
$this
->setUpContentTypeTest($target_bundle, $referenced_data);
// Create referencing entity type.
$referencing_data['fields'] = [
$er_field_name => 'entity_reference',
];
$this
->setUpContentTypeTest($bundle, $referencing_data);
// 1. Build the referenced entities.
$referenced_formatter_link = [
'field_name' => 'field_link',
'plugin_id' => 'link',
'settings' => [],
];
$this
->setUpFormatterDisplay($target_bundle, $referenced_formatter_link);
$referenced_formatter_data = [
'field_name' => $this->testFieldName,
'plugin_id' => $this->testPluginId,
'settings' => $image_settings + $this
->getFormatterSettings(),
];
$this->referencedDisplay = $this
->setUpFormatterDisplay($target_bundle, $referenced_formatter_data);
// Create referenced entities.
$this->referencedEntity = $this
->setUpContentWithItems($target_bundle, $referenced_data);
// 2. Build the referencing entity.
$referencing_formatter_settings = $this
->getDefaultFields(TRUE);
$referencing_formatter_data = [
'field_name' => $er_field_name,
'plugin_id' => $er_plugin_id,
'settings' => empty($entity_settings) ? $referencing_formatter_settings : array_merge($referencing_formatter_settings, $entity_settings),
];
$this->referencingDisplay = $this
->setUpFormatterDisplay($bundle, $referencing_formatter_data);
}