Skip to content
Snippets Groups Projects

Issue #3252215: Default domain values not being assigned while creating a new Entity

1 file
+ 15
0
Compare changes
  • Side-by-side
  • Inline
+ 15
0
@@ -593,6 +593,21 @@ function domain_entity_field_widget_single_element_form_alter(&$element, FormSta
if ($context['items']->getFieldDefinition()->getName() !== DomainEntityMapper::FIELD_NAME) {
return;
}
$form_object = $form_state->getFormObject();
if (!$form_object instanceof EntityFormInterface) {
return;
}
// Get the current Entity information.
$entity = $form_object->getEntity();
// Add Default value if we are creating a new Entity.
if ((is_object($entity)) && ($entity->isNew())) {
// Get active Domain ID.
$active_id = \Drupal::service('domain.negotiator')->getActiveId();
// Default value based on the current Active Domain.
$element['#default_value'] = [$active_id];
}
$form_object = $form_state->getFormObject();
if (!$form_object instanceof EntityFormInterface) {
Loading