1

I am using the Wordpress Module to migrate from Wordpress to Drupal 8. I am trying to have the alias be set to the link value (<link>https://myurl.com/wordpress-path</link>). I added the following to the source:

    -
      name: link
      label: 'The link value'
      selector: 'link'

and the following to process:

  path/pathauto:
    plugin: default_value
    default_value: 0
  alias:
    -
      plugin: get
      source: link
    -
      plugin: str_replace
      source: link
      search: 'https://myurl.com/'
      replace: '/'

I have also tried path/alias and path instead of alias but no luck. I verified that the str_replace plugin does return the correct value but somehow it does not save in the node.

Here is my full migrate_plus.migration.my_wordpress_wordpress_content_post.yml:

uuid: 5b3b3b84-8d41-4a80-b1ca-c9046c269297
langcode: en
status: true
dependencies: {  }
id: wp_wordpress_wordpress_content_page
class: null
field_plugin_method: null
cck_plugin_method: null
migration_tags:
  - WordPress
migration_group: wp_wordpress
label: 'Import content from WordPress XML'
source:
  plugin: url
  data_fetcher_plugin: http
  data_parser_plugin: xml
  item_selector: '/rss/channel/item[wp:post_type="page"]'
  fields:
    -
      name: title
      label: 'Content title'
      selector: title
    -
      name: post_id
      label: 'Unique content ID'
      selector: 'wp:post_id'
    -
      name: content
      label: 'Body of the content'
      selector: 'content:encoded'
    -
      name: excerpt
      label: 'Excerpt of the content'
      selector: 'excerpt:encoded'
    -
      name: pubDate
      label: 'Publish date of the content'
      selector: pubDate
    -
      name: post_date
      label: 'Post date of the content'
      selector: 'wp:post_date'
    -
      name: status
      label: 'Published status of the content'
      selector: 'wp:status'
    -
      name: creator
      label: 'Username of the content creator'
      selector: 'dc:creator'
    -
      name: post_tag
      label: 'Tags assigned to the content item'
      selector: 'category[@domain="post_tag"]/@nicename'
    -
      name: category
      label: 'Categories assigned to the content item'
      selector: 'category[@domain="category"]/@nicename'
    -
      name: link
      label: 'The link value'
      selector: 'link'
  ids:
    post_id:
      type: integer
process:
  title:
    -
      plugin: get
      source: title
  body/value:
    -
      plugin: get
      source: content
  body/summary:
    -
      plugin: get
      source: excerpt
  created:
    -
      plugin: callback
      source: post_date
      callable: strtotime
  changed:
    -
      plugin: get
      source: '@created'
  status:
    -
      plugin: static_map
      source: status
      default_value: 0
      map:
        publish: 1
  uid:
    plugin: migration
    migration: wp_wordpress_wordpress_authors
    source: creator
  body/format:
    plugin: default_value
    default_value: basic_html
  type:
    plugin: default_value
    default_value: page
  path/pathauto:
    plugin: default_value
    default_value: 0
  alias:
    -
      plugin: get
      source: link
    -
      plugin: str_replace
      source: link
      search: 'https://myurl.com/'
      replace: '/'
destination:
  plugin: 'entity:node'
migration_dependencies:
  required:
    - wp_wordpress_wordpress_authors
1

Turns out path/alias worked. I must have been doing something wrong or my page was cached that it wasn't redirecting to the alias.

path/alias:
  -
    plugin: get
    source: link
  -
    plugin: str_replace
    source: link
    search: 'https://myurl.com/'
    replace: '/'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.