Problem/Motivation

Add API documentation to the MenuLinkParent process plugin.

Proposed resolution

In #15 phenaproxima pointed out the the plugin is out of date and needs 'sprucing up'. That work was done in this patch. Some of the changes (Haven't read the whole issue) include general cleaning up and support for external URIs.

Remaining tasks

Tests. A list was given in #44 of the tests that are needed. When you write a test please strike it off the list here.

  • The menu link is a root item.
  • The parent ID exists.
  • The parent ID did not exist, but was stubbed.
  • The parent ID did not exist and couldn't be stubbed.
  • The parent ID did not exist, could not be stubbed, and the parent link path/menu name were not passed. (This should result in a MigrateSkipRowException.)
  • The parent ID did not exist, could not be stubbed, and the parent link path is external and could be loaded.
  • The parent ID did not exist, could not be stubbed, and the parent link path is external and could not be loaded. (Should result in a MigrateSkipRowException.)
  • The parent ID did not exist, could not be stubbed, and the parent link path is an internal URI that exists and could be loaded.
  • The parent ID did not exist, could not be stubbed, and the parent link path is an internal URI that doesn't exist. (Should result in a MigrateSkipRowException.)


Create a follow up for this TODO in MuenLinkParent, "Introduce a new exception to be thrown if stubbing fails or is disallowed, and catch that instead"

User interface changes

API changes

Data model changes

Release notes snippet

CommentFileSizeAuthor
#97 2845485-97.patch14.82 KBquietone
#97 diff-94-97.txt598 bytesquietone
#94 2845485-94.patch14.82 KBquietone
#94 interdiff-90-94.txt736 bytesquietone
#90 2845485-90.patch14.8 KBquietone
#90 interdiff-88-90.txt938 bytesquietone
#88 2845485-88.patch14.79 KBquietone
#88 interdiff-86-88.txt1.18 KBquietone
#86 2845485-86.patch14.76 KBquietone
#86 interdiff-84-86.txt2.48 KBquietone
#84 2845485-84.patch15.97 KBquietone
#84 interdiff-82-84.txt1.81 KBquietone
#82 2845485-82.patch16.34 KBquietone
#82 interdiff-80-82.txt1.12 KBquietone
#80 2845485-80.patch16.4 KBquietone
#80 interdiff-77-80.txt7.44 KBquietone
#77 2845485-77.patch15.1 KBquietone
#77 interdiff-73-77.patch840 bytesquietone
#73 2845485-73.patch15.17 KBquietone
#73 diff-71-8.9.x-73-9.1.x.txt13.04 KBquietone
#72 2845485-71.patch16.19 KBquietone
#71 interdiff-68-71.txt724 bytesquietone
#68 interdiff-67-68.txt1.85 KBquietone
#68 2845485-68.patch16.19 KBquietone
#68 interdiff-67-68.txt1.85 KBquietone
#67 2845485-67.patch16.21 KBquietone
#67 interdiff-65-67.txt4.84 KBquietone
#65 interdiff-64-64.txt4.66 KBquietone
#65 2845485-65.patch16.32 KBquietone
#64 2845485-64.patch15.68 KBquietone
#64 interdiff-62-64.txt863 bytesquietone
#62 2845485-62.patch15.8 KBquietone
#62 diff-58-62.txt18.54 KBquietone
#58 2845485-58.patch15.73 KBvacho
#53 2845485-53.patch15.71 KBquietone
#53 interdiff-50-53.txt5.18 KBquietone
#50 2845485-50.patch14.67 KBjofitz
#49 2845485-49.patch8.23 KBjofitz
#47 2845485-47.patch12.17 KBjofitz
#47 interdiff-2845485-45-47.patch1.32 KBjofitz
#45 2845485-45-complete.patch12.19 KBjofitz
#45 2845485-45-test_only.patch4.04 KBjofitz
#37 interdiff-2845485-32-37.txt1.77 KBmasipila
#37 2845485-37.patch8.15 KBmasipila
#33 interdiff-2845485-27-32.txt4.72 KBmasipila
#33 2845485-32.patch8.53 KBmasipila
#27 2845485-27.patch8.05 KBjofitz
#27 interdiff-19-27.txt876 bytesjofitz
#25 2845485-25.patch15.29 KBpk188
#23 2845485-23.patch15.29 KBpk188
#19 interdiff-2845485-17-19.txt6.89 KBphenaproxima
#19 2845485-19.patch8.1 KBphenaproxima
#17 interdiff-2845485-13-17.txt4.25 KBphenaproxima
#17 2845485-17.patch5.4 KBphenaproxima
#13 2845485-13.patch1.8 KBjofitz
#13 interdiff-8-13.txt1.15 KBjofitz
#8 2845485-8.patch1.73 KBjofitz
#8 interdiff-2-8.txt2.76 KBjofitz
#6 2845485-6.patch2.76 KBjofitz
#6 interdiff-2-6.txt2.76 KBjofitz
#2 2845485-1.patch2.18 KBquietone
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

quietone created an issue. See original summary.

quietone’s picture

Status: Active » Needs review
FileSize
2.18 KB
phenaproxima’s picture

Assigned: Unassigned » phenaproxima

Self-assigning for review.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

phenaproxima’s picture

Assigned: phenaproxima » Unassigned
Status: Needs review » Needs work
  1. +++ b/core/modules/migrate/src/Plugin/migrate/process/MenuLinkParent.php
    @@ -15,7 +15,28 @@
    + * Determines the menu link parent plugin IDs.
    

    For people who don't understand that menu links are plugins, this will be extraordinarily confusing. I think we should strike all mentions of plugin IDs. Let's change this, then, to something like "Determines the parent of a menu link."

    Ideally, we should also link to documentation that explains how menu links work in D8.

  2. +++ b/core/modules/migrate/src/Plugin/migrate/process/MenuLinkParent.php
    @@ -15,7 +15,28 @@
    + * The menu_link_parent process plugin figures out menu link parent plugin IDs.
    

    This sentence adds nothing. Let us be rid of it.

  3. +++ b/core/modules/migrate/src/Plugin/migrate/process/MenuLinkParent.php
    @@ -15,7 +15,28 @@
    + * The source is an array of three values:
    + *   - parent_id: The parent link ID (plid) is the mlid of the link above in the hierarchy, or zero if the link is at the top level in its menu.
    + *   - menu_name: The menu name. All links with the same menu name (such as 'navigation') are part of the same menu.
    + *   - parent_link_path: The Drupal path or external path this link points to.
    

    These lines exceed 80 characters.

    Can we re-word the parent_id description to "The numeric ID of the parent menu link, or 0 if the link is at the top level of its menu"?

    In the parent_link_path description, "external path" should be "external URL".

  4. +++ b/core/modules/migrate/src/Plugin/migrate/process/MenuLinkParent.php
    @@ -15,7 +15,28 @@
    + * @code
    + * process:
    + *   parent:
    + *     plugin: menu_link_parent
    + *     source:
    + *       - plid
    + *       - menu_name
    + *       - parent_link_path
    + * @endcode
    

    This example needs to be explained.

  5. +++ b/core/modules/migrate/src/Plugin/migrate/process/MenuLinkParent.php
    @@ -64,9 +85,24 @@ public static function create(ContainerInterface $container, array $configuratio
    -   * {@inheritdoc}
        *
        * Find the parent link GUID.
    +   * Performs the associated process.
    +   *
    +   * @param string $value
    +   *   The input string.
    +   * @param \Drupal\migrate\MigrateExecutableInterface $migrate_executable
    +   *   The migration in which this process is being executed.
    +   * @param \Drupal\migrate\Row $row
    +   *   The row from the source to process.
    +   * @param string $destination_property
    +   *   The destination property currently worked on. This is only used together
    +   *   with the $row above.
    +   *
    +   * @return string
    +   *   The sub string of $value.
    +   *
    +   * @throws \Drupal\migrate\MigrateSkipRowException
    

    This should be {@inheritdoc}.

jofitz’s picture

Status: Needs work » Needs review
FileSize
2.76 KB
2.76 KB

Changes in response to code review.

Status: Needs review » Needs work

The last submitted patch, 6: 2845485-6.patch, failed testing.

jofitz’s picture

FileSize
2.76 KB
1.73 KB

Here's the correct patch from #6.

gaurav.kapoor’s picture

Status: Needs work » Needs review

Checked the patch in #8 and it as per suggestions given in #5.So marking it for review , so that it can be tested.

gaurav.kapoor’s picture

Status: Needs review » Reviewed & tested by the community
phenaproxima’s picture

Assigned: Unassigned » phenaproxima
Status: Reviewed & tested by the community » Needs review

I'd like to take another look at this before we jump ahead with RTBC.

phenaproxima’s picture

Status: Needs review » Needs work
  1. +++ b/core/modules/migrate/src/Plugin/migrate/process/MenuLinkParent.php
    @@ -15,7 +15,33 @@
    + * The source is an array of three values:
    + *   - parent_id: The numeric ID of the parent menu link, or 0 if the link is at
    + *     the top level of its menu.
    + *   - menu_name: The menu name. All links with the same menu name (such as
    + *     'navigation') are part of the same menu.
    + *   - parent_link_path: The Drupal path or external URL this link points to.
    

    These will need to be outdented to be flush with the first line.

  2. +++ b/core/modules/migrate/src/Plugin/migrate/process/MenuLinkParent.php
    @@ -15,7 +15,33 @@
    + * In this example the parent_id of '20' will be looked up and returned from
    + * amongst the already migrated IDs. If it is not found then the
    

    This is a little unclear because it is directly referring to something that is done by the migration plugin, not this one. We should probably include a link, at least, to the migration plugin's documentation.

    Also, I notice that the plugin's transform() method throws a MigrateSkipRowException if it falls all the way through. That needs to be documented.

jofitz’s picture

Status: Needs work » Needs review
FileSize
1.15 KB
1.8 KB

I have addressed #12.1 and documented the MigrateSkipRowException (I hope this is what you meant, @phenaproxima).

As for #12.2 - the example is an adapted version of that in d*_menu_links which does indeed involve the migration plugin, but I would argue that this example does not. I'm struggling to explain this any more clearly than I did the first time, so I am open to any guidance.

prash_98’s picture

The patch applies well and also the required documentation have been added. So I guess that it can be changed to RTBC.

phenaproxima’s picture

Status: Needs review » Needs work

I took a closer look at the MenuLinkParent plugin and it's pretty far out of date; for example, it tries to catch a MigrateSkipRowException that is no longer thrown. I need the entire plugin needs sprucing up in addition to better documentation, so I think we should expand the scope of this issue and fix it up in here.

jofitz’s picture

Status: Needs work » Needs review

While removing the MigrateSkipRowException try-catch I discovered that is is still required because Migration::transform() can throw the exception if the 'no_stub' property of the migration destination is set to true (see modules/migrate/src/Plugin/migrate/process/Migration.php:124 which leads to modules/migrate/src/Plugin/Migration.php:400). I hope that makes some sense (happy to discuss in IRC)!

I can't see anything else in the plugin that needs sprucing up, but let me know if you have something specific in mind, @phenaproxima.

Setting back to Needs Review (in hope of RTBC).

phenaproxima’s picture

Title: Add documentation to MenuLinkParent process plugin » Refactor and document the MenuLinkParent process plugin
FileSize
5.4 KB
4.25 KB

Sorry -- I had to refactor the plugin a bit. It's out of date and confusing, I couldn't help myself.

I made the following changes:

1) Added a skip_row configuration option to control whether or not the plugin throws MigrateSkipRowException. The decision really shouldn't be up to the plugin at all -- if someone wants to skip the row, they should put a skip_on_empty in the process pipeline. However, to maintain BC, I added this option and defaulted it to TRUE.

2) Got rid of the try-catch block. The migration process plugin does not throw MigrateSkipRowException unless it receives an empty value, which this plugin guarantees will not happen. Therefore the try-catch has no purpose.

3) Various other bits and pieces.

Status: Needs review » Needs work

The last submitted patch, 17: 2845485-17.patch, failed testing.

phenaproxima’s picture

Status: Needs work » Needs review
Issue tags: +Needs issue summary update
FileSize
8.1 KB
6.89 KB

Okay, this should fix the broken tests.

I have streamlined things a little bit by making MenuLinkParent directly extend the Migration process plugin (aliased here as Lookup for clarity). I also restored the try-catch that I removed in #17 -- a path already well-trodden by @Jo Fitzgerald, but one I had to grok for myself -- and added a comment explaining it.

Additionally, I added support for external URIs. At the moment, MenuLinkParent doesn't know what to do if the parent_link_path is an external URI; it'll probably just fail with an InvalidArgumentException, thrown by Url::fromUserInput(). I made it more graceful; it will attempt to look up an existing link with that same external URI before falling through. It's a backwards-compatible change, so I'm not sure it'll need a change record...?

jofitz’s picture

A very minor nit-pick, but perhaps Migration could be aliased as MigrationLookup (rather than just Lookup) because that's what it'll be called once #2845486: Rename Migration process plugin and add documentation is in.

phenaproxima’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests

Just realized that we'll need tests of the external URI handling.

heddn’s picture

Issue tags: +Needs reroll

Migration process plugin was renamed to migration_lookup. Needs re-roll.

pk188’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll
FileSize
15.29 KB

Re rolled.

Status: Needs review » Needs work

The last submitted patch, 23: 2845485-23.patch, failed testing.

pk188’s picture

Status: Needs work » Needs review
FileSize
15.29 KB
jofitz’s picture

@pk188 Please can you explain the changes to core/lib/Drupal/Core/Database/Driver/pgsql/Schema.php ?

jofitz’s picture

Assigned: phenaproxima » Unassigned
FileSize
876 bytes
8.05 KB
pk188’s picture

quietone’s picture

Status: Needs review » Needs work
+++ b/core/modules/migrate/src/Plugin/migrate/process/MenuLinkParent.php
@@ -2,38 +2,67 @@
+ * Determines the parent of a menu link.
...
+ * The source is an array of three values:
+ * - parent_id: The numeric ID of the parent menu link, or 0 if the link is at

What? The description says it determines the parent of a menu link, but then one of the source values is the parent link menu. I don't know much about menu links but this is a bit confusing.

In #5.1, phenaproxima suggested adding a link to documentation that explains how menu links work in D8. Maybe I missed it, but I don't see such a link.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

masipila’s picture

Assigned: Unassigned » masipila

I'll have a look at this in the near future.

masipila’s picture

Assigned: masipila » Unassigned

Here's a patch with suggested improvements to the API documentation.

A couple of questions to @phenaproxima:

1. Is your idea that this TODO item should be addressed under this same issue or as a follow-up?

     catch (MigrateSkipRowException $e) {
-
+      // There are two reasons the exception may have been thrown. Either the
+      // input value was empty -- definitely not the case, since we checked for
+      // that at the top of this method -- or the lookup tried to stub the
+      // parent menu link, but the destination's configuration has 'no_stub' set
+      // to TRUE. In this latter case, we'll just act as if the lookup failed,
+      // and fall back to looking for the parent link using the combination of
+      // menu name  and  parent link path.
+      //
+      // TODO: Introduce a new exception to be thrown if stubbing fails or is
+      // disallowed, and catch that instead.
+      $parent_id = NULL;
+    }

2. And the same question for this

+    // TODO: Remove this behavior and the skip_row configuration option.
+    if (!empty($this->configuration['skip_row'])) {
+      throw new MigrateSkipRowException();
     }
-    throw new MigrateSkipRowException();
+    return NULL;

Cheers,
Markus

masipila’s picture

Apparently I forgot to attach the files to the previous comment...

masipila’s picture

Issue tags: +API Documentation
phenaproxima’s picture

I think we should probably address both in this issue. We're already refactoring the hell out of MenuLinkParent, so I see no reason not to attack those TODOs now.

masipila’s picture

Assigned: Unassigned » masipila

Self assigning.

masipila’s picture

Assigned: masipila » Unassigned
FileSize
8.15 KB
1.77 KB

Here's a new version trying to address #32.2.

  • The 'skip_row' configuration option was added in #19 i.e. it is not in the current codebase.
  • I could not see why it was added in #19 with the TODO comment to remove it, so maybe @phenaproxima can elaborate the background a bit.

For the #32.1

  • Did I understand correctly @phenaproxima that you are suggesting that we would create a new exception that we could throw in MigrationLookup?
  • So instead of throwing MigrateSkipRowException MigrationLookup would through a new exception that we would catch here?
  • I read through the MigrationLookup::transform() and with the comments that we have on this issue and in the patch TODO comments could not figure out the details... @phenaproxima, could you elaborate this as well?

Cheers,
Markus

Edit: formatting

quietone’s picture

Decided to run the tests. Had a read through and everything seems done except one item, about a new Exception. It is the second item in #37, where there is a question directed to phenaproxima.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

joelpittet’s picture

[error] The internal path component 'https://example.com/publications.html' is external. You are not allowed to specify an external URL together with internal:/.''

Which is coming from MenuLinkParent because of the assumption that the parent link path is routeable through $url = Url::fromUserInput("/$parent_link_path");

The patch doesn't resolve this but does touch this class and line so I thought I'd mention it and hopefully I can resolve in another issue. Just and FYI

giorgio79’s picture

Wild idea: why not treat Menu Link Parents via the content system and use an entity reference field? Similar to taxonomy parent table removal at #2543726: Make $term->parent behave like any other entity reference field, to fix REST and Migrate support and de-customize its Views integration given menus were already converted to entities to use fieldability? #916388: Convert menu links into entities

joelpittet’s picture

I moved my issue to it's own thing with a patch to avoid mudding up this one.
#2968170: MenuLinkParent breaks migration when Parent URI is external

phenaproxima’s picture

Status: Needs work » Needs review
phenaproxima’s picture

Status: Needs review » Needs work

The documentation here is excellent. Really nice and clear. It's also easy to follow the logic of the plugin -- these are significant improvements.

+++ b/core/modules/migrate/src/Plugin/migrate/process/MenuLinkParent.php
@@ -52,51 +94,76 @@ public function __construct(array $configuration, $plugin_id, $plugin_definition
+        $url = Url::fromUserInput('/' . ltrim($parent_link_path, '/'));

Don't we need to prefix the URL with internal:/?

Other than that, this needs dedicated tests of each possible path through the plugin:

  • The menu link is a root item.
  • The parent ID exists.
  • The parent ID did not exist, but was stubbed.
  • The parent ID did not exist and couldn't be stubbed.
  • The parent ID did not exist, could not be stubbed, and the parent link path/menu name were not passed. (This should result in a MigrateSkipRowException.)
  • The parent ID did not exist, could not be stubbed, and the parent link path is external and could be loaded.
  • The parent ID did not exist, could not be stubbed, and the parent link path is external and could not be loaded. (Should result in a MigrateSkipRowException.)
  • The parent ID did not exist, could not be stubbed, and the parent link path is an internal URI that exists and could be loaded.
  • The parent ID did not exist, could not be stubbed, and the parent link path is an internal URI that doesn't exist. (Should result in a MigrateSkipRowException.)
jofitz’s picture

Here's the beginning of the tests. I don't have time to finish this now, but maybe someone else can take up the baton?

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

jofitz’s picture

Corrected the mis-named data provider. Still requires plenty more tests.

quietone’s picture

@Jo Fitzgerald, go go go! I would love to see this finished.

jofitz’s picture

Patch from #47 no longer applies. Re-rolled.

jofitz’s picture

Status: Needs work » Needs review
FileSize
14.67 KB

Failed to incorporate test file in #49 patch. This is a re-roll of the patch in #47.

jofitz’s picture

Status: Needs review » Needs work

NW for remaining tests.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

quietone’s picture

Issue summary: View changes
Status: Needs work » Needs review
FileSize
5.18 KB
15.71 KB

This is the the only issue that didn't get finished in the push to get all the process plugins docuemented. In the hopes of making progress I've added a test case and some comments. Not sure the test is correct since I don't know this area very well.

quietone’s picture

Issue summary: View changes
Issue tags: -Needs issue summary update

fix formatting in the IS

heddn’s picture

Did we update the list of tests in the IS that are now covered or is that still needed?

  1. +++ b/core/modules/migrate/src/Plugin/migrate/process/MenuLinkParent.php
    @@ -2,38 +2,70 @@
    + * Menu link item belongs to a menu such as 'Navigation' or 'Administration'.
    + * Menu link item also has a parent item unless it is the root element of the
    + * menu.
    

    These phrases could be combined into a more simple single sentence.

  2. +++ b/core/modules/migrate/src/Plugin/migrate/process/MenuLinkParent.php
    @@ -52,51 +94,76 @@ public function __construct(array $configuration, $plugin_id, $plugin_definition
    +      // that at the top of this method -- or the lookup tried to stub the
    +      // parent menu link, but the destination's configuration has 'no_stub' set
    ...
    +      // TODO: Introduce a new exception to be thrown if stubbing fails or is
    +      // disallowed, and catch that instead.
    

    This TODO either needs to be removed (my preference) or an issue opened.

heddn’s picture

Status: Needs review » Needs work
Issue tags: -Needs tests

Cleaning up tags and bumping back to NW.

quietone’s picture

Issue tags: +Needs reroll

Needs a reroll.

vacho’s picture

Only patch reroll by now.

Ghost of Drupal Past’s picture

I think extending a plugin instead of calling to it diminishes the value of process plugin being plugins -- one could replace the migration_lookup plugin class with their own for their own needs and the callers would be oblivious to it. By extension a tight coupling is introduced which doesn't seem necessary to me.

vacho’s picture

Issue tags: -Needs reroll

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

quietone’s picture

Status: Needs work » Needs review
FileSize
18.54 KB
15.8 KB

Working on a reroll.

Status: Needs review » Needs work

The last submitted patch, 62: 2845485-62.patch, failed testing. View results

quietone’s picture

Status: Needs work » Needs review
FileSize
863 bytes
15.68 KB

The process plugin needs to implement ContainerFactoryPluginInterface.

quietone’s picture

A few tweaks for testing.

dww’s picture

Status: Needs review » Needs work

Mostly this looks great, thanks! Definitely agree all this could use some clean-up and help. :)

Mostly nit picks, but this includes a few things of substance, so setting NW...

  1. +++ b/core/modules/migrate/src/Plugin/migrate/process/MenuLinkParent.php
    @@ -7,17 +7,50 @@
    + * Menu link item belongs to a menu such as 'Navigation' or 'Administration'.
    ...
    + *       - admin
    ...
    + * determine the parent by a combination of 'admin' menu name and
    

    Originally, we call the menu name "Administration". Then in the example code, we have just 'admin', which we (sort of) explain. It's a bit of a confusing example, since the menu link path also starts with 'admin', and folks might think that's what's going on (especially if they skim or don't read the fine print).

    Could we use an example from a 'Main navigation' ('main') menu, so that there's no overlap between the menu machine name and the link path?

  2. +++ b/core/modules/migrate/src/Plugin/migrate/process/MenuLinkParent.php
    @@ -7,17 +7,50 @@
    + * @see https://www.drupal.org/docs/8/api/menu-api
    

    Ooof, I know there's talk of restructuring d.o doc links to remove the 8 vs. 9 part of these paths, since the 9 vs. 8 handbooks are going to be so overlapping. I wonder how many @see links we already have like this. :/ I wonder what's the alternative.

  3. +++ b/core/modules/migrate/src/Plugin/migrate/process/MenuLinkParent.php
    @@ -103,7 +140,6 @@ public function __construct(array $configuration, $plugin_id, $plugin_definition
    -    $migration_configuration['migration'][] = $migration->id();
    

    I haven't read all the comments in the thread, but I don't see this line being added back elsewhere...

  4. +++ b/core/modules/migrate/src/Plugin/migrate/process/MenuLinkParent.php
    @@ -142,9 +180,24 @@ public function transform($value, MigrateExecutableInterface $migrate_executable
    +        // combination of menu name  and  parent link path.
    

    extra spaces around 'and' here.

    Otherwise, LOVE how thorough and helpful this comment is!

  5. +++ b/core/modules/migrate/src/Plugin/migrate/process/MenuLinkParent.php
    @@ -142,9 +180,24 @@ public function transform($value, MigrateExecutableInterface $migrate_executable
    +        // TODO: Introduce a new exception to be thrown if stubbing fails or is
    

    Should this be a formal @todo? Is there already an open issue about this? If not, can we file it and include a link to it with this comment?

  6. +++ b/core/modules/migrate/src/Plugin/migrate/process/MenuLinkParent.php
    @@ -152,25 +205,32 @@ public function transform($value, MigrateExecutableInterface $migrate_executable
    +    // Parent could not be determined by ID so we try to determine by the
    

    Wants a comma after "ID" before "so".

  7. +++ b/core/modules/migrate/tests/src/Unit/process/MenuLinkParentTest.php
    @@ -56,44 +65,58 @@ protected function setUp() {
    +   * @param string|array $source_value
    

    If this is a string or array of strings, @param string|string[] would be better. We can almost always do better than array as a @param type.

  8. +++ b/core/modules/migrate/tests/src/Unit/process/MenuLinkParentTest.php
    @@ -56,44 +65,58 @@ protected function setUp() {
    +    [$parent_id, $menu_name, $parent_link_path] = $source_value;
    

    Looks like $source_value is always treated as an array of strings...

    so the above should probably just be @param string[] $source_value.

  9. +++ b/core/modules/migrate/tests/src/Unit/process/MenuLinkParentTest.php
    @@ -56,44 +65,58 @@ protected function setUp() {
    +    $plugin->transform([$parent_id, $menu_name, $parent_link_path], $this->migrateExecutable, $this->row, 'destinationproperty');
    

    On first glance, not clear why we're converting this back into an array manually. Why not just:

    $plugin->transform($source_value, ...) ?

  10. +++ b/core/modules/migrate/tests/src/Unit/process/MenuLinkParentTest.php
    @@ -56,44 +65,58 @@ protected function setUp() {
    +   * Provides data for the MenuLinkParentTest.
    

    That's not the test this provides data for.

  11. +++ b/core/modules/migrate/tests/src/Unit/process/MenuLinkParentTest.php
    @@ -56,44 +65,58 @@ protected function setUp() {
    +      // The parent ID did not exist, could not be stubbed, and the parent link
    +      // path is external and could not be loaded.
    +      'test one' => [
    

    A) In all cases, "The parent ID did not exist, could not be stubbed". Why repeat that every time? Can't we comment that once at the start and say it holds for all the examples?

    Once we do that, the part that's different for each case could be listed as the array key, so we wouldn't need comments at all. E.g.:

    'external path' => [...],
    'no menu name' => [...],
    'internal path does not exist' => ...
    

    (or something).

  12. +++ b/core/modules/migrate/tests/src/Unit/process/MenuLinkParentTest.php
    @@ -56,44 +65,58 @@ protected function setUp() {
    +      // The parent ID did not exist, could not be stubbed, and the parent link
    +      // path/menu name were not passed.
    +      'test two' => [
    +        'source_value' => [1, NULL, 'http://drupal.org'],
    +      ],
    

    Looks like only the menu name isn't passed. Not sure why this is talking about "the parent link path/" in the comment. Maybe we don't need comments at all (see above), but if we keep them, can we simplify this to only mention the menu name?

  13. +++ b/core/modules/migrate/tests/src/Unit/process/MenuLinkParentTest.php
    @@ -110,18 +133,84 @@ public function testLegacyTransformExternal() {
    +   * @param string|array $source_value
    +   *   The source value(s) for the migration process plugin.
    

    As above. This should be @param string[] $source_value.

  14. +++ b/core/modules/migrate/tests/src/Unit/process/MenuLinkParentTest.php
    @@ -110,18 +133,84 @@ public function testLegacyTransformExternal() {
    +   * @param string|array $expected_result
    +   *   The expected value(s) of the migration process plugin.
    

    Looking at the provider, this is always a string. If it handles an array, it's not clear how. wouldn't transform() always return a single string, not an array? If it does take an array, it should be string[].

  15. +++ b/core/modules/migrate/tests/src/Unit/process/MenuLinkParentTest.php
    @@ -110,18 +133,84 @@ public function testLegacyTransformExternal() {
    +      // The menu link is a root item.
    +      'menu link is route item' => [
    ...
    +      // The parent ID exists.
    +      'parent id exists' => [
    ...
    +      // The parent ID exists and is external.
    +      'parent id exists external' => [
    

    These keys are self-documenting. Not sure we also need to replicate them as comments.

Thanks again!
-Derek

quietone’s picture

Status: Needs work » Needs review
FileSize
4.84 KB
16.21 KB

Thanks for the timely review!

Addressing the low hanging fruit from #66. Fixes for 4, 5, 6, 7, 10, 13, 14, 15

todo: 1, 2, 3, 9, 11, 12

quietone’s picture

1. Used menu_name 'navigation' since that is the name of the menu in the Drupal7 fixture for link_path 'admin/structure'.
2. There doesn't seem to be anything to do here for this?
3. This was removed #17 when phenaproxima did some refactoring because the plugin was out of date.
9, 11 and 12 Fixed.

Hopefully, that will tidy this up a bit and pass tests. Still to do is make that all the test cases in the IS are covered.

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

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

dww’s picture

Status: Needs review » Needs work
Related issues: +#3131567: Introduce a new exception if stubbing fails or is disallowed

Fantastic. Thanks for opening #3131567: Introduce a new exception if stubbing fails or is disallowed

One very tiny remaining nit:

+++ b/core/modules/migrate/src/Plugin/migrate/process/MenuLinkParent.php
@@ -142,9 +180,24 @@ public function transform($value, MigrateExecutableInterface $migrate_executable
+        // @todo Introduce a new exception to be thrown if stubbing fails or is
+        // disallowed. https://www.drupal.org/node/3131567

From what I've seen, the core convention for these is something like this:

    // @todo In https://www.drupal.org/node/3131567 introduce a
    //   new exception to be thrown if stubbing fails or is disallowed.

I'm composing this in dreditor, not emacs, so I'm not sure that's wrapped correctly, but hopefully you get the idea. ;) Key points:

a) Start with "In [link]"
b) Subsequent lines for the same @todo should be indented 2 spaces

Otherwise, this seems RTBC to me. Thanks again!

quietone’s picture

Issue summary: View changes
FileSize
724 bytes

@dww, thanks for the vote of confidence but I think the tests still need work. All the cases in the IS are not covered.

For #70 I fixed the spacing but left the text as is. I did that because the @todo: To Do notes section in the standard does not specify that format and what is here is similar to the example given on that page.

quietone’s picture

Uploading the patch will help.

quietone’s picture

Status: Needs work » Needs review
FileSize
13.04 KB
15.17 KB

And now a version for 9.1.x. I redid the test a bit to make it clearer what is happening (at least for me). I retained testTransformExternal but added a data provider to it. There is one test for external links, testTransformExternal, and on for internal links, testMenuLinkParent, and a helper added to do the common setup and run the final assertion.

quietone’s picture

There is one path in menu_link_parent that is not tested, which is;

        $url = Url::fromUserInput('/' . ltrim($parent_link_path, '/'));
        if ($url->isRouted()) {
          $links = $this->menuLinkManager->loadLinksByRoute($url->getRouteName(), $url->getRouteParameters(), $menu_name);
        }

And that is because the url is always not routed and thus fails this test. How to test that?

quietone’s picture

Issue summary: View changes
mikelutz’s picture

Status: Needs review » Needs work

#74 Seems like a bug, or at least a code smell. Url::fromUserInput() will always return an unrouted internal:// url. I don't see why we need/have that code path, as I don't believe it can be executed.

quietone’s picture

Status: Needs work » Needs review
FileSize
840 bytes
15.1 KB

@mikelutz, thanks. This is an area I know little about. This patch removes that block of code from the source plugin.

Status: Needs review » Needs work

The last submitted patch, 77: 2845485-77.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

mikelutz’s picture

Hmm, interesting. I guess I need to dig into it a little further.

quietone’s picture

Status: Needs work » Needs review
FileSize
7.44 KB
16.4 KB

OK, this restores that block of code. And I figured out what needs to be done to test it. Yea! This patch does that and does some cleanup as well.

quietone’s picture

Issue summary: View changes

Add strikethrough to the relevant test in the list in the IS.

quietone’s picture

The MenuLinkParent process plugin is now using the migrate.lookup service not the migration_lookup process plugin it was when this issue was created. The service does not create stubs it just does the lookup, therefor all references to stub can be removed.

dww’s picture

Status: Needs review » Needs work

Looking good. A few final concerns:

  1. +++ b/core/modules/migrate/src/Plugin/migrate/process/MenuLinkParent.php
    @@ -99,10 +135,13 @@ public static function create(ContainerInterface $container, array $configuratio
    +    // Handle root elements of a menu.
         if (!$parent_id) {
           // Top level item.
    

    Why do we need both of these comments for the same early return?

  2. +++ b/core/modules/migrate/tests/src/Unit/process/MenuLinkParentTest.php
    @@ -55,44 +66,210 @@ protected function setUp(): void {
    +   * Provides data for testTransformException.
    ...
    +   * Provides data for testMenuLinkParent.
    

    Core isn't totally consistent, but seems to use () at the end of function names in comments like this.

  3. +++ b/core/modules/migrate/tests/src/Unit/process/MenuLinkParentTest.php
    @@ -55,44 +66,210 @@ protected function setUp(): void {
    +  /**
    +   * Provides data for testMenuLinkParent.
    +   */
    +  public function providerTransformExternal() {
    +    return [
    +      // The parent ID does not exist and the parent link path is external and
    +      // could be loaded.
    +      'test' => [
    +        'source_value' => [9054, 'admin', 'http://example.com'],
    +        'lookup_result' => NULL,
    +        'plugin_id' => 'menu_link_content:fe151460-dfa2-4133-8864-c1746f28ab27',
    +        'expected_result' => 'menu_link_content:fe151460-dfa2-4133-8864-c1746f28ab27',
    +      ],
    +    ];
    +  }
    

    Seems slightly weird to go through the trouble of a data provider when there's only 1 test case. I guess it's "good plumbing for later" but I wonder about YAGNI.

    If we keep it, the comment points to the wrong test function, and we should add ().

  4. +++ b/core/modules/migrate/tests/src/Unit/process/MenuLinkParentTest.php
    @@ -55,44 +66,210 @@ protected function setUp(): void {
    +  /**
    +   * Provides data for testMenuLinkParent.
    +   */
    +  public function providerMenuLinkParenInternal() {
    +    return [
    +      'no parent id internal route' => [
    +        'source_value' => [20, 'admin', 'admin/content'],
    +        'lookup_result' => NULL,
    +        'plugin_id' => 'system.admin_structure',
    +        'expected_result' => 'system.admin_structure',
    +      ],
    +    ];
    +  }
    

    I believe all this is dead code. If not, typo in the function name.

Almost RTBC. :)

Thanks!
-Derek

quietone’s picture

Status: Needs work » Needs review
FileSize
1.81 KB
15.97 KB

Thanks for the quick review.

1. Fixed.
2. Fixed.
3. Comment fixed. I made a provider because I wasn't sure if other test cases will be needed. Maybe a review would point out one I missed?
4. Yes, it is dead. It has been removed.

dww’s picture

Re: #84: Thanks for the fixes! Looking really close now.

Re: #84.3: I'd feel a lot better RTBC'ing if we added a 2nd case to that provider. Not sure what else makes sense for testing an external menu parent. If we truly can't think of any other cases to test for that, I'd advocate undoing the provider and just let it be a simple test case with a single case. A provider for 1 case seems like a wonky precedent to set for core tests. Of course, what I think doesn't matter as much as what the core committers think. ;) /shrug

quietone’s picture

Ok. How about this, I moved that single test into providerMenuLinkParent() and removed testTransformExternal().

dww’s picture

Status: Needs review » Needs work

Yeah, that's much better, thanks! However, with that change:

+++ b/core/modules/migrate/tests/src/Unit/process/MenuLinkParentTest.php
@@ -55,44 +66,160 @@ protected function setUp(): void {
+   * Tests menu link content process plugin when the parent is an internal link.

This comment is no longer true. :/

Sorry,
-Derek

quietone’s picture

Status: Needs work » Needs review
FileSize
1.18 KB
14.79 KB

Oh fudge. At the risk of making another error I changed the summary link of both of the tests. And then I found an unused use statement.

@dww, Thanks for you patience.

dww’s picture

Thanks for catching that the other test summary was wrong.

If we're going to go this far, we should use proper sentences for these. ;)

  1. +++ b/core/modules/migrate/tests/src/Unit/process/MenuLinkParentTest.php
    @@ -77,7 +76,7 @@ protected function setUp(): void {
    +   * Tests an exception is thrown when the parent menu link is not found.
    

    "Tests that an ..."?

    Or maybe:

    "Tests which exception ..."?

  2. +++ b/core/modules/migrate/tests/src/Unit/process/MenuLinkParentTest.php
    @@ -116,7 +115,7 @@ public function providerTransformException() {
    +   * Tests menu link content process plugin.
    

    Tests the menu ...

quietone’s picture

OK. ... I am reminded of the poor grades I got in English (my first and only language) classes many years ago.

dww’s picture

Status: Needs review » Reviewed & tested by the community

Sorry about the reminder. ;)

Nothing left to complain about, RTBC! 🎉

Thanks for your patience and perseverance...

alexpott’s picture

This one bit has me a bit confused...

+++ b/core/modules/migrate/src/Plugin/migrate/process/MenuLinkParent.php
@@ -7,16 +7,49 @@
+ * - parent_link_path: The Drupal path or external URL this menu link points to.

parent_link_path - I think this should be The Drupal path or external URL the parent of this menu link points to.

alexpott’s picture

Status: Reviewed & tested by the community » Needs review

Setting back to needs review for #92 - if I'm wrong this can be set back to rtbc.

quietone’s picture

Yea, this is interesting. The process plugin is only provided information about the parent not the child so which link is 'this menu link'? Any way, the change suggested does bring that line into accord with the rest of the documentation.

dww’s picture

Status: Needs review » Reviewed & tested by the community

Interdiff in #94 addresses #92. Sorry I missed that in earlier reviews. Back to RTBC.

Thanks!
-Derek

catch’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs reroll

Needs a re-roll.

quietone’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll
FileSize
598 bytes
14.82 KB

Simple reroll.

heddn’s picture

Status: Needs review » Reviewed & tested by the community

And back to RTBC.

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed and pushed 244ccb2863 to 9.1.x. Thanks!

I considered backporting to 9.1.x but since this mixes documentation and code changes I felt that this was unnecessary. I'm pretty sure that the code changes are safe but been caught out in the past so not taking the risk.

  • alexpott committed 244ccb2 on 9.1.x
    Issue #2845485 by quietone, jofitz, phenaproxima, masipila, vacho, dww,...

Status: Fixed » Closed (fixed)

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