Configure Bynder Image to use DAT Preset selected by the user

Created on 3 April 2024, 9 months ago
Updated 21 June 2024, 6 months ago

Problem/Motivation

Hi community, I'm wondering if someone can help me figuring out how I can configure the Bynder Image display to consider the DAT Preset selected by the user.
I was able to use the custom transformation successfully but when I use the presets, it doesn't work.

I recorded this video to explain: https://www.loom.com/share/62f3a429105a4b3db05680d99a1ba823?sid=0e3fbae2...

I really appreciate any help you can provide.

✨ Feature request
Status

Fixed

Version

4.2

Component

Code

Created by

🇧🇷Brazil carolpettirossi Campinas - SP

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

Merge Requests

Comments & Activities

  • Issue created by @carolpettirossi
  • 🇧🇷Brazil carolpettirossi Campinas - SP
  • 🇧🇷Brazil carolpettirossi Campinas - SP

    Looking at how the module works, it seems that it saves the transformations from the URL. The problem is that the preset doesn't have transformations with the expected structure in the URL.

    So the preset format is:
    https://trinity.bynder.com/transform/1x1/d5033e2c-5171-47d7-8a33-c2b852e7a7f5/Beta-Gamma-Sigma-240405-036

    The custom transformation format is:
    https://trinity.bynder.com/transform/0e549895-f5f0-4f09-8c1d-6fa9e9f13179/Beta-Gamma-Sigma-240405-037?io=transform:crop,height:250,width:250,path:circle&focuspoint=0.4,0.26

    Note, there's no io param in the preset which breaks this part of the code in the BynderSearch class:

      public function getTransformations(string $url) {
        // Cannot use UrlHelper here, because Bynder uses the same query arg for
        // all transformations. E.g. ?io=transform:fo&io=filter:bar.
        if ($transformations = parse_url($url, PHP_URL_QUERY)){
          return $transformations;
        }
        return NULL;
      }
    

    Then on BynderFormatter, when rendering the media entity, the TRANSFORMATIONS_FIELD_NAME returns empty
    $media_entity->get(Bynder::TRANSFORMATIONS_FIELD_NAME)->isEmpty()

    Results in rendering the image with the default DAT config from the formatter, when in fact I'd like to use the preset.

    Any suggestions on how we can improve the module to allow Presets?

  • 🇧🇷Brazil carolpettirossi Campinas - SP

    It looks like when the media entity is created, we don't save the preset information:

              $media[] = $storage->create([
                'bundle' => $image_type->id(),
                $image_source_field => $bynder_info['id'],
                'name' => $bynder_info['name'],
                Bynder::TRANSFORMATIONS_FIELD_NAME => $transformation,
              ]);
    

    What's the best approach here? Saving it in the TRANSFORMATIONS_FIELD_NAME? or creating a new field?

  • 🇧🇷Brazil carolpettirossi Campinas - SP

    Updating this to a Feature Request since it doesn't seem that the module already supports DAT Preset.

  • 🇧🇷Brazil carolpettirossi Campinas - SP
  • Pipeline finished with Failed
    8 months ago
    Total: 181s
    #141109
  • Status changed to Needs review 8 months ago
  • 🇧🇷Brazil carolpettirossi Campinas - SP

    Can someone review the code I proposed in the MR?

    I'm basically suggesting we keep using TRANSFORMATIONS_FIELD_NAME to store the preset. When the URL has the transform/{preset}/{bynder_id} structure we save the transformation as preset:{preset_machine_name} and the when displaying it, we check for preset: before moving to the "default" approach.

    Attaching the patch for reference and composer usage

  • Status changed to Needs work 8 months ago
  • 🇸🇮Slovenia primsi

    Thanks for the MR and work. I tested the patch and added two comments.

    From my perspective, same field name is completely fine. Maybe others have different opinions :)

  • 🇧🇷Brazil carolpettirossi Campinas - SP

    @Primsi, I added another comment aside from the above to the MR.

    Please let me know how I can improve this MR and get this into a state where we can push to the module.

    Thanks,
    Carol

  • Pipeline finished with Failed
    8 months ago
    Total: 180s
    #150270
  • Status changed to RTBC 8 months ago
  • 🇧🇷Brazil carolpettirossi Campinas - SP

    @primsi, thanks for working on the MR and improving it. I tested and it works as expected with custom transformation and presets.

    Moving this to RTBC

  • Pipeline finished with Failed
    8 months ago
    Total: 188s
    #154469
  • Status changed to Needs work 8 months ago
  • 🇨🇭Switzerland berdir Switzerland

    This is failing tests.

  • Pipeline finished with Failed
    8 months ago
    Total: 279s
    #155497
  • Pipeline finished with Failed
    8 months ago
    Total: 199s
    #155521
  • Pipeline finished with Failed
    8 months ago
    Total: 207s
    #155531
  • Pipeline finished with Failed
    8 months ago
    Total: 194s
    #155539
  • Status changed to Needs review 8 months ago
  • 🇸🇮Slovenia primsi

    The ::submitForm() fails seems to be unrelated, but minor, so I fixed them here. The missing 'derivative' key one is related to this issue but it happens on non-image assets, so I just added an isset().

  • Pipeline finished with Success
    8 months ago
    Total: 192s
    #156363
  • Status changed to RTBC 8 months ago
  • 🇧🇷Brazil carolpettirossi Campinas - SP

    I've just tested the latest changes, and it's working as expected:

    - Can use the default transform base url
    - Can use a preset
    - Can use a custom transformation

  • Pipeline finished with Skipped
    6 months ago
    #193437
  • Status changed to Fixed 6 months ago
  • 🇨🇭Switzerland berdir Switzerland

    Merged this now.

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

Production build 0.71.5 2024