Export URL alias configuration for nodes

Created on 20 April 2016, about 8 years ago
Updated 13 February 2024, 5 months ago

Hi, thanks for the great work on this module.

I wonder if it is possible to export the URL alias configuration for nodes? The configuration was not present in my export. Is it because this is a setting not present in all entities and purposely omitted from the export?

🐛 Bug report
Status

Closed: won't fix

Version

1.0

Component

Code

Created by

🇳🇮Nicaragua dinarcon

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.

  • 🇩🇪Germany stefan.korn Jossgrund

    Hm, still having trouble with 2.x and path aliases (maybe I have overlooked somehting, but I can not get a clean solution with path_aliases. Tried different things, exporting path_alias, removing the 'pid' entry from node export etc.).

    Based on #7 (path.alias_storage is gone now) one could use something like this:

    $url_aliases = array(
      'b64cb122-d96c-467d-b22d-901d8ad3232c' => '/home',
      '90382fbc-d908-4a27-99e9-2e7017eb2853' => '/api',
      '75590ebe-b559-4080-9467-c7ff7579cba3' => '/about'
    );
    
    foreach ($url_aliases as $uuid => $url_alias) {
      $node = \Drupal::entityTypeManager()->getStorage('node')->loadByProperties([
        'uuid' => $uuid
      ]);
      $node = reset($node);
    
      if ($node instanceof \Drupal\node\Entity\Node && isset($url_aliases[$uuid])) {
        \Drupal::entityTypeManager()->getStorage('path_alias')->create(
          [
            'path' => '/node/' . $node->id(),
            'alias' => $url_aliases[$uuid]
          ]
        )->save();
      }
    

    You can for example put this in a .php file and then execute this via drush scr after the default content has been imported.

    Could have also use it in hook_node_insert as per #7, but seems not the cleanest way to run through this every time a node is inserted, though this is kind of a one time task.

Production build 0.69.0 2024