'field_name' =>
$field_name,
'entity_type' =>
$this->entityTypeId,
'bundle' =>
$this->bundle,
'label' =>
$existing_storage_label,
// Field translatability should be explicitly enabled by the users.
'translatable' => FALSE,
]);
$field->
save();
// Configure the display modes.
$this->
configureEntityFormDisplay($field_name,
$default_options['entity_form_display'
] ??
[]);
$this->
configureEntityViewDisplay($field_name,
$default_options['entity_view_display'
] ??
[]);
// Store new field information for any additional submit handlers.
$form_state->
set(['fields_added', '_add_existing_field'
],
$field_name);
$form_state->
setRedirect("entity.field_config.{
$this->entityTypeId
}_field_edit_form",
array_merge(FieldUI::
getRouteBundleParameter($entity_type,
$this->bundle
),
['field_config' => "
$this->entityTypeId.
$this->bundle.
$field_name"
]));
} catch (\Exception
$e) { $this->
messenger()->
addError($this->
t('There was a problem reusing field %label: @message',
[ '%label' =>
$existing_storage_label,
'@message' =>
$e->
getMessage(),
]));
} }