diff --git a/core/modules/path/src/Plugin/Field/FieldWidget/PathWidget.php b/core/modules/path/src/Plugin/Field/FieldWidget/PathWidget.php index cd4d845..38b971f 100644 --- a/core/modules/path/src/Plugin/Field/FieldWidget/PathWidget.php +++ b/core/modules/path/src/Plugin/Field/FieldWidget/PathWidget.php @@ -67,14 +67,22 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen $field_name = $items->getFieldDefinition()->getName(); $translatable_field_names = array_keys($entity->getTranslatableFields()); if (in_array($field_name, $translatable_field_names)) { - // Have to load the unchanged entity because content_translation will - // have already loaded the new translation. - // @see \Drupal\content_translation\Controller\ContentTranslationController::prepareTranslation(). - /** @var \Drupal\Core\TypedData\TranslatableInterface $unchanged_entity */ - $unchanged_entity = $this->entityTypeManager->getStorage($entity->getEntityTypeId())->loadUnchanged($entity->id()); - if (!in_array($entity->language()->getId(), array_keys($unchanged_entity->getTranslationLanguages()))) { - // If this current language is not in translated versions do not use - // the existing path. + // If $entity->id() is not empty, set unchanged entity. + if (!empty($entity->id())) { + // Have to load the unchanged entity because content_translation will + // have already loaded the new translation. + // @see \Drupal\content_translation\Controller\ContentTranslationController::prepareTranslation(). + /** @var \Drupal\Core\TypedData\TranslatableInterface $unchanged_entity */ + $unchanged_entity = $this->entityTypeManager->getStorage($entity->getEntityTypeId())->loadUnchanged($entity->id()); + // If unchanged entity (by ID) is NOT empty continue... + if (!in_array($entity->language()->getId(), array_keys($unchanged_entity->getTranslationLanguages()))) { + // If this current language is not in translated versions do not use + // the existing path. + $use_existing_path = FALSE; + } + } else { + // If the entity ID is empty (typically on a node/add/{bundle} page) + // do not use the existing path. $use_existing_path = FALSE; } }