Fatal error: ome mandatory parameters are missing ("view_mode") to generate a URL for route "flag.action_link_flag"

Created on 23 January 2025, 4 months ago

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

πŸ› Bug report
Status

Active

Version

4.0

Component

Flag core

Created by

πŸ‡ΊπŸ‡ΈUnited States mark_fullmer Tucson

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @mark_fullmer
  • πŸ‡ΊπŸ‡ΈUnited States mark_fullmer Tucson
  • πŸ‡ΊπŸ‡ΈUnited States mark_fullmer Tucson

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

  • Status changed to Needs work 13 days ago
  • πŸ‡ΊπŸ‡ΈUnited States neclimdul Houston, TX

    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 I 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.

  • πŸ‡ΊπŸ‡ΈUnited States caesius

    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 πŸ› Compatibility with Flag 8.x-4.0-beta6 Active

Production build 0.71.5 2024