Blocks #3051251: Existing menu links show validation issues on migration (and ALL menu links pointing to node translations are invalid) if it will solved by menu link migration derivatives.

Problem/Motivation

For being able to properly migrate menu links (without depending on every content entities' migration), we should be able to create stub menu links.
Right now, this is blocked by the Route migrateprocess plugin, because it assumes that the $options variable it populates form the input value array is an array.

Proposed resolution

Before merging with $route['options], check whether the local $options variable is an array or not.

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

Issue fork drupal-3156083

Command icon 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

huzooka created an issue. See original summary.

huzooka’s picture

Assigned: huzooka » Unassigned
Status: Active » Needs review
huzooka’s picture

Title: Route migrate process plugin shoudn't assume that the $options variable is always an array » Route migrate process plugin shouldn't assume that the $options variable is always an array
wim leers’s picture

Status: Needs review » Needs work
  1. +++ b/core/modules/migrate/tests/src/Kernel/process/RouteTest.php
    @@ -25,6 +25,19 @@ class RouteTest extends KernelTestBase {
    +    // We have to set up the system.site since PAthProcessorForn::processInput
    

    🤓 PAthPath

    🤓 "set up the system.site" does not really make sense I think. It should either be "set up the system.site config" or "configure a front page".

  2. +++ b/core/modules/migrate/tests/src/Kernel/process/RouteTest.php
    @@ -48,141 +61,144 @@ public function testRoute($value, $expected) {
    +      // Valid internal link path and options.
    +      'Valid internal link path and options' => [
    ...
    +      // Valid internal link path and empty options.
    +      'Valid internal link path and empty options' => [
    

    👏 for using meaningful labels for test cases of a data provider.

    🙈 … but that means the comment is unnecessary — let's remove it!

  3. 🤔 Am I missing something or is there no new test case for now allowing options to not be an array? A failing test-only patch would prove me wrong 🤓
deepak goyal’s picture

Status: Needs work » Needs review
StatusFileSize
new8.72 KB
new1.04 KB

HI @Wim Leers
Updated patch please review.

mikelutz’s picture

Status: Needs review » Needs work

#6 only pulled out the comments specifically mentioned by @wimleer in #5, but there are several other similar comments among those test cases which should also be removed.

raman.b’s picture

Status: Needs work » Needs review
StatusFileSize
new8.1 KB
new8.8 KB
new2.48 KB

Addressed remaining pointers from #5

The last submitted patch, 9: 3156083-9-test-only.patch, failed testing. View results

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

quietone’s picture

Status: Needs review » Reviewed & tested by the community

Reviewing this and I wish there was a patch with just the new tests that did not include the changes to the array keys. There was just a lot of noise to deal with. I do prefer the string array keys but it was too many changes at one for me.

Anyway, the patch is fine, testing for an array before using a variable as an array is sensible. And the test covers the use case.

alexpott’s picture

Status: Reviewed & tested by the community » Needs review
+++ b/core/modules/migrate/src/Plugin/migrate/process/Route.php
@@ -127,7 +127,9 @@ public function transform($value, MigrateExecutableInterface $migrate_executable
+        if (is_array($options)) {
+          $route['options'] += $options;
+        }

+++ b/core/modules/migrate/tests/src/Kernel/process/RouteTest.php
@@ -48,141 +61,150 @@ public function testRoute($value, $expected) {
+      'Valid internal link path and non-array options' => [
+        'data' => [
+          'user/login',
+          'options',
+        ],
+        'expected' => [
+          'route_name' => 'user.login',
+          'route_parameters' => [],
+          'options' => [
+            'query' => [],
+          ],
+          'url' => NULL,
         ],

Here we set $options to a string. It feels odd to ignore this data. In the issue summary we say we need this stubbing. What is $route['options'] in this case - is it NULL? Because if so I think the fix should be something like

if ($options) {
  $route['options'] += $options;
}

or maybe the issue is with

    else {
      list($link_path, $options) = $value;
    }

if $value is ['some_path'] ... then $options is going to be NULL.

Maybe the better fix would be

    else {
      list($link_path, $options) = $value;
      $options = (array) $options;
    }
quietone’s picture

Status: Needs review » Needs work

Setting to NW to address the questions in #13

quietone’s picture

Issue tags: -migrate-d7-d9, -migrate-d7-d8

The route process plugin is not specific to Drupal 7 sources, removing tag.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

fjgarlin made their first commit to this issue’s fork.

fjgarlin’s picture

Patch was no longer applying to 11.x so I converted it into an MR with a really small change for it to apply.
Feedback from #13 still needs addressing.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.