FotoramaGalleryImageFieldCreationTrait.php in Fotorama Gallery 8.2
File
tests/src/FunctionalJavascript/FotoramaGalleryImageFieldCreationTrait.php
View source
<?php
namespace Drupal\Tests\fotorama_gallery\FunctionalJavascript;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
trait FotoramaGalleryImageFieldCreationTrait {
protected function createImageField($name, $type_name, array $storage_settings = [], array $field_settings = [], array $widget_settings = [], array $formatter_settings = [], $description = '') {
FieldStorageConfig::create([
'field_name' => $name,
'entity_type' => 'node',
'type' => 'image',
'settings' => $storage_settings,
'cardinality' => !empty($storage_settings['cardinality']) ? $storage_settings['cardinality'] : 1,
])
->save();
$field_config = FieldConfig::create([
'field_name' => $name,
'label' => $name,
'entity_type' => 'node',
'bundle' => $type_name,
'required' => !empty($field_settings['required']),
'settings' => $field_settings,
'description' => $description,
]);
$field_config
->save();
$entity_type = 'node';
$view_mode = 'default';
\Drupal::entityTypeManager()
->getStorage('entity_form_display')
->load($entity_type . '.' . $type_name . '.' . $view_mode)
->setComponent($name, [
'type' => 'image_image',
'settings' => $widget_settings,
])
->save();
\Drupal::entityTypeManager()
->getStorage('entity_view_display')
->load($entity_type . '.' . $type_name . '.' . $view_mode)
->setComponent($name, [
'type' => 'fotorama_gallery',
'settings' => $formatter_settings,
])
->save();
return $field_config;
}
}