Problem/Motivation

The most recent release, 8.x-4.0-beta6, introduced an issue that triggers a PHP fatal error with the output:

Symfony\Component\Routing\Exception\MissingMandatoryParametersException: Some mandatory parameters are missing ("view_mode") to generate a URL for route "flag.action_link_flag". in Drupal\Core\Routing\UrlGenerator->doGenerate() (line 187 of /app/web/core/lib/Drupal/Core/Routing/UrlGenerator.php).

Steps to reproduce

This was observed on a site running on Drupal 10.4.1 and PHP 8.3. More research is needed to see what other factors could contribute to this error (i.e., site configuration or custom code that no longer works?).

Proposed resolution

TBD

Remaining tasks

User interface changes

API changes

Data model changes

CommentFileSizeAuthor
#7 flag-add-view-mode-param.patch769 bytesrobin_rosh

Issue fork flag-3501854

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

mark_fullmer created an issue. See original summary.

mark_fullmer’s picture

Title: Fatal error: ome mandatory parameters are missing ("view_mode") to generate a URL for route "flag.action_link_flag" » Fatal error: some mandatory parameters are missing ("view_mode") to generate a URL for route "flag.action_link_flag"
mark_fullmer’s picture

Status: Active » Closed (works as designed)

This was an announced API change, per https://www.drupal.org/node/3458551 , in prior releases. Closing as "Works as designed."

neclimdul’s picture

Status: Closed (works as designed) » Needs work

I'm not sure announcing it in a changelog is enough.

First, its deprecated, not changed and 4.0 isn't out. So the expectation would be that deprecated code would continue to function issuing the warning to users.
`Not providing the "$view_mode" parameter is deprecated in flag:8.x-4.0-beta4 and will throw an error from flag:8.x-4.0. See https://www.drupal.org/node/3458551.`

Since it didn't, I just got a fatal error never having seen a deprecation. No chance to fix if I missed the changelog.

Second, the default code for generating links doesn't require a view mode and defaults to null.

  /**
   * Get the action link as a Link object.
   *
   * @param \Drupal\flag\FlagInterface $flag
   *   The flag entity.
   * @param \Drupal\Core\Entity\EntityInterface $entity
   *   The flaggable entity.
   * @param string|null $view_mode
   *   The flaggable entity view mode.
   *
   * @return \Drupal\Core\Link
   *   The action Link.
   */
  public function getAsLink(FlagInterface $flag, EntityInterface $entity, ?string $view_mode = NULL);

I haven't tested it yet but this would seem to trigger a fatal error when using the function as documented.

caesius’s picture

On one hand, it's a beta module so backward-incompatible changes can be expected.

On the other hand, is it really "works as expected" if it breaks other contrib modules? See #3507901: Compatibility with Flag 8.x-4.0-beta6

robin_rosh’s picture

I'm facing the same issue even after upgrading from 9.5 to 10.5, specifically with flag 5.0, also the flag functionality not working wherever i'm using. Could any one provide the solution in my case?

robin_rosh’s picture

StatusFileSize
new769 bytes

Fixes missing view_mode parameter in flag.action_link_flag and flag.action_link_unflag routes.
Prevents InvalidParameterException and PHP deprecation warnings after upgrading to Flag 5.x.
Patch tested and resolves issue #3501854.

ivnish’s picture

Assigned: mark_fullmer » Unassigned
Status: Needs work » Postponed (maintainer needs more info)

Folks, how to reproduce this? Do you use contrib or custom modules?

jacobsaw’s picture

I can confirm this is an issue when using a contrib module like Bookmarks. This code https://git.drupalcode.org/project/bookmarks/-/blob/1.0.x/src/Plugin/Blo... triggers the error "User error: Symfony\Component\Routing\Exception\InvalidParameterException: Parameter "view_mode" for route "flag.action_link_flag" must match "[^/]++" ("" given) to generate a corresponding URL.".

I could submit a patch to add the view mode to that module, but in this use case I would just be passing "default" anyway.

ivnish’s picture

Version: 8.x-4.x-dev » 5.x-dev
Assigned: Unassigned » ivnish
Status: Postponed (maintainer needs more info) » Active

  • ivnish committed 660427f1 on 5.x
    [#3501854] feat: Fatal error: some mandatory parameters are missing ("...
ivnish’s picture

Assigned: ivnish » Unassigned
Status: Active » Fixed

I changed the default viewmode to "default" to fix old contrib modules

Now that this issue is closed, please review the contribution record.

As a contributor, attribute any organization helped you, or if you volunteered your own time.

Maintainers, please credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

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