Update the ModalAjaxController::hookModalSubmit() to return JSON instead of int value

Created on 13 August 2023, 11 months ago
Updated 26 August 2023, 10 months ago

Problem/Motivation

Talked to @tguerineau at #3363861-6: undefined method Drupal\Core\Extension\ModuleHandler::getImplementations() β†’

Proposed resolution

Update the method to return a JSON
Update the Javascript to receive the new value

Remaining tasks

User interface changes

API changes

Data model changes

πŸ“Œ Task
Status

Fixed

Version

5.0

Component

Code

Created by

πŸ‡§πŸ‡·Brazil RenatoG Campinas

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

Comments & Activities

  • Issue created by @RenatoG
  • πŸ‡¦πŸ‡·Argentina tguerineau

    I've been working on addressing the issue as described, and here's a summary of the changes I made:
    - Updated ModalAjaxController::hookModalSubmit() to return a JSON response instead of integers: Instead of directly echoing TRUE or FALSE and exiting, I transitioned to using structured JSON responses. This approach provides more context on the outcome, whether it's a success or a failure, and offers additional information that can be helpful for debugging.

    - Modified the Ajax code in modal-page.js to correctly handle and act upon the new JSON response format. Error messages are now logged to the console for debugging purposes.

    Attached is the patch with the changes I've made. Feedback and further testing are appreciated!

  • Status changed to Needs review 10 months ago
  • πŸ‡§πŸ‡·Brazil RenatoG Campinas

    Thanks for the patch @tguerineau, let's review the code and test it

  • Status changed to Needs work 10 months ago
  • πŸ‡§πŸ‡·Brazil RenatoG Campinas

    It's working fine, just come points on phpcs

    FILE: modal_page/src/Controller/ModalAjaxController.php
    -------------------------------------------------------------------------------------------------------------------------------------
    FOUND 6 ERRORS AFFECTING 6 LINES
    -------------------------------------------------------------------------------------------------------------------------------------
     101 | ERROR | [x] Namespaced classes/interfaces/traits should be referenced with use statements
     104 | ERROR | [ ] The array declaration extends to column 85 (the limit is 80). The array content should be split up over multiple
         |       |     lines
     112 | ERROR | [ ] The array declaration extends to column 84 (the limit is 80). The array content should be split up over multiple
         |       |     lines
     118 | ERROR | [ ] The array declaration extends to column 108 (the limit is 80). The array content should be split up over multiple
         |       |     lines
     130 | ERROR | [x] Expected newline after closing brace
     136 | ERROR | [ ] The array declaration extends to column 115 (the limit is 80). The array content should be split up over multiple
         |       |     lines
    -------------------------------------------------------------------------------------------------------------------------------------
    PHPCBF CAN FIX THE 2 MARKED SNIFF VIOLATIONS AUTOMATICALLY
    -------------------------------------------------------------------------------------------------------------------------------------
    
    Time: 959ms; Memory: 14MB
  • Status changed to Needs review 10 months ago
  • πŸ‡§πŸ‡·Brazil RenatoG Campinas

    Adjusted phpcs

    • a1986122 committed on 5.0.x
      Issue #3380924 by renatog, tguerineau: Update the ModalAjaxController::...
  • Status changed to Fixed 10 months ago
  • πŸ‡§πŸ‡·Brazil RenatoG Campinas

    Moved to the dev branch. Thank you so much for your great job @tguerineau

  • πŸ‡§πŸ‡·Brazil RenatoG Campinas

    I think we can implement the same improvement on this other method to be consistent

  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.69.0 2024