3 namespace Drupal\Tests\video_embed_field\Functional;
4 use Drupal\field\Entity\FieldConfig;
5 use Drupal\field\Entity\FieldStorageConfig;
6 use Drupal\simpletest\ContentTypeCreationTrait;
7 use Drupal\simpletest\NodeCreationTrait;
10 * A trait for manipulating entity display.
12 trait EntityDisplaySetupTrait {
14 use ContentTypeCreationTrait;
15 use NodeCreationTrait;
25 * The name of the content type.
29 protected $contentTypeName;
34 * @var \Drupal\Core\Entity\Display\EntityViewDisplayInterface
36 protected $entityDisplay;
41 * @var \Drupal\Core\Entity\Display\EntityFormDisplayInterface
43 protected $entityFormDisplay;
46 * Setup the entity displays with required fields.
48 protected function setupEntityDisplays() {
49 $this->fieldName = 'field_test_video_field';
50 $this->contentTypeName = 'test_content_type_name';
51 $this->createContentType(['type' => $this->contentTypeName]);
52 $field_storage = FieldStorageConfig::create([
53 'field_name' => $this->fieldName,
54 'entity_type' => 'node',
55 'type' => 'video_embed_field',
57 'allowed_providers' => [],
60 $field_storage->save();
62 'field_storage' => $field_storage,
63 'bundle' => $this->contentTypeName,
66 $this->entityDisplay = entity_get_display('node', $this->contentTypeName, 'default');
67 $this->entityFormDisplay = entity_get_form_display('node', $this->contentTypeName, 'default');
71 * Set component settings for the display.
74 * The component to change settings for.
75 * @param array $settings
76 * The settings to use.
78 protected function setDisplayComponentSettings($type, $settings = []) {
79 $this->entityDisplay->setComponent($this->fieldName, [
81 'settings' => $settings,
86 * Set component settings for the form.
89 * The component to change settings for.
90 * @param array $settings
91 * The settings to use.
93 protected function setFormComponentSettings($type, $settings = []) {
94 $this->entityFormDisplay
95 ->setComponent($this->fieldName, [
97 'settings' => $settings,
103 * Create a video node using the video field.
105 * @param string $value
106 * The video URL to use for the field value.
108 * @return \Drupal\node\NodeInterface
111 protected function createVideoNode($value) {
112 return $this->createNode([
113 'type' => $this->contentTypeName,
114 $this->fieldName => [