function LayoutBuilderDefaultValuesTest::addImageFields
Same name in other branches
- 9 core/modules/layout_builder/tests/src/Functional/LayoutBuilderDefaultValuesTest.php \Drupal\Tests\layout_builder\Functional\LayoutBuilderDefaultValuesTest::addImageFields()
- 10 core/modules/layout_builder/tests/src/Functional/LayoutBuilderDefaultValuesTest.php \Drupal\Tests\layout_builder\Functional\LayoutBuilderDefaultValuesTest::addImageFields()
Helper function to add image fields.
1 call to LayoutBuilderDefaultValuesTest::addImageFields()
- LayoutBuilderDefaultValuesTest::setUp in core/
modules/ layout_builder/ tests/ src/ Functional/ LayoutBuilderDefaultValuesTest.php
File
-
core/
modules/ layout_builder/ tests/ src/ Functional/ LayoutBuilderDefaultValuesTest.php, line 287
Class
- LayoutBuilderDefaultValuesTest
- Tests rendering default field values in Layout Builder.
Namespace
Drupal\Tests\layout_builder\FunctionalCode
protected function addImageFields() : void {
// Create files to use as the default images.
$files = $this->drupalGetTestFiles('image');
$images = [];
for ($i = 1; $i <= 6; $i++) {
$filename = "test-file-{$i}";
$desired_filepath = 'public://' . $filename;
\Drupal::service('file_system')->copy($files[0]->uri, $desired_filepath, FileExists::Error);
$file = File::create([
'uri' => $desired_filepath,
'filename' => $filename,
'name' => $filename,
]);
$file->save();
$images[] = $file;
}
$field_name = 'field_image_storage_default';
$storage_settings['default_image'] = [
'uuid' => $images[0]->uuid(),
'alt' => 'My storage default alt text',
'title' => '',
'width' => 0,
'height' => 0,
];
$field_settings['default_image'] = [
'uuid' => NULL,
'alt' => '',
'title' => '',
'width' => NULL,
'height' => NULL,
];
$widget_settings = [
'preview_image_style' => 'medium',
];
$this->createImageField($field_name, 'node', 'test_node_type', $storage_settings, $field_settings, $widget_settings);
$field_name = 'field_image_instance_default';
$storage_settings['default_image'] = [
'uuid' => NULL,
'alt' => '',
'title' => '',
'width' => NULL,
'height' => NULL,
];
$field_settings['default_image'] = [
'uuid' => $images[0]->uuid(),
'alt' => 'My instance default alt text',
'title' => '',
'width' => 0,
'height' => 0,
];
$widget_settings = [
'preview_image_style' => 'medium',
];
$this->createImageField($field_name, 'node', 'test_node_type', $storage_settings, $field_settings, $widget_settings);
$field_name = 'field_image_both_defaults';
$storage_settings['default_image'] = [
'uuid' => $images[0]->uuid(),
'alt' => 'My storage default alt text',
'title' => '',
'width' => 0,
'height' => 0,
];
$field_settings['default_image'] = [
'uuid' => $images[1]->uuid(),
'alt' => 'My instance default alt text',
'title' => '',
'width' => 0,
'height' => 0,
];
$widget_settings = [
'preview_image_style' => 'medium',
];
$this->createImageField($field_name, 'node', 'test_node_type', $storage_settings, $field_settings, $widget_settings);
$field_name = 'field_image_no_default';
$storage_settings = [];
$field_settings = [];
$widget_settings = [
'preview_image_style' => 'medium',
];
$this->createImageField($field_name, 'node', 'test_node_type', $storage_settings, $field_settings, $widget_settings);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.