Problem/Motivation
All the usages for new EditorDialogSave($values) is passing in $form_state->getValues(), but the phpdoc for the __construct() method and the $values property says it should be a string. That appears to be incorrect and it should typehint as an array.
/**
* An array of values that will be passed back to the editor by the dialog.
*
* @var string // But this just said above it would be an array???
*/
protected $values;
Method
__construct
Found usages (2 usages found)
web\core\modules\editor\src\Form (2 usages found)
EditorImageDialog.php (1 usage found)
EditorImageDialog (1 usage found)
submitForm (1 usage found)
232 $response->addCommand(new EditorDialogSave($form_state->getValues()));
EditorLinkDialog.php (1 usage found)
EditorLinkDialog (1 usage found)
submitForm (1 usage found)
85 $response->addCommand(new EditorDialogSave($form_state->getValues()));
Steps to reproduce
Proposed resolution
EditorDialogSave should typehint as an array
Remaining tasks
Review
User interface changes
NA
API changes
Add typehint to EditorDialogSave
Data model changes
NA
Release notes snippet
NA
Comments
Comment #2
dave reidComment #3
dave reidComment #4
dave reidComment #5
dave reidHere's the fix for Drupal 9, I think in order to not break backwards compatibility, the Drupal 8 patch should not include the typehint, but I don't know how any code would work without the value not being an array.
Comment #6
dave reidComment #7
xjmAnother "How do we typehint with BC?" issue. We're not able to make the typehint change in 9.0 at this point, and we need to figure out how we can add typehints with the continuous upgrade path.
Comment #8
dave reidI would think this is safe to fix no matter what just based on it was never supposed to work with strings.
Comment #10
abhijith s commentedPatch #5 cant be applied in 9.2.x.Need reroll.
Comment #11
abhijith s commentedRerolled patch #5 for 9.2.x.
Comment #12
guilhermevp commentedMakes sense to change, I agree with comment #8.
Comment #13
guilhermevp commentedSending D8 backport.
Comment #16
catchRestoring status after HEAD was broken.
Comment #17
larowlanIn terms of typehinting, https://3v4l.org/h9cYK shows that this doesn't break child implementations.
However, it might break calling code.
http://grep.xnddx.ru/search?text=new+EditorDialogSave&filename= shows there are some places where the return is not an array
http://grep.xnddx.ru/node/31368503 and http://grep.xnddx.ru/node/31370333 are two examples
So I think perhaps we should change the phpdoc only in D9, and then in D10, add a typehint.
Which means we need to trigger_error for a deprecation for anyone calling the constructor where $values is not an array.
Needs work for those changes
Comment #18
larowlanCrediting myself for trawling through 3 pages of contrib grep to find those two cases 👩💻
Comment #19
guilhermevp commentedTotally deserved!
Sending comment only patch.
Comment #22
smustgrave commentedSeems simple and makes sense after reading the ticket.
Comment #23
catch#19 looks OK for 9.5 at this point, however per #17 we need a (now 10.1.x) patch to @trigger_error('....', E_USER_DEPRECATED) when the constructor is called without an array, so that we can add the actual type hint in Drupal 11.
Also I haven't sent it for a retest because DrupalCI is having trouble, but the last green run on the patch was from 9.3.x, it's good to check things are green on both 9.5.x and 10.1.x (if they're eligible for both branches) before RTBCing.
Comment #24
smustgrave commentedYou mean something like this?
Comment #25
catchSo yes, but this should something like
'The $values parameter to ' . __METHOD___ . ' must be an array'so people know where the error has come from. Should be existing constructor deprecation examples in 9.5.x using __METHOD__ to copy (usually for missing arguments but this is similar enough).Comment #26
Ratan Priya commentedComment #27
Ratan Priya commented@catch,
I made the changes you required at comments #25
Needs review.
Comment #28
smustgrave commented@Ratan Priya can you please upload an interdiff if you're going to upload a patch please.
Comment #29
Ratan Priya commented@smustgrave,
Added interdiff against #27
Thankyou.
Comment #30
smustgrave commentedThank you!
Looking at #27 appears it's just missing the E_USER_DEPRECATED variable.
Example copied from core
@trigger_error('Passing a \'throw_exception\' option to ' . __METHOD__ . ' is deprecated in drupal:9.2.0 and is removed in drupal:10.0.0. Always catch exceptions. See https://www.drupal.org/node/3201187', E_USER_DEPRECATED);@catch do you want this ticket number in the comment?
Comment #31
Ratan Priya commented@smustgrave,
Made changes as per the example given in #30
needs review.
Comment #32
smustgrave commentedLooks good. Will let the test runner complete before marking RTBC.
Comment #33
smustgrave commentedDeprecation added per #25 looks good.
Comment #35
ameymudras commented- Retested the patch #31 and now it seems to pass.
- The issue summary is clear and describes the problem
- Code is simple and does the type change along with triggering a depreciation error as expected
Marking this issue as RTBC
Comment #36
alexpottThis deprecation message should say when we're going to fix this and add a typehint. I think it should be something like:
FWIW I'm not convince that this is ever called with a non-array anywhere by anything. Here's the code and docs that is triggered by this:
So we document that response.values is expected to be an array. There are other places in the JS code base where we expect an array here so I'm not 100% that this check is necessary. And maybe we could just add the typehint...
Comment #37
narendra.rajwar27Updating patch as suggested in comment #36
Comment #38
smustgrave commented@alexpott see what you are saying but would this just add an extra layer IF a string is passed. If never triggered maybe we can remove later down the line
Comment #40
shubham chandra commentedAdded patch against #37 in Drupal 10.1.x
Comment #41
bnjmnm@Shubham Sharma: Rerolls are not automatically needed if a Drupal dev branch version changes. In many cases, the patch still applies. If you click the "Add test / retest" link on the most recent patch of a given issue, you can test the patch on 10.1.x (or whatever the current dev branch is). If the patch applies there, then no reroll is needed.
You added a reroll that was not needed - I noticed you doing the same in at least 7 other recent issues. Credit is not granted for unnecessary rerolls.
Comment #42
smustgrave commentedReviewing #37 it appears to be adding the typehint already
(array $values) {Comment #44
scott_euser commentedAgreed, typehint is there, and what I can see in contrib modules like https://git.drupalcode.org/project/ckeditor5_embedded_content/-/blob/1.0... they are also passing arrays. Testing this patch and the contrib module also continues to work fine + PhpStorm stops complaining about the value as an array not matching the string hint. I believe this can be RTBC.
Comment #45
alexpottLet's add a parameter typehint while we're at it.
If we have the typehint then the deprecation is pointless because it will never occur.
I think in this instance adding the typehint is okay given the earlier comment.
Comment #47
scott_euser commentedUpdated as per feedback in #45. Hiding patches in favour of merge request.
Comment #48
smustgrave commentedFeedback appears to have been addressed.
Updated the issue summary slightly to use standard template.
Comment #49
longwaveCan't quite believe it took us four years to commit pretty much the original patch from #5, but here we are.
Not backported just in case this breaks some strange edge case somewhere, although you are probably doing something wrong if you run into this.
Committed d2d6d0c and pushed to 11.x. Thanks!