Closed (won't fix)
Project:
Default Content
Version:
8.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
20 Apr 2016 at 21:53 UTC
Updated:
13 Feb 2024 at 14:35 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
larowlanYou need #2649646: Normalize path fields as part of the entity: allow REST clients to know the path alias (core bug)
Comment #3
dinarcon commentedThanks for the reference @larowlan
Comment #4
yannisc commentedIs there any workaround for this? Not having the url path is critical. Is there a way to set it e.g. via a drush command?
Comment #5
bartk commented@yannisc:
It can be done from Drush.
You can also do it in your module's hook_install function, like this:EDIT: THIS DOES NOT WORK IN YOUR MODULE'S HOOK_INSTALL(), because it executes before the content is inserted. You'll have to do it elsewhere, perhaps in response to default_content's ImportEvent.
The Drush command, as long as you know the nid (1, in this example), would be:
drush php-eval "\Drupal::service('path.alias_storage')->save('/node/1, '/home');"Comment #6
yannisc commentedthank you, @bartk!
Comment #7
ygerasimov commentedYou can do this with hook_node_insert.
Comment #8
pguillard commentedI suggest renaming the title of this one to "Export URL contributed alias for nodes"
as URL alias Configuration (admin/config/search/path/patterns) is CMI / Config
Thanks @ygerasimov, really usefull.
Comment #9
pguillard commentedI guess we should use hook_entity_insert instead :
Comment #10
badjava commentedI created an experimental module called Default Content Extras that supports this feature.
Comment #11
larowlansigh, why not collaborate with patches here?
Comment #12
badjava commentedYes, I should've posted a patch here first. I made the assumption that this issue was going to get fixed when the underlying core issue was fixed.
Here is a patch that adds a node normalizer and expands the existing term normalizer to include path alias data in $entity['path']['alias'].
Comment #14
larowlanI don't think hard-coding support for Node and Taxonomy is the right approach.
a) you cannot assume node URIs are node/{X} because the D8 routing system allows changing that
b) what if another entity type has a path field.
Instead I think we should use the PathItem normalizer approach as per https://www.drupal.org/node/2649646#comment-10752008
Comment #15
badjava commentedAgreed, it's a solution, not a great one. I suspect this will get resolved properly in #2846554: Make the PathItem field type actually computed and auto-load stored aliases so setting this to postponed.
Comment #16
chi commentedAnother workaround is exporting Pathauto patterns instead instead of aliases. This works only if your aliases are not relying on entity IDs.
Comment #17
tanc@Chi can you elaborate? I have set a pathauto pattern for my content type but when default_content inserts a node the pathauto pattern is not generated for that node. Any idea how to get it to trigger?
Comment #18
tancOh, my mistake, my tests were incorrect. The pathauto url does get generated fine.
Comment #19
JvE commentedIssue #2846554: Make the PathItem field type actually computed and auto-load stored aliases has been fixed in 8.4 for a while now.
What needs to happen to get this default content issue resolved?
Comment #20
yannisc commentedAny progress on that?
Comment #21
larowlanIf the core issue doesn't resolve it, then we need a new normalizer for the PathItem fields
Comment #22
bburgShould a PathItem normalizer be added to this module then? Or perhaps Better Normalizers?
Are these two separate issues? Using an exported path Vs. using pathauto to generate a path? I'd like to contribute, but I'm still unfamiliar with Normalizers in D8.
Comment #23
bburgThis is a dirty hack, but for anyone else trying to get their paths importing correctly, I dropped this in Importer::importContent() just after the entity->save() calls. It seems to work for me, but will most certainly not work for all use cases.
Note the hard-coded 'en' language parameter.
Comment #24
manuel.adanAnd why only for nodes?
Comment #25
andypostCore issue resolved, anything left here? or one more normalizer needed for better normalizers?
Comment #26
manuel.adanThe fixed_path_alias module may help on this. It allows to export/import selected path aliases to/from config.
Comment #27
rob230 commentedPatch for anyone wanting to use bburg's hack (which imports paths for nodes in the English language).
It would be great to have a real solution for this because I feel that the alias is an important aspect of pages.
Comment #28
berdirI've recently created the 2.0.x branch, see the project page on all the improvements in the 2.0.x branch. Testing that and providing feedback would be very welcome. The 1.x branch isn't actively maintained and won't receive new features anymore, so I'm closing this and other issues as won't fix.
path import should work in 1.x but you need to manually adjust the exported content, remove the pid column and when using pathauto, add the pathauto ignore flag. This is supported by default in 2.0.x and aliases should just work.
Comment #29
stefan.kornHm, still having trouble with 2.x and path aliases (maybe I have overlooked something, 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:
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.