Early Bird Registration for DrupalCon Portland 2024 is open! Register by 23:59 PST on 31 March 2024, to get $100 off your ticket.
There is currently no way to explicitly define a path alias on a node being imported.
Attempting to define both an alias and disable pathauto as shown below produces the error shown below:
path:
alias: '/article-2'
pathauto: false
InvalidArgumentException: 'path' cannot hold more than 1 values. 2 values were parsed from the YAML file. in /drupal/web/root/modules/contrib/yaml_content/src/ContentLoader/ContentLoader.php:353
Attempting to define just the alias instead using the pattern below produces a separate error:
path:
alias: '/article-2'
Drupal\Core\Entity\EntityMalformedException: The "node" entity cannot have a URI as it does not have an ID in /drupal/web/root/core/lib/Drupal/Core/Entity/Entity.php:179
Finally, trying to assign the alias directly to the path attempts to process it as a node property producing the error below:
path: '/article-2'
Drupal\Core\Entity\Query\QueryException: 'path' not found in /drupal/web/root/core/lib/Drupal/Core/Entity/Query/Sql/Tables.php:316
Comment | File | Size | Author |
---|---|---|---|
#14 | yaml_content-n2883434-14.patch | 1.37 KB | DamienMcKenna |
| |||
#14 | yaml_content-n2883434-14.interdiff.txt | 1.07 KB | DamienMcKenna |
Comments
Comment #2
kedramonHi,
same behavior
the correct input is:
by the way, if nid is also passed it works
Comment #3
lamp5Hey. I have a question. Is there a way to update an alias instead of creating it again when I update my nodes ??
Comment #4
drupalninja99 CreditAttribution: drupalninja99 at Mediacurrent commentedI get this error even with this syntax:
Comment #5
bjlewis2 CreditAttribution: bjlewis2 commentedIf I pass a node id in manually, I'm able to get the alias to work, but that's really not ideal...
e.g.
Comment #6
lamp5@drupalninja99 When you importing your nodes, NIDs are not exist and path can not be created. It is similar to menu item Menu item YAML content
First you have to create node and next add path to it.
Now YAML content has acces to node ID.
Comment #7
drupalninja99 CreditAttribution: drupalninja99 at Mediacurrent commented@bjlewis2 I am using this method right now bc I couldn't get the other one to work. Its not great but it works and the nid is arbitrary anyway
Comment #8
sluceroComment #9
kedramonWhat is strange if a pattern for url is like
[node:content-type]/[node:title]
then it fail. only the case with passing nid works.Comment #10
DamienMcKennaThis should work without requiring the magic steps described in #5 or #6.
Comment #11
macganibo CreditAttribution: macganibo commentedWhen adding path to a node, contentLoader.php triggers populateField function and tries to delete existing fields, but when "Drupal\pathauto\PathautoFieldItemList" is pass, it triggers this line of code from Drupal\path\Plugin\Field\FieldType\PathFieldItemList.php:
The line of code assumes that current entity is existing thus throws EntityMalformedException.
Proposed work around:
Skip deleting fields for new entity.
Comment #12
DamienMcKennaThanks macganibo!
Let's see what the testbot says.
I'll also test it out today.
Comment #13
DamienMcKennaThe patch in #11 works great, I can now do imports like this:
Whereas before the alias would be "/organization-chart", after either updating the existing node or deleting & rerunning the import the path is now set correctly.
Great work, macganibo!
Comment #14
DamienMcKennaThis adds a Pathauto alias to one of the example nodes.
Comment #15
DamienMcKennaOk, it turns out this doesn't work when it's triggered by an installation profile, you end up getting this screenful:
Comment #16
DamienMcKennaJust to be clear - the import works correctly after an installation profile has ran, but it does not work when the import is triggered via an installation profile's install tasks.
Comment #17
DamienMcKennaThe fact that the error only happens during the installation profile but does work after the site is installed makes me wonder if it's a caching problem?
Comment #18
DamienMcKennaI destroyed my vagrant install, reran the build and the patch worked. So I'm not sure what was going on last week. Thanks Wilmark!
Comment #20
sluceroMerged! Thank you all for the help on this!
Comment #21
slucero