protected function LingotekNodeWhenFieldIsRemovedTest::addNewField in Lingotek Translation 3.4.x
Same name and namespace in other branches
- 8.2 tests/src/Functional/LingotekNodeWhenFieldIsRemovedTest.php \Drupal\Tests\lingotek\Functional\LingotekNodeWhenFieldIsRemovedTest::addNewField()
- 4.0.x tests/src/Functional/LingotekNodeWhenFieldIsRemovedTest.php \Drupal\Tests\lingotek\Functional\LingotekNodeWhenFieldIsRemovedTest::addNewField()
- 3.0.x tests/src/Functional/LingotekNodeWhenFieldIsRemovedTest.php \Drupal\Tests\lingotek\Functional\LingotekNodeWhenFieldIsRemovedTest::addNewField()
- 3.1.x tests/src/Functional/LingotekNodeWhenFieldIsRemovedTest.php \Drupal\Tests\lingotek\Functional\LingotekNodeWhenFieldIsRemovedTest::addNewField()
- 3.2.x tests/src/Functional/LingotekNodeWhenFieldIsRemovedTest.php \Drupal\Tests\lingotek\Functional\LingotekNodeWhenFieldIsRemovedTest::addNewField()
- 3.3.x tests/src/Functional/LingotekNodeWhenFieldIsRemovedTest.php \Drupal\Tests\lingotek\Functional\LingotekNodeWhenFieldIsRemovedTest::addNewField()
- 3.5.x tests/src/Functional/LingotekNodeWhenFieldIsRemovedTest.php \Drupal\Tests\lingotek\Functional\LingotekNodeWhenFieldIsRemovedTest::addNewField()
- 3.6.x tests/src/Functional/LingotekNodeWhenFieldIsRemovedTest.php \Drupal\Tests\lingotek\Functional\LingotekNodeWhenFieldIsRemovedTest::addNewField()
- 3.7.x tests/src/Functional/LingotekNodeWhenFieldIsRemovedTest.php \Drupal\Tests\lingotek\Functional\LingotekNodeWhenFieldIsRemovedTest::addNewField()
- 3.8.x tests/src/Functional/LingotekNodeWhenFieldIsRemovedTest.php \Drupal\Tests\lingotek\Functional\LingotekNodeWhenFieldIsRemovedTest::addNewField()
Adds a new text field.
Parameters
string $entity_type_id: The entity type id.
string $bundle: The bundle.
string $field_name: The field name.
string $label: The label.
Return value
\Drupal\Core\Entity\EntityInterface The field config.
1 call to LingotekNodeWhenFieldIsRemovedTest::addNewField()
- LingotekNodeWhenFieldIsRemovedTest::setUp in tests/
src/ Functional/ LingotekNodeWhenFieldIsRemovedTest.php
File
- tests/
src/ Functional/ LingotekNodeWhenFieldIsRemovedTest.php, line 169
Class
- LingotekNodeWhenFieldIsRemovedTest
- Tests removing a field that was enabled for translation but it's not anymore.
Namespace
Drupal\Tests\lingotek\FunctionalCode
protected function addNewField($entity_type_id, $bundle, $field_name, $label) {
$field_storage = FieldStorageConfig::create([
'field_name' => $field_name,
'entity_type' => $entity_type_id,
'type' => 'text_with_summary',
'translatable' => TRUE,
]);
$field_storage
->save();
$field = FieldConfig::create([
'field_storage' => $field_storage,
'bundle' => $bundle,
'label' => $label,
'settings' => [
'display_summary' => TRUE,
],
]);
$field
->save();
// Assign widget settings for the 'default' form mode.
EntityFormDisplay::load($entity_type_id . '.' . $bundle . '.' . 'default')
->setComponent($field_name, [
'type' => 'text_textarea_with_summary',
])
->save();
EntityViewDisplay::load($entity_type_id . '.' . $bundle . '.' . 'default')
->setComponent($field_name, [
'label' => 'hidden',
'type' => 'text_default',
])
->save();
// The teaser view mode is created by the Standard profile and therefore
// might not exist.
$view_modes = \Drupal::service('entity_display.repository')
->getViewModes($entity_type_id);
if (isset($view_modes['teaser'])) {
EntityViewDisplay::load($entity_type_id . '.' . $bundle . '.' . 'default')
->setComponent($field_name, [
'label' => 'hidden',
'type' => 'text_summary_or_trimmed',
])
->save();
}
return $field;
}