Problem/Motivation

When manually constructing a download url as the Media Entity Download project description explains:

$url = Url::fromRoute(
  'media_entity_download.download',
  [
    'media' => $media_id,
  ],
  [
    'query' => [
      'delta' => $delta,
    ],
  ]
);

The counter is not incremented.

Proposed resolution

Make the module more robust by replacing media_entity_download_count_file_access() (which is more of a hack/workaround than a solid solution) with a request event subscriber that triggers every time the media_entity_download.download route is visited. This way, there aren't any accidental increments when file access is checked. Also, because we have direct access to the media entity, the logic becomes a lot simpler.

This indirectly fixes the following issues as well:

User interface changes

None.

API changes

None.

Data model changes

None.

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

dieterholvoet created an issue. See original summary.

dieterholvoet’s picture

Issue summary: View changes
Status: Active » Needs review
vipin.mittal18’s picture

Status: Needs review » Fixed

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

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

Maintainers, credit people who helped resolve this issue.