Closed (fixed)
Project:
Modal
Version:
5.0.x-dev
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
15 Jan 2023 at 12:21 UTC
Updated:
2 Feb 2023 at 05:24 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #3
diegorsAdded the form validation to accept URL from YouTube in the formats:
Moving to NR.
Comment #4
jasjeet kaur brar commentedI applied the patch on Drupal version 9.5.1 with PHP 8.2, it's fixed the problem. Please check attachments.
Comment #5
renatog commentedGood catch @diegors! Thanks a lot
Thanks for the review @jasjeet-kaur-brar
I think on this case we could use
$this->t()that's right?Example:
$this->t('Invalid video YouTube URL'));Comment #6
atul_ghate commentedI will work on this
Comment #7
atul_ghate commentedThe patch has been rerolled, please review it
Comment #8
renatog commentedThank you so much team!
On this case we're using
#element_validateand technically this is used to validate this specific element (field) on form submitThe good side is that this is used to validate this field in all entities that this field is being applied
But in the other hand, this field will be used only on Modal entity so if we do this for all fields on Modal entity we'll have a lot of methods to validate all elements
Since this field will be used only on Modal entity, I recommend apply the validation inside of method validateForm as the other fields is being validated as well
Comment #9
diegorsMake sense @RenatoG, I will work on that.
Comment #10
diegorsI did changes as @RenatoG suggested in #8
Comment #11
renatog commentedThanks a lot @diegors
I recommend using
if (!empty($values['modal_video_link'])) {since the empty has more verifications, like, 0, NULL, FALSE, empty strings "", etcHere seems that there is a typo os char
Current:
Expected:
And the last (but not least):
I think we can create a separated method with this validation instead of putting the entire logic inside of "validateForm". This is because with the time, adding 10 validations for example this method will be huge and SonarQube will open points (because it recommends methods with few lines instead of long methods)
Recommendation:
Inside of validateForm call a helper, for example:
Helper class called: "ModalFieldValidationHelper.php"
Inside of this class have a method called: "validateVideoLink"
This method will have this logic on validation of "video link" and set the "setErrorByName" if necessary
So inside of validateForm we'll have only 1 line, E.g:
Is that makes sense?
Comment #12
diegorsThanks a lot @RenatoG, did the changes suggested in #11, but I created an
ModalFieldValidationServiceinstead of aModalFieldValidationHelperto pass to in the create method , I am not sure if that is ok, but here is my contribution.Comment #13
renatog commentedYeah, for sure! That's awesome!
The file name was just an example, your service is perfect
Comment #14
renatog commentedSmall adjustments:
Since will return "bool" the comment can be updated. Because says that will return
TRUEorNOinstead ofFALSENote that "U" of YouTube is also in Caps. I think can be something like:
Return TRUE if is a valid YouTube url, or FALSE otherwise.I'm putting the tag "Novice" since is a small adjustment
Comment #15
sahilgidwani commentedComment #16
sahilgidwani commentedI did changes @RenatoG suggested.
Comment #17
sahilgidwani commentedComment #18
renatog commentedIt's working fine! #RTBC
Comment #20
renatog commentedMoved to the dev branch 5.0.x
Thanks a lot @diegors for providing a great solution and thanks everyone for your contribution helping testing that as well
Great job!
Comment #21
sahilgidwani commented