protected function ImageWidgetCropTest::createImageField in Image Widget Crop 8
Create a new image field.
Parameters
string $name: The name of the new field (all lowercase), exclude the "field_" prefix.
string $type_name: The node type that this field will be added to.
string $widget_name: The name of the widget.
array $storage_settings: A list of field storage settings that will be added to the defaults.
array $field_settings: A list of instance settings that will be added to the instance defaults.
array $widget_settings: A list of widget settings that will be added to the widget defaults.
3 calls to ImageWidgetCropTest::createImageField()
- ImageWidgetCropTest::testCropUi in src/
Tests/ ImageWidgetCropTest.php - Test Image Widget Crop UI.
- ImageWidgetCropTest::testFileEntityIntegration in src/
Tests/ ImageWidgetCropTest.php - Tests integration with file_entity module.
- ImageWidgetCropTest::testImageWidgetCrop in src/
Tests/ ImageWidgetCropTest.php - Test Image Widget Crop.
File
- src/
Tests/ ImageWidgetCropTest.php, line 242
Class
- ImageWidgetCropTest
- Minimal test case for the image_widget_crop module.
Namespace
Drupal\image_widget_crop\TestsCode
protected function createImageField($name, $type_name, $widget_name, $storage_settings = [], $field_settings = [], $widget_settings = []) {
\Drupal::entityTypeManager()
->getStorage('field_storage_config')
->create([
'field_name' => $name,
'entity_type' => 'node',
'type' => 'image',
'settings' => $storage_settings,
'cardinality' => !empty($storage_settings['cardinality']) ? $storage_settings['cardinality'] : 1,
])
->save();
$field_config = \Drupal::entityTypeManager()
->getStorage('field_config')
->create([
'field_name' => $name,
'label' => $name,
'entity_type' => 'node',
'bundle' => $type_name,
'required' => !empty($field_settings['required']),
'settings' => $field_settings,
]);
$field_config
->save();
/** @var \Drupal\Core\Entity\Display\EntityFormDisplayInterface $form_display */
$form_display = \Drupal::entityTypeManager()
->getStorage('entity_form_display')
->load('node.' . $type_name . '.default');
$form_display
->setComponent($name, [
'type' => $widget_name,
'settings' => $widget_settings,
])
->save();
/** @var \Drupal\Core\Entity\Display\EntityViewDisplayInterface $view_display */
$view_display = \Drupal::entityTypeManager()
->getStorage('entity_view_display')
->load('node.' . $type_name . '.default');
$view_display
->setComponent($name)
->save();
}