Feature request: Ability to specify minimum image resolution for an image upload

Created on 17 December 2024, 5 days ago

When developing components, I frequently want to specify a minimum resolution for the source file. This might be useful when creating a hero component with a large background image.

Currently, there's no way to do this, but we should make it possible.

Feature request
Status

Active

Version

0.0

Component

Code

Created by

🇺🇸United States mherchel Gainesville, FL, US

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

Comments & Activities

  • Issue created by @mherchel
  • 🇧🇪Belgium wim leers Ghent 🇧🇪🇪🇺

    In order to not violate @lauriii's product requirements (nutshell version: "no XB-specific metadata in SDCs"), this would have to be expressed in SDC's metadata. Please move this to Drupal core's single-directory components issue queue component and link it from 📌 [SPIKE] Comprehensive plan for integrating with SDC Active 🙏😊

  • 🇫🇮Finland lauriii Finland

    I clarified the original product requirements with two principles that explain the original motivation in Allow developers to customize how components behave in XB Active .

    1. Components built for Experience Builder should work with Drupal Core without Experience Builder installed.
    2. Components built for Drupal Core should work with Experience Builder without additional changes.

    This doesn't mean that we couldn't add additional capabilities within XB, so long as it doesn't violate these principles.

    Image is already a capability that's specific to Experience Builder. Are we really blocked on core to make this change?

  • 🇧🇪Belgium wim leers Ghent 🇧🇪🇪🇺

    Allow developers to customize how components behave in XB Active is news to me. Responded there.

    Image is already a capability that's specific to Experience Builder. Are we really blocked on core to make this change?

    It isn't, not really. Literally all it relies upon is [PP-1] Allow schema references in Single Directory Component prop schemas Postponed .

  • 🇧🇪Belgium wim leers Ghent 🇧🇪🇪🇺

    But, taking a practical look, and without investigating whether this is how [PP-1] Allow schema references in Single Directory Component prop schemas Postponed currently works, but assuming we could make it work like this (unsure about it), I'd propose something like this:

    diff --git a/schema.json b/schema.json
    index 12d5c628..30a133d6 100644
    --- a/schema.json
    +++ b/schema.json
    @@ -200,11 +200,13 @@
             },
             "width": {
               "title": "Image width",
    -          "type": "integer"
    +          "type": "integer",
    +          "minimum": "0"
             },
             "height": {
               "title": "Image height",
    -          "type": "integer"
    +          "type": "integer",
    +          "minimum": "0"
             }
           }
         },
    diff --git a/tests/modules/sdc_test_all_props/components/all-props/all-props.component.yml b/tests/modules/sdc_test_all_props/components/all-props/all-props.component.yml
    index 43c5c9a1..c0c9c674 100644
    --- a/tests/modules/sdc_test_all_props/components/all-props/all-props.component.yml
    +++ b/tests/modules/sdc_test_all_props/components/all-props/all-props.component.yml
    @@ -198,11 +198,25 @@ props:
           $ref: json-schema-definitions://experience_builder.module/image
           # @todo Remove in https://www.drupal.org/project/drupal/issues/3352063 — should not be necessary, but removing this causes \Drupal\Core\Theme\Component\ComponentMetadata::parseSchemaInfo() to generate `type = ['', 'object'] 🐛
           type: object
    +      width:
    +        minimum: 500
           examples:
             - src: https://placehold.co/600x400.png
               alt: 'Boring placeholder'
               width: 600
               height: 400
    +    test_object_drupal_image_big:
    +      title: 'Object, $ref=json-schema-definitions://experience_builder.module/image, overridden minimum width'
    +      $ref: json-schema-definitions://experience_builder.module/image
    +      width:
    +        minimum: 1000
    +      # @todo Remove in https://www.drupal.org/project/drupal/issues/3352063 — should not be necessary, but removing this causes \Drupal\Core\Theme\Component\ComponentMetadata::parseSchemaInfo() to generate `type = ['', 'object'] 🐛
    +      type: object
    +      examples:
    +        - src: https://placehold.co/1000x400.png
    +          alt: 'BIG HERO IMAGE'
    +          width: 1000
    +          height: 400
     
         # The "date-range" object format for this module.
         test_object_drupal_date_range:
    

    WDYT? 😊

  • 🇫🇮Finland lauriii Finland

    I like the proposal in #5 🤩 Only problem I see with that is that I'm sure there would be a lot of people who'd want this behavior on regular media reference fields using images 😅

  • 🇧🇪Belgium wim leers Ghent 🇧🇪🇪🇺

    Great! 😄🥳

    It shouldn't matter where the image is coming from: an image field or a media field, or even an Instagram or Flickr photo — it's up to the individual field to then map these restrictions to corresponding validation constraints.

    (Prior art of exactly that: search the XB codebase for the string FileExtension, and you'll find a similar example for ensuring an image URI is a HTTP(S) URI pointing to an image.)

    Three things remain then:

    1. @mherchel confirming he also likes #5 🤞
    2. verifying that the reuse-but-override-subset of schema stuff is actually how JSON schema works 😅
    3. working PoC
  • 🇧🇪Belgium wim leers Ghent 🇧🇪🇪🇺
  • 🇺🇸United States mherchel Gainesville, FL, US

    @mherchel confirming he also likes #5 🤞

    So to confirm the component.yml will look something like this?

    test_object_drupal_image_big:
      title: 'My title'
      $ref: json-schema-definitions://experience_builder.module/image
      width:
        minimum: 1000
      height:
        minimum: 1000
     

    I'm also assuming this will be exposed in the upload/selection form so the editor can see the requirements?

    if so, this is fantastic! Thanks for working on this!

Production build 0.71.5 2024