Problem/Motivation
Core is about to add a default content export system: #3532694: Add a command-line utility to export content in YAML format
It is extensible and modules can integrate with it by means of an event. Pathauto should integrate with this new system.
Proposed resolution
It is possible that nothing will actually be necessary; core naïvely exports the Path field items, only removing the non-portable path ID.
But if it turns out that core is not exporting the Pathauto flag, then Pathauto should subscribe to the new PreExportEvent and wrap around the core callback for path field items, ensuring that the flag is preserved on export.
Issue fork pathauto-3535498
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
phenaproximaThe core blocker is in!
Comment #3
dieterholvoet commentedFYI, it seems like core is not exporting the Pathauto flag by default.
Comment #4
phenaproximaThat's because it is a computed property, which core ignores by default.
Pathauto could force the property to be exported by overriding the export callback for
pathfield items. That's doable by subscribing toPreExportEvent.Comment #5
dieterholvoet commentedComment #7
dieterholvoet commentedPathauto seems to be causing issues with default content.
Drupal\pathauto\PathautoItem::postSave()makes it so its parent method,Drupal\path\Plugin\Field\FieldType\PathItem::postSave(), is never triggered when pathauto is enabled. This causes aliases of translations to sometimes not be imported.Comment #8
dieterholvoet commentedIt seems like #2973478: Aliases are not created for affected translations fixes this problem. With a patch from that issue, aliases for all translations are generated during import. That does mean that the exported alias is not used and instead a new alias is generated, but that might be acceptable in context of Pathauto.
Comment #9
csakiistvan@dieterholvoet — the MR itself tests out fine, but could you clarify the last sentence of comment #8? "The exported alias is not used and instead a new alias is generated" only seems to hold for items with
pathauto: 1. Forpathauto: 0items the exported alias is used verbatim (see the round trip below), and that is precisely what exporting the flag buys us — so as a general statement it appears to argue against the MR's own purpose. Did you mean it strictly for the automatic case? Also, should #2973478 be marked as a dependency here rather than just related, if the translation import fix is required?Environment
Not reproducible in the browser — the core default content exporter is a CLI/API feature. The core
drupal content:exportscript does not bootstrap in a docroot-based composer layout, so theDrupal\Core\DefaultContent\Exporterservice (which that command wraps) is called directly.Prerequisites
pathauto: 1);pathauto: 0).Steps
pathfield in the YAML output. Note that nopathautokey is present for either node.Drupal\pathauto\EventSubscriber\DefaultContentSubscriber, which subscribes toPreExportEventand registers an export callback forfield_item:paththat drops the non-portablepidand adds the computedpathautostate to the exported values.ddev drush crpathfield in the YAML output.Expected results
pathfield contains onlyaliasandlangcode; the pathauto state is missing, because it is a computed property and core skips those.pathfield also containspathauto: 1for the automatically aliased node andpathauto: 0for the hand-aliased node./my-hand-made-aliasunchanged for the hand-aliased node, and regenerates the pattern-based alias for the other one.pidvalue in the export.Actual results
Before the fix both nodes exported as
aliaspluslangcodeonly, with no pathauto state. After applying MR !185 and rebuilding caches, the export containedpathauto: 1for "Pathauto Export Test" andpathauto: 0for "Manual Alias Test", and nopid. The round trip confirmed the practical effect: with the flag exported, the re-imported "Manual Alias Test" kept/my-hand-made-alias, while "Pathauto Export Test" was regenerated to/article/pathauto-export-test. Importing the same YAML with thepathautolines stripped out (i.e. the pre-fix export) silently replaced the hand-written alias with the generated/article/manual-alias-test, so without this fix the manual alias is lost on import. Works as intended.Remarks
pathauto: 1. Forpathauto: 0items,PathautoItem::postSave()defers toPathItem::postSave()and the exported alias is used verbatim — which is exactly what this MR makes possible, and losing it would be data loss rather than acceptable behaviour. The wording in comment #8 reads as more general than it is.PathautoItem::postSave()prevents translation aliases from being imported, and comment #8 says a patch from #2973478 fixes it. That issue is currently only listed as related; if the fix is required for correct multilingual import it should be marked as a dependency of this issue. The translation scenario was not covered by this test.Testing produced with the assistance of an LLM.
Comment #10
dieterholvoet commentedYes
Yes, it's needed when dealing with translations, but that doesn't mean we can't merge this before that one.