govCMS / GovCMS8

Current stable release of the main GovCMS8 distribution.
GNU General Public License v2.0
60 stars 58 forks source link

Linkit Module and Media items - direct link to file. #202

Open OPCIT opened 5 years ago

OPCIT commented 5 years ago

In order to get Linkit to work with Media items (files and images) make sure to create a new matcher:

Navigate to Configuration > Linkit > Default > Edit profile > Manage matchers > Add matcher • Select the ‘Media’ radio button, followed by ‘Save and continue’ • Check the ‘File’ and ‘Image’ checkboxes. • Select the ‘Save changes’ button.

Then follow the setup screenshots at #10 : https://www.drupal.org/project/linkit/issues/2926655

murraywoodman commented 5 years ago

I presume that the link created does link straight to the file. On more than one project this approach has caused problems where media editors update a Media File. ie. They upload a new version - same Media entity, new File. The end result is that a new file is created on the filesystem with a different URL.

If the original file URL is still in the HTML for a page, or indeed in a bookmark, the new version will never be seen. Old content continues to be served. It is therefore dangerous to link to the File direct if they are to be updated. Linking to the Media entity is one way to avoid this.

This is why we have used https://www.drupal.org/project/media_entity_download on some non GovCMS projects. This module provides a new URL media/x/download and will serve the resource through that URL. So if the underliying File changes, no worries, the new File will be picked up and served. ie. The updated version will be served.

When working with GovCS8, we have taken to sending all users to the Media page, /media/x and then redirecting client side to the resource. This is not ideal, but it does allow us to take a media centric view of the world and ensures that anon user does get the latest version. The downside is that the user ends up on the file page and this in turn can be bookmarked. The problem is not entirely avoided.

This is an important issue for clients who wish to ensure that the latest version of Media is guaranteed for users. eg. A PDF of terms and conditions, etc.

Personally, I'd like to see media_entity_download available to handle this kind of thing.

That said, I'd be interested to hear how others may be handling this issue.

OPCIT commented 5 years ago

I believe the link is still stored as 'media/123' in the node content, but when rendered the Linkit module filter translates it to the current file path associated with it that media entity.

Editing a media entity to update the file and using Linkit to to insert a media item (PDF) will ensure that no 404 is returned as the media asset ID never changes.

murraywoodman commented 5 years ago

Cool. Thanks for the clarification @OPCIT .

murraywoodman commented 5 years ago

Is sounds as though the PDF URL will be shown to the user, and that this URL will be used to download the resource. This URL can then be bookmarked and used later on, even when the Media has been updated. The advantage of a URL such as /media/X/download is that the user never sees the PDF URL and therefore they cannot bookmark something which may become obsolete.

simesy commented 5 years ago

In the version of govcms I'm looking at there is no media matcher, just a file matcher. Please see https://github.com/govCMS/govCMS8/pull/327

brett-sargeant commented 5 years ago

In the version of govcms I'm looking at there is no media matcher, just a file matcher. Please see #327

We've been adding one on our sites, similar to the OP instructions.

simesy commented 5 years ago

Yep I think things changed a bit, so if someone tried to add a "media" matcher today per OP there isn't one.

fubarhouse commented 5 years ago

Something like this?:

simesy commented 5 years ago

Yes but that's what is in https://github.com/govCMS/govCMS8/pull/327/files plus a patch on linkit.

AntoineOsanz commented 5 years ago

Thanks all, this PR is intended to be in the next release of GovCMS D8.