Two interconnected issues here:

First, if you import content to a content type with an autopath pattern set, the created nodes do not get the auto generated URL. E.g., they have node/###.

This seems to be because there is no 'path' entry in the values used to create the new entity. This means a test is the path field exists done by the pathauto entity hooks fails. A value is needed here to trigger the pathauto autogenerate process.

Second, item is that the path target (URL Alias) is not available when defining a map for a content type with a pathauto pattern set.

Traced this down to the path field being marked as Read Only by pathauth. It seems like the path target code should override the FieldTargetBase::targets method to allow this to be available. This would allow non-autogenerated paths to be imported.

I'm not sure the best way to approach this problem, so I don't have a patch for this.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

cgmonroe created an issue. See original summary.

MegaChriz’s picture

Title: Pathauto import problems. » Add a target for path alias
Category: Bug report » Feature request

Not for all fields mapping targets are implemented. For path alias there should be a mapping target available. This would be a feature request.

As for Pathauto, when not mapping to the path alias, I expect Pathauto to automatically set an alias when a pattern is configured for the content type in question. If it doesn't, then it sounds like a bug in Pathauto.

Changing this into a feature request for the path alias target.

cgmonroe’s picture

Good call on part #1, being a pathauto bug. There is now a patch for pathauto that lets imported nodes be created with the autogenerated alias.

See: #2946273: Alias is not generated when Pathauto widget is hidden

And you're right, having the path available for pathauto related nodes is a feature.

kollod’s picture

For path alias there should be a mapping target available. This would be a feature request.

This is a key feature for those who`d like to upgrade from D6 to D8. The core Upgrade (so called "experimental modules") feature is non-working. Feeds do the job greatly except but importing aliases. Consider this please when will work on next version...

Anyway, I`ve found a solution how to import aliases into D8 ( this from here - LOL! I tried many ways and searched for modules... but simple solution was there)
I`ve imported my D6 aliases with Feeds mapping them to custom link_type field ("field_mycustomurltupefield") in Drupal8, and then Bulk generated (Pathauto) new aliases for nodes using token [node:field_mycustomurltupefield:uri]. You only have to set Pathauto to not strip some letters ("/", ".", "-" etc.) and strip "internal" (added to link type field if path is not absolute).
I`ll share the metod in another topic...
p.s. I also tried to autocopy imported aliases from custom field`s "value" row in Mysql tables into "url_aliase" table, but aliase table has different structure - aliases are assigned to nodes "/node/904", unlike field`s data - to "entity_id" with numbers that are equal to node`s ID numbers (there still should be a way to do this via Mysql...)


UPD.
The above method didn`t work in fact - Feeds not transferring aliase data into link type fields, although it does allow to map them (Pathauto does Bulk generates aliases from link type fields, but I`ve put those aliases manually into 2-3 three fields just to check as if... then Feeds didn`t do the job. So I was to quick in my conclusions).
So the only way I found is to hack core Path module. From my post Upgrade D6 to D8 with Feeds. We can

There are working solution - more easy way. We will HACK DRUPAL CORE!
a) Go to =>> /modules/path/src/Plugin/Field/FieldType and open file PathItem.php
Delete this * no_ui = TRUE, in line 18
It`s in this part:

/**
 * Defines the 'path' entity field type.
 *
 * @FieldType(
 *   id = "path",
 *   label = @Translation("Path"),
 *   description = @Translation("An entity field containing a path alias and related data."),
 *   no_ui = TRUE,
 *   default_widget = "path",
 *   list_class = "\Drupal\path\Plugin\Field\FieldType\PathFieldItemList",
 *   constraints = {"PathAlias" = {}},
 * )
 */

b) Go-go to =>> Content types =>> Article or Page (which needed) /admin/structure/types/manage/page/fields/add-field
From the dropdown Add new field - select Path (newly appeared, but clean the cache before /admin/config/development/performance ). Give it a name - say Kool hack path = field_kool_hack_path Save. You`ll get white page with error message "Unexpected error. Try again later". Surely unexpected!)) IGNORE! Go back here /admin/structure/types/manage/page/fields and see your new created Path field there.
...URL aliases - map them to "field_kool_hack_path" field (created in step 6 - ohh).
And that`s all - aliases will get imported (they are stored in DB table url_alias as should be , "field_kool_hack_path" table in DB is empty in fact there are only "entity_id" and "revision_id" rows, aliase data passed to url_alias table. We can place back no_ui = TRUE line back in PathItem.php )
--------------------------------------

Aliases are all there. There will be be some unexpected things if you try to delete "field_kool_hack_path" field later. It happaned to me, but I`mworking with backups (at each stage downloading backup). Better don`t do this. It would be easier way to update/clone D8->D8 to get rif of that field etc..

frankx’s picture

13.02.2019

With Module Feeds import csv file from a content type into a conten type on D869 webseite. It worked well.

Just, I could not change the imported node id or number (node/xxx) with a new URL-Alias.

I tried to give a node, which i created within the same content type of the D8 webseite directly, a new URL-Alias and it worked as usual.

BUT i can not give the URL-Alias to the imported nodes.

is a way to solve the problem?

Thank a lot for your help.

i found out:
Administration-> Configuration-> Search and metadata
+Add redirect
Add path manuelly

elsteff1385’s picture

#4's hack is not working (anymore).

Subbing to this topic, in the latest Feeds 8.x-dev the "URL Alias" or "Path Alias" is not available (from the target dropdown menu) in mapping of a Feed.

I have disabled/deleted all Pathauto patterns.

Drupal 8.6.13
Feeds 8.x-3.0-alpha4+10-dev
Pathauto 8.x-1.3

MegaChriz’s picture

Status: Active » Needs review
FileSize
1.51 KB

I think that the Pathauto module somehow marks the path field read-only. Feeds assumes you cannot import values for read-only fields, so doesn't provide a field target in this case.

Here's a hack to let Feeds skip the read-only check for the path field. Not tested if this works or what the implications are, but the field does show up as target.

elsteff1385’s picture

#7 confirmed working.

1: /admin/config/search/path/patterns -> in the related pattern, i disabled the specific content type (in my case "Basic Page")

2: /admin/structure/feeds/add -> added feed type. settings:
- Fetcher: upload file
- Parser: CSV
- Processor: Node
- Content type: Basic Page
- Import period: Off
- Parser settings: default delimiter: ;
- Processor settings: Update existing contents

3: /admin/structure/feeds/manage/basic_page_node_import/mapping
- screenshot attached

4: /feed/add -> uploaded CSV file.

GUID;URL;Title;Body;Summary
1;alias/1;Title 1;Body 1;Summary 1
2;alias/2;Title 2;Body 2;Summary 2
3;alias/3;Title 3;Body 3;Summary 3

- This failed with error message: "Alias path alias/1 has to start with a slash." -> nice specific error info.

5: /feed/add -> uploaded fixed CSV file.

GUID;URL;Title;Body;Summary
1;/alias/1;Title 1;Body 1;Summary 1
2;/alias/2;Title 2;Body 2;Summary 2
3;/alias/3;Title 3;Body 3;Summary 3

No errors, perfect result :)

  • MegaChriz committed 3a2b95b on 8.x-3.x
    Issue #2948484 by MegaChriz, elsteff1385: Expose a target for path alias...
MegaChriz’s picture

Title: Add a target for path alias » Expose a target for path alias even when that field is set read only by pathauto
Status: Needs review » Fixed

The hack will do for now. Committed #7 (with coding standard fixes).

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.