Add support path alias for node entities

Created on 29 May 2022, over 2 years ago
Updated 13 March 2023, almost 2 years ago

Add support path alias for node entities on import data

✨ Feature request
Status

Needs work

Version

2.0

Component

Code

Created by

πŸ‡·πŸ‡ΊRussia batkor Irkutsk

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡·πŸ‡ΊRussia batkor Irkutsk

    Hi.

    Create patch for beta3 tags.
    Implements from event dispatcher.

    I think need move patch for a 2 branch

  • πŸ‡·πŸ‡ΊRussia batkor Irkutsk

    Example for $11

    /**
       * Implements pre save event subscriber.
       *
       * @param \Drupal\default_content_deploy\Event\PreSaveEntityEvent $event
       *   The event.
       */
      public function preSave(PreSaveEntityEvent $event) {
        $pathAliasesStorage = $this
          ->entityTypeManager
          ->getStorage('path_alias');
        $data = $event->getData();
        $entity = $event->getEntity();
    
        if (empty($data['path'])) {
          return;
        }
    
        foreach (array_keys($entity->getTranslationLanguages()) as $langcode) {
          $value = NULL;
    
          foreach ($data['path'] as $pathValue) {
            if ($pathValue['langcode'] === $langcode) {
              $value = $pathValue;
              break;
            }
          }
    
          if (!empty($value) && !empty($value['alias'])) {
            unset($value['pid']);
            $value['pathauto'] = PathautoState::SKIP;
            $pathAliases = $pathAliasesStorage->loadByProperties([
              'alias' => $value['alias'],
            ]);
            $pathAliasesStorage->delete($pathAliases);
            $translateEntity = $entity->getTranslation($langcode);
            $translateEntity->set('path', $value);
            $this->pathautoGenerator->createEntityAlias($translateEntity, 'insert');
          }
        }
      }
    
  • πŸ‡ΊπŸ‡¦Ukraine Mykhailo.Levchenko

    Hi all,

    Is there any info on when this patch will be applied?

    Thank you,
    Misha

  • First commit to issue fork.
  • πŸ‡©πŸ‡ͺGermany mkalkbrenner πŸ‡©πŸ‡ͺ

    The event is committed.

    We could solve this feature request now be adding a small default_content_deploy_pathauto sub-module to this repository.
    There we could declare all required dependencies and implement the event subscriber.

    BTW That's the pattern we use in the Search API eco-system.

  • πŸ‡©πŸ‡ͺGermany mkalkbrenner πŸ‡©πŸ‡ͺ
  • πŸ‡©πŸ‡ͺGermany mkalkbrenner πŸ‡©πŸ‡ͺ

    Meanwhile, the situation changed drastically. Paths are computed fields and don't belong to a node or an other entity directly.
    The recommended way is to export the path alias entity itself.

    Nevertheless we should handle pathauto. We should add a configuration option if a alias should be generated or not during import.
    The default should be to turn it off.

Production build 0.71.5 2024