Skip to content

Conversation

@hans2103
Copy link
Contributor

@hans2103 hans2103 commented Nov 7, 2025

Pull Request for no issue

Summary of Changes

This PR will add a subform to plugin media-action/crop to give you the option to configure your own aspect-ratios.
With this PR merged I am able to create a own set of aspect ratios.

Testing Instructions

  • Go To System > Plugins > Media-Action = Crop and notice the lack of options

  • Go To Content > Media ... select the three dots of an image and press "Edit". Open the dropdown at Aspect-Ratio and notice the presence of a pre-defined set of aspect-ratios

  • Apply the PR

  • npm run build:js to compile newly added js

  • Go To System > Plugins > Media-Action = Crop and notice the availability of an aspect-ratio-calculator and a subform to add / remove / edit aspect-ratio options. Add, remove and edit aspect ratios as you add them in css too... using 16 / 9, numbers with a slash

  • Save the changes

  • Go To Content > Media ... select the three dots of an image and press "Edit". Open the dropdown at Aspect-Ratio and notice the changed set of aspect ratios

Actual result BEFORE applying this Pull Request

Screenshot 2025-11-07 at 11 37 04 Screenshot 2025-11-07 at 11 37 31

Expected result AFTER applying this Pull Request

Screenshot 2025-12-02 at 10 33 51 Screenshot 2025-12-02 at 10 34 27

Link to documentations

Please select:

  • Documentation link for docs.joomla.org:

  • No documentation changes for docs.joomla.org needed

  • Pull Request link for manual.joomla.org:

  • No documentation changes for manual.joomla.org needed

@joomla-cms-bot joomla-cms-bot added Language Change This is for Translators NPM Resource Changed This Pull Request can't be tested by Patchtester PR-6.1-dev labels Nov 7, 2025
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request adds configurable aspect ratios to the media crop plugin, allowing administrators to customize the available aspect ratio options through the plugin settings instead of being limited to hard-coded values.

Key Changes:

  • Added a subform configuration in the plugin XML to allow administrators to define custom aspect ratios with labels, values (in fraction or decimal format), and optional grouping (landscape/portrait)
  • Implemented onContentPrepareForm method to dynamically inject custom aspect ratios into the crop form
  • Updated JavaScript to parse aspect ratio values in both fraction format (e.g., "16/9") and decimal format (e.g., "1.5")

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 11 comments.

Show a summary per file
File Description
plugins/media-action/crop/src/Extension/Crop.php Adds form preparation logic to inject custom aspect ratios and return type declarations for loadJs/loadCss methods
plugins/media-action/crop/form/crop.xml Updates default aspect ratio values from decimal to fraction format (e.g., "1.3333..." to "4/3")
plugins/media-action/crop/crop.xml Adds configuration fieldset with subform for defining custom aspect ratios and references layouts folder
build/media_source/plg_media-action_crop/js/crop.es6.js Adds parseAspectRatio function to handle both fraction and decimal aspect ratio formats
administrator/language/en-GB/plg_media-action_crop.ini Adds language strings for the new aspect ratio configuration options

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

label="PLG_MEDIA-ACTION_CROP_RATIO_VALUE"
description="PLG_MEDIA-ACTION_CROP_RATIO_VALUE_DESC"
required="true"
pattern="([1-9]\d*/[1-9]\d*|[1-9]\d*)"
Copy link

Copilot AI Nov 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The regex pattern ([1-9]\d*/[1-9]\d*|[1-9]\d*) doesn't allow decimal values like "0.5" or "1.5" which the JavaScript parseAspectRatio function can handle via parseFloat(). Additionally, it doesn't allow single-digit values like "1" without additional digits. Consider updating the pattern to allow both fraction and decimal formats, e.g., ([1-9]\d*/[1-9]\d*|\d+\.?\d*) or (\d+/\d+|\d+\.?\d+) if you want to support zero-based values.

Suggested change
pattern="([1-9]\d*/[1-9]\d*|[1-9]\d*)"
pattern="(\d+/\d+|\d+\.?\d*)"

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not want to support zero-based values.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not want to support zero-based values.

that means you don't allow such values:

				<option class="crop-aspect-ratio-option" value="0.8">4:5</option>
				<option class="crop-aspect-ratio-option" value="0.75">3:4</option>
				<option class="crop-aspect-ratio-option" value="0.6666666666666667">2:3</option>
				<option class="crop-aspect-ratio-option" value="0.5625">9:16</option>

this options are all zero based.

I think we shouldn't force people to use the 1/2 since they might already get a 0.xyz value from another place and just want to copy paste it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we shouldn't force people to use the 1/2 since they might already get a 0.xyz value from another place and just want to copy paste it.

@HLeithner for real?
That is exactly what you suggested to do 4 days ago. Using a / to calculate implies adding as such too.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You miss understand me, it's not a you MUST use x/y it's an optional thing. both should work. If I like to use 0.35 then that should be possible. But normally I would expect the more readable x/y variant.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@HLeithner at this moment Joomla does not allow to configure any aspect ratios. This PR provides a solution that people can configure aspect ratios. At first I added a calculator to create the required value for the aspect ratios.
After your suggestion, which was very valid, I have removed the calculator and moved the calculation of the required value to javascript. People just have to enter the aspect ratio as if they add it in css too..... with a slash between the two numbers.

This PR as it is right now works like a charm. If other kind of input is needed for better UI, please create a new PR when this is merged and adjust it. But please... continue with the PR as it is right now.

@bembelimen
Copy link
Contributor

Hello @hans2103 ,
thanks for your contribution. I think the feature you want to add is a valid use case, but please allow me to give my personal feelings about that PR (and please take it not personal, that are my feelings):

It's a bit annoying to have to review vibe coding. If I see what correction Brian suggested and all this "small" mistakes. At the end it means, you saved some time for yourself and created a lot of new work for the reviewers. If you would have once reviewed and fixed the stuff by yourself it would have saved a lot of maintainer time. Also this AI generated blob at the end is just a waste of time for everyone reading it.

I don't mind using AI to solve problems, but I would really like to see at least a review from yourself before the PR is created, don't push the work load to the maintainer.

@hans2103
Copy link
Contributor Author

hans2103 commented Dec 1, 2025

@bembelimen you're welcome for my attribution. Your personal feelings are not taken personal. But do keep in mind that I have reviewed the code myself too. But... I've been working on it for some time now and almost at the point of just giving up, convert it to a personal plugin and closing the PR. It just takes too much time to add a simple idea. Every new person inspecting the code has a new opinion on it. I will press "commit suggestion" as Copilot suggested and leave it as is.

hans2103 and others added 7 commits December 1, 2025 15:23
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Ensures that aspect ratio values are properly escaped when added as attributes to XML elements.

This prevents potential issues with special characters in the values, enhancing the robustness of the crop functionality.
@hans2103
Copy link
Contributor Author

hans2103 commented Dec 2, 2025

@rdeutz @chmst Thank you both for the thumbs up in the comment of @bembelimen
Could you both take some time to test this PR so it can be merged into Joomla core?

@brianteeman
Copy link
Contributor

Usually language string keys are in the form _LABEL and _DESC. I woujld prefer it if you maintained this (undocumented) practice.

So for example
PLG_MEDIA-ACTION_CROP_RATIO_LABEL
PLG_MEDIA-ACTION_CROP_RATIO_LABEL_DESC

becomes
PLG_MEDIA-ACTION_CROP_RATIO_DESC
PLG_MEDIA-ACTION_CROP_RATIO_LABEL

@hans2103
Copy link
Contributor Author

hans2103 commented Dec 2, 2025

@brianteeman thank you... I've added _LABEL to each key in the subform making it consistent with the (undocumented) practice

Copy link
Member

@HLeithner HLeithner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

allow 0.35 and 1.35 beside 1/2 and 2/1 as value.

@hans2103
Copy link
Contributor Author

hans2103 commented Dec 2, 2025

allow 0.35 and 1.35 beside 1/2 and 2/1 as value.

This PR only handles numerator / denominator to make implementation and understanding easier. (by your request even)

Please create a new PR for that if you like.
It implies a complete refactor of the current javascript I am proposing in this PR.

@HLeithner
Copy link
Member

allow 0.35 and 1.35 beside 1/2 and 2/1 as value.

This PR only handles numerator / denominator to make implementation and understanding easier. (by your request even)

Please create a new PR for that if you like. It implies a complete refactor of the current javascript I am proposing in this PR.

not really only need to change the regex and the description for the field the rest works already as it should. Btw. I tested the pr and it works fine.

@hans2103
Copy link
Contributor Author

hans2103 commented Dec 2, 2025

allow 0.35 and 1.35 beside 1/2 and 2/1 as value.

This PR only handles numerator / denominator to make implementation and understanding easier. (by your request even)
Please create a new PR for that if you like. It implies a complete refactor of the current javascript I am proposing in this PR.

not really only need to change the regex and the description for the field the rest works already as it should. Btw. I tested the pr and it works fine.

can you create a PR on my PR with your suggestion?

hans2103 and others added 4 commits December 2, 2025 14:27
Co-authored-by: Allon Moritz <allon.moritz@digital-peak.com>
Co-authored-by: Allon Moritz <allon.moritz@digital-peak.com>
Co-authored-by: Allon Moritz <allon.moritz@digital-peak.com>
@laoneo
Copy link
Member

laoneo commented Dec 2, 2025

I have tested this item ✅ successfully on e7ff28e

Remove some options and added a new one. Worked as expected. I think some cleanup like the regex can be done on a second step when needed.


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/46421.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Language Change This is for Translators NPM Resource Changed This Pull Request can't be tested by Patchtester PR-6.1-dev RTC This Pull Request is Ready To Commit

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants