\Drupal\editor\Ajax\EditorDialogSave::__construct() should typehint as an array instead of a string

Created on 2 December 2019, about 5 years ago
Updated 25 January 2024, 11 months ago

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

πŸ› Bug report
Status

Fixed

Version

11.0 πŸ”₯

Component
EditorΒ  β†’

Last updated 6 days ago

Created by

πŸ‡ΊπŸ‡ΈUnited States dave reid Nebraska USA

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

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Reviewing #37 it appears to be adding the typehint already (array $values) {

  • Status changed to RTBC about 1 year ago
  • πŸ‡¬πŸ‡§United Kingdom scott_euser

    Agreed, 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.

  • last update about 1 year ago
    29,722 pass
  • Status changed to Needs work about 1 year ago
  • πŸ‡¬πŸ‡§United Kingdom alexpott πŸ‡ͺπŸ‡ΊπŸŒ
    1. +++ b/core/modules/editor/src/Ajax/EditorDialogSave.php
      @@ -15,17 +15,20 @@ class EditorDialogSave implements CommandInterface {
         protected $values;
      

      Let's add a parameter typehint while we're at it.

    2. +++ b/core/modules/editor/src/Ajax/EditorDialogSave.php
      @@ -15,17 +15,20 @@ class EditorDialogSave implements CommandInterface {
      -  public function __construct($values) {
      +  public function __construct(array $values) {
      +    if (!is_array($values)) {
      +      @trigger_error('Calling \Drupal\editor\Ajax\EditorDialogSave::__construct with a non-array $values parameter is deprecated in drupal:10.1.0 and is removed from drupal:11.0.0.', E_USER_DEPRECATED);
      +    }
      

      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.

  • Status changed to Needs review 12 months ago
  • πŸ‡¬πŸ‡§United Kingdom scott_euser

    Updated as per feedback in #45. Hiding patches in favour of merge request.

  • Status changed to RTBC 12 months ago
  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Feedback appears to have been addressed.

    Updated the issue summary slightly to use standard template.

  • πŸ‡¬πŸ‡§United Kingdom longwave UK

    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!

  • Status changed to Fixed 11 months ago
    • longwave β†’ committed d2d6d0c1 on 11.x
      Issue #3098201 by Ratan Priya, guilhermevp, scott_euser, smustgrave,...
  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024