You are here

function path_entity_translation_create in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/path/path.module \path_entity_translation_create()
  2. 9 core/modules/path/path.module \path_entity_translation_create()

Implements hook_entity_translation_create().

File

core/modules/path/path.module, line 119
Enables users to rename URLs.

Code

function path_entity_translation_create(ContentEntityInterface $translation) {
  foreach ($translation
    ->getFieldDefinitions() as $field_name => $field_definition) {
    if ($field_definition
      ->getType() === 'path' && $translation
      ->get($field_name)->pid) {

      // If there are values and a path ID, update the langcode and unset the
      // path ID to save this as a new alias.
      $translation
        ->get($field_name)->langcode = $translation
        ->language()
        ->getId();
      $translation
        ->get($field_name)->pid = NULL;
    }
  }
}