X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=web%2Fcore%2Fmodules%2Fpath%2Fpath.module;fp=web%2Fcore%2Fmodules%2Fpath%2Fpath.module;h=38cb57beee2f7e6c2beecc346ef489d999eaf646;hp=a724b773d6ef88637cb4c43b8ff84f4348f86cb3;hb=9917807b03b64faf00f6a1f29dcb6eafc454efa5;hpb=aea91e65e895364e460983b890e295aa5d5540a5 diff --git a/web/core/modules/path/path.module b/web/core/modules/path/path.module index a724b773d..38cb57bee 100644 --- a/web/core/modules/path/path.module +++ b/web/core/modules/path/path.module @@ -5,6 +5,7 @@ * Enables users to rename URLs. */ +use Drupal\Core\Entity\ContentEntityInterface; use Drupal\Core\Entity\EntityTypeInterface; use Drupal\Core\Field\BaseFieldDefinition; use Drupal\Core\Form\FormStateInterface; @@ -62,7 +63,7 @@ function path_form_node_form_alter(&$form, FormStateInterface $form_state) { * Implements hook_entity_base_field_info(). */ function path_entity_base_field_info(EntityTypeInterface $entity_type) { - if ($entity_type->id() === 'taxonomy_term' || $entity_type->id() === 'node') { + if (in_array($entity_type->id(), ['taxonomy_term', 'node', 'media'], TRUE)) { $fields['path'] = BaseFieldDefinition::create('path') ->setLabel(t('URL alias')) ->setTranslatable(TRUE) @@ -76,3 +77,17 @@ function path_entity_base_field_info(EntityTypeInterface $entity_type) { return $fields; } } + +/** + * Implements hook_entity_translation_create(). + */ +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; + } + } +}