public function LingotekFunctionalJavascriptTestBase::createImageField in Lingotek Translation 3.2.x
Same name and namespace in other branches
- 8.2 tests/src/FunctionalJavascript/LingotekFunctionalJavascriptTestBase.php \Drupal\Tests\lingotek\FunctionalJavascript\LingotekFunctionalJavascriptTestBase::createImageField()
- 4.0.x tests/src/FunctionalJavascript/LingotekFunctionalJavascriptTestBase.php \Drupal\Tests\lingotek\FunctionalJavascript\LingotekFunctionalJavascriptTestBase::createImageField()
- 3.0.x tests/src/FunctionalJavascript/LingotekFunctionalJavascriptTestBase.php \Drupal\Tests\lingotek\FunctionalJavascript\LingotekFunctionalJavascriptTestBase::createImageField()
- 3.1.x tests/src/FunctionalJavascript/LingotekFunctionalJavascriptTestBase.php \Drupal\Tests\lingotek\FunctionalJavascript\LingotekFunctionalJavascriptTestBase::createImageField()
- 3.3.x tests/src/FunctionalJavascript/LingotekFunctionalJavascriptTestBase.php \Drupal\Tests\lingotek\FunctionalJavascript\LingotekFunctionalJavascriptTestBase::createImageField()
- 3.4.x tests/src/FunctionalJavascript/LingotekFunctionalJavascriptTestBase.php \Drupal\Tests\lingotek\FunctionalJavascript\LingotekFunctionalJavascriptTestBase::createImageField()
- 3.5.x tests/src/FunctionalJavascript/LingotekFunctionalJavascriptTestBase.php \Drupal\Tests\lingotek\FunctionalJavascript\LingotekFunctionalJavascriptTestBase::createImageField()
- 3.6.x tests/src/FunctionalJavascript/LingotekFunctionalJavascriptTestBase.php \Drupal\Tests\lingotek\FunctionalJavascript\LingotekFunctionalJavascriptTestBase::createImageField()
- 3.7.x tests/src/FunctionalJavascript/LingotekFunctionalJavascriptTestBase.php \Drupal\Tests\lingotek\FunctionalJavascript\LingotekFunctionalJavascriptTestBase::createImageField()
- 3.8.x tests/src/FunctionalJavascript/LingotekFunctionalJavascriptTestBase.php \Drupal\Tests\lingotek\FunctionalJavascript\LingotekFunctionalJavascriptTestBase::createImageField()
Create a new image field.
Parameters
string $name: The name of the new field (all lowercase).
string $type_name: The bundle that this field will be added to.
string $entity_type_id: The entity type that this field will be added to. Defaults to 'node'.
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.
Return value
\Drupal\Core\Entity\EntityInterface The field config.
Throws
\Drupal\Core\Entity\EntityStorageException
3 calls to LingotekFunctionalJavascriptTestBase::createImageField()
- LingotekSettingsContentSingleFormTest::setUp in tests/
src/ FunctionalJavascript/ LingotekSettingsContentSingleFormTest.php - LingotekSettingsTabContentFormTest::setUp in tests/
src/ FunctionalJavascript/ LingotekSettingsTabContentFormTest.php - LingotekSettingsTabContentFormWithLotsOfContentTest::setUp in tests/
src/ FunctionalJavascript/ LingotekSettingsTabContentFormWithLotsOfContentTest.php
File
- tests/
src/ FunctionalJavascript/ LingotekFunctionalJavascriptTestBase.php, line 141
Class
Namespace
Drupal\Tests\lingotek\FunctionalJavascriptCode
public function createImageField($name, $type_name, $entity_type_id = 'node', array $storage_settings = [], array $field_settings = [], array $widget_settings = []) {
$fieldStorage = \Drupal::entityTypeManager()
->getStorage('field_storage_config')
->create([
'field_name' => $name,
'entity_type' => $entity_type_id,
'type' => 'image',
'settings' => $storage_settings,
'cardinality' => !empty($storage_settings['cardinality']) ? $storage_settings['cardinality'] : 1,
]);
$fieldStorage
->save();
$field_config = \Drupal::entityTypeManager()
->getStorage('field_config')
->create([
'field_name' => $name,
'label' => $name,
'entity_type' => $entity_type_id,
'bundle' => $type_name,
'required' => !empty($field_settings['required']),
'settings' => $field_settings,
]);
$field_config
->save();
$entity_form_display = EntityFormDisplay::load($entity_type_id . '.' . $type_name . '.' . 'default');
if (!$entity_form_display) {
$entity_form_display = EntityFormDisplay::create([
'targetEntityType' => $entity_type_id,
'bundle' => $type_name,
'mode' => 'default',
'status' => TRUE,
]);
}
$entity_form_display
->setComponent($name, [
'type' => 'image_image',
'settings' => $widget_settings,
])
->save();
$display = EntityViewDisplay::load($entity_type_id . '.' . $type_name . '.' . 'default');
if (!$display) {
$display = EntityViewDisplay::create([
'targetEntityType' => $entity_type_id,
'bundle' => $type_name,
'mode' => 'default',
'status' => TRUE,
]);
}
$display
->setComponent($name)
->save();
return $field_config;
}