function FieldStorageCreationTrait::configureEntityFormDisplay
Same name in other branches
- 11.x core/modules/field_ui/src/Form/FieldStorageCreationTrait.php \Drupal\field_ui\Form\FieldStorageCreationTrait::configureEntityFormDisplay()
Configures the field for the default form mode.
Parameters
string $field_name: The field name.
array[] $widget_settings: (optional) Array of widget settings, keyed by form mode. Defaults to an empty array.
Throws
\Drupal\Core\Entity\EntityStorageException
2 calls to FieldStorageCreationTrait::configureEntityFormDisplay()
- FieldConfigEditForm::save in core/
modules/ field_ui/ src/ Form/ FieldConfigEditForm.php - Form submission handler for the 'save' action.
- FieldStorageReuseForm::reuseCallback in core/
modules/ field_ui/ src/ Form/ FieldStorageReuseForm.php - Callback function to handle re-using an existing field.
File
-
core/
modules/ field_ui/ src/ Form/ FieldStorageCreationTrait.php, line 21
Class
- FieldStorageCreationTrait
- Provides common functionality for adding or re-using a field.
Namespace
Drupal\field_ui\FormCode
protected function configureEntityFormDisplay(string $field_name, array $widget_settings = []) {
// For a new field, only $mode = 'default' should be set. Use the
// preconfigured or default widget and settings. The field will not appear
// in other form modes until it is explicitly configured.
foreach ($widget_settings as $mode => $options) {
$form_display = $this->entityDisplayRepository
->getFormDisplay($this->entityTypeId, $this->bundle, $mode);
if ($form_display->status()) {
$form_display->setComponent($field_name, $options)
->save();
}
}
if (empty($widget_settings)) {
$this->entityDisplayRepository
->getFormDisplay($this->entityTypeId, $this->bundle, 'default')
->setComponent($field_name, [])
->save();
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.