Problem/Motivation

token_node_menu_link_submit() creates the menu link entity ahead of time so that menu-parents tokens can be generated for pathauto.
If the node being saved is not the default revision, we flag the menu link as such too.
However, for new menu links this results in token generation that generates a plugin not found exception, because the menu tree has not been updated (because the menu link is a draft).

Steps to reproduce

  1. Create a new node-type
  2. Setup a pathauto pattern for the node-type with [node:menu-link:parents:join-path]/[node:title]
  3. Enable content-moderation for the given node-type
  4. Create a new draft node and place it in the menu
  5. 💥

Proposed resolution

Catch plugin not found exception and return.

Remaining tasks

Tests

User interface changes

API changes

Data model changes

Release notes snippet

CommentFileSizeAuthor
#2 3113991-draft.patch837 byteslarowlan

Issue fork token-3113991

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

larowlan created an issue. See original summary.

larowlan’s picture

Issue summary: View changes
Status: Active » Needs review
StatusFileSize
new837 bytes

this seems to prevent it from blowing up

Status: Needs review » Needs work

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

ngkoutsaik’s picture

Hi,

I reviewed the issue and run the steps to get the error. I am not certain if I misunderstood but I get a different error.

Drupal\Core\Entity\EntityStorageException: The requested context was not found in the supplied array of contexts. in Drupal\Core\Entity\Sql\SqlContentEntityStorage->save() (line 846 of core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php).

I also applied the patch, which applied cleanly, but the issue still repeats.

amykhailova’s picture

I'm on 8.x-1.7 and it seems that it's not an issue anymore. I have followed your steps and cannot reproduce the error.

mohit_aghera’s picture

I noticed similar issues for the different scenario where I changed content from archived to published state.

Steps to reproduce:
- Content is archived and it doesn't have any menu link
- When we change content form archived to published state or review state and add a new link from the node edit form, the link is not created when it tries to create instance.

The issue seems with the following code in function "token_node_menu_link_submit()"

 if ($needs_save) {
      $entity->isDefaultRevision($node->isDefaultRevision());
      $entity->save();

      $node->menu_link = $entity;
      // Leave this for _menu_ui_node_save() to pick up so we don't end up with
      // duplicate menu-links.
      $form_state->setValue(['menu', 'entity_id'], $entity->id());
    }

since when we move to "needs review", it might not be the default revision for the node.
Eventually it fails.

I think following check should address the issue.

    if ($needs_save) {
      if (!$node->isDefaultRevision() && $entity->isNew()) {
        $entity->isDefaultRevision(TRUE);
      }
      else {
        $entity->isDefaultRevision($node->isDefaultRevision());
      }
      $entity->save();

      $node->menu_link = $entity;
      // Leave this for _menu_ui_node_save() to pick up so we don't end up with
      // duplicate menu-links.
      $form_state->setValue(['menu', 'entity_id'], $entity->id());
    }

Adding a MR with the fix.