EntityDisplaySetupTrait.php in Video Embed Field 8.2
File
tests/src/Functional/EntityDisplaySetupTrait.php
View source
<?php
namespace Drupal\Tests\video_embed_field\Functional;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\Tests\node\Traits\ContentTypeCreationTrait;
use Drupal\Tests\node\Traits\NodeCreationTrait;
trait EntityDisplaySetupTrait {
use ContentTypeCreationTrait;
use NodeCreationTrait;
protected $fieldName;
protected $contentTypeName;
protected $entityDisplay;
protected $entityFormDisplay;
protected function setupEntityDisplays() {
$this->fieldName = 'field_test_video_field';
$this->contentTypeName = 'test_content_type_name';
$this
->createContentType([
'type' => $this->contentTypeName,
]);
$field_storage = FieldStorageConfig::create([
'field_name' => $this->fieldName,
'entity_type' => 'node',
'type' => 'video_embed_field',
'settings' => [
'allowed_providers' => [],
],
]);
$field_storage
->save();
FieldConfig::create([
'field_storage' => $field_storage,
'bundle' => $this->contentTypeName,
'settings' => [],
])
->save();
$this->entityDisplay = $this->container
->get('entity_display.repository')
->getViewDisplay('node', $this->contentTypeName, 'default');
$this->entityFormDisplay = $this->container
->get('entity_display.repository')
->getFormDisplay('node', $this->contentTypeName, 'default');
}
protected function setDisplayComponentSettings($type, $settings = []) {
$this->entityDisplay
->setComponent($this->fieldName, [
'type' => $type,
'settings' => $settings,
])
->save();
}
protected function setFormComponentSettings($type, $settings = []) {
$this->entityFormDisplay
->setComponent($this->fieldName, [
'type' => $type,
'settings' => $settings,
])
->save();
}
protected function createVideoNode($value) {
return $this
->createNode([
'type' => $this->contentTypeName,
$this->fieldName => [
[
'value' => $value,
],
],
]);
}
}