public function LingotekTestBase::createImageField in Lingotek Translation 3.0.x
Same name and namespace in other branches
- 8.2 tests/src/Functional/LingotekTestBase.php \Drupal\Tests\lingotek\Functional\LingotekTestBase::createImageField()
- 4.0.x tests/src/Functional/LingotekTestBase.php \Drupal\Tests\lingotek\Functional\LingotekTestBase::createImageField()
- 3.1.x tests/src/Functional/LingotekTestBase.php \Drupal\Tests\lingotek\Functional\LingotekTestBase::createImageField()
- 3.2.x tests/src/Functional/LingotekTestBase.php \Drupal\Tests\lingotek\Functional\LingotekTestBase::createImageField()
- 3.3.x tests/src/Functional/LingotekTestBase.php \Drupal\Tests\lingotek\Functional\LingotekTestBase::createImageField()
- 3.4.x tests/src/Functional/LingotekTestBase.php \Drupal\Tests\lingotek\Functional\LingotekTestBase::createImageField()
- 3.5.x tests/src/Functional/LingotekTestBase.php \Drupal\Tests\lingotek\Functional\LingotekTestBase::createImageField()
- 3.6.x tests/src/Functional/LingotekTestBase.php \Drupal\Tests\lingotek\Functional\LingotekTestBase::createImageField()
- 3.7.x tests/src/Functional/LingotekTestBase.php \Drupal\Tests\lingotek\Functional\LingotekTestBase::createImageField()
- 3.8.x tests/src/Functional/LingotekTestBase.php \Drupal\Tests\lingotek\Functional\LingotekTestBase::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
6 calls to LingotekTestBase::createImageField()
- LingotekContentTranslationDocumentUploadHookTest::setUp in tests/
src/ Functional/ LingotekContentTranslationDocumentUploadHookTest.php - LingotekContentTranslationPreSaveHookTest::setUp in tests/
src/ Functional/ LingotekContentTranslationPreSaveHookTest.php - LingotekNodeEmbeddingTagsTranslationTest::setUp in tests/
src/ Functional/ LingotekNodeEmbeddingTagsTranslationTest.php - LingotekNodeLocaleTranslationTest::setUp in tests/
src/ Functional/ LingotekNodeLocaleTranslationTest.php - LingotekNodeTranslationTest::setUp in tests/
src/ Functional/ LingotekNodeTranslationTest.php
File
- tests/
src/ Functional/ LingotekTestBase.php, line 100
Class
- LingotekTestBase
- Base class for Lingotek test. Performs authorization of the account.
Namespace
Drupal\Tests\lingotek\FunctionalCode
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;
}