joomla-cms icon indicating copy to clipboard operation
joomla-cms copied to clipboard

Fix image selection in media field

Open bembelimen opened this issue 5 years ago • 7 comments

Summary of Changes

When creating a 3rd party filesystem plugin and selecting an image in a media file selection (e.g. in the article form view), the image will not be displayed, because the variable is wrong.

Testing Instructions

  • Apply patch
  • Run npm
  • Install a 3rd party media filesystem plugin (like: https://github.com/bembelimen/joomla-cms/tree/4.1/media-manager ) and select an image in a media field.

Actual result BEFORE applying this Pull Request

  • Image not selected/displayed

Expected result AFTER applying this Pull Request

  • Image selected/displayed

@dgrammatiko perhaps you can check?

bembelimen avatar Nov 29 '20 00:11 bembelimen

Is thump_path always the same as the url? If so then remove it in the Media manager Api, but I think that thump is for a thumbnail provided by some cloud storage providers (s3, dropbox)

dgrammatiko avatar Nov 29 '20 12:11 dgrammatiko

Is thump_path always the same as the url? If so then remove it in the Media manager Api, but I think that thump is for a thumbnail provided by some cloud storage providers (s3, dropbox)

No, but that is not the fix here. Thumbpath is for non local adapters. This fix is the call, when someone either insert an image into the editor (via the image plugin) or uses the image media field (like the intro image). In this case only the "url" is relevant. I search the whole Joomla for Joomla.selectedMediaFile.thumb which is never used, I assume, that is is a leftover or a typo?

So the value filled in has to be Joomla.selectedMediaFile.url to functional.

bembelimen avatar Nov 29 '20 19:11 bembelimen

So the value filled in has to be Joomla.selectedMediaFile.url to functional.

Yes, you're right. FWIW the thumb part shouldn't be there but rather in https://github.com/joomla/joomla-cms/blob/acb3b6d66582d6b3467731680b4813536eccf53e/build/media_source/system/js/fields/joomla-field-media.w-c.es6.js#L159-L187 something like:

updatePreview() {
  if (['true', 'static'].indexOf(this.preview) === -1 || this.preview === 'false' || !this.previewElement) {
    return;
  }

  // Reset preview
  if (this.preview) {
    const { value } = this.inputElement;

    if (!value) {
      this.previewElement.innerHTML = '<span class="field-media-preview-icon"></span>';
    } else {
      let thumb = Joomla.selectedMediaFile.url;
      this.previewElement.innerHTML = '';
      const imgPreview = new Image();

      if (Joomla.selectedMediaFile.thumb) {
        thumb = Joomla.selectedMediaFile.thumb;
      }

      const mediaType = {
        image() {
          imgPreview.src = /http/.test(thumb) ? thumb : Joomla.getOptions('system.paths').rootFull + thumb;
          imgPreview.setAttribute('alt', '');
        },
      };

      mediaType[this.type]();

      this.previewElement.style.width = this.previewWidth;
      this.previewElement.appendChild(imgPreview);
    }
  }
}

dgrammatiko avatar Nov 29 '20 19:11 dgrammatiko

Is this on hold or should it still be tested?

brianteeman avatar Apr 02 '21 22:04 brianteeman

Can a maintainer please set the label "Conflicting Files"?

ghost avatar Jun 09 '21 12:06 ghost

This should be already fixed by now

dgrammatiko avatar Feb 03 '22 16:02 dgrammatiko

This pull request has automatically rebased to 4.2-dev.

HLeithner avatar Jun 27 '22 13:06 HLeithner

What should we do with this PR @bembelimen @dgrammatiko

rdeutz avatar Oct 21 '22 10:10 rdeutz

If https://github.com/joomla/joomla-cms/pull/38805 is merged then also local adapters would have a thumb so this PR would break the other one.

dgrammatiko avatar Oct 21 '22 11:10 dgrammatiko