Problem/Motivation
I'm evaluating Smart Content. I am trying to add a segment but I get an AJAX error.
Here's the Chrome console error:
An AJAX HTTP error occurred.
HTTP Result Code: 200
Debugging information follows.
Path: /admin/structure/smart_content_segment_set/add?ajax_form=1
StatusText: parsererro
ResponseText: Warning: uasort() expects parameter 1 to be array, null given in /code/web/modules/contrib/smart_content/src/SegmentSet.php on line 157
Here's the visual behavior:
https://gyazo.com/2460e0641a2b870b5d395bae02551c8b
Steps to reproduce
The following modules are installed:
Smart Content
Smart Content A/B
Smart Content Block
Smart Content Browser
Smart Content Data Layer
Smart Content UTM
We are are not using LayoutBuilder.
Drupal 8.9.13.
Proposed resolution
n/a
Remaining tasks
n/a
User interface changes
n/a
API changes
n/a
Data model changes
n/a
Comments
Comment #2
capellicFormatting update.
Comment #3
capellicAdded Drupal version.
Comment #4
capellicThis patch only executes usort if $this->segments is defined. This allows me to add to get behind adding the segment set label.
Comment #5
capellicComment #6
mrosati commentedi kinda have the same error (see attachment):
* Drupal 9.1.7
* Version 3.0.0 of the module
The error happens whenever i try to create a new segment, however the attached patch does not have any effect in my case, i'm still unable to create a segment.
Comment #7
capellicHello @mrosati, I read the error. You're right, while this is an AJAX error it isn't the same as mine. The error my patch addresses targets the sorting of segments. I recommend opening up a separate ticket.
Comment #8
jucedogi commentedAs an FYI, I just encountered this issue with Drupal 9.3 running on PHP 8.
Tested on PHP 7.4 and form works properly with this version.
Logged error message seems to be the same as the one from the ResponseMessage:
TypeError: uasort(): Argument #1 ($array) must be of type array, null given in uasort() (line 157 of /code/web/modules/contrib/smart_content/src/SegmentSet.php)
So possibly code incompatibility with PHP8 it seems.
Comment #9
jucedogi commentedI revisited this due to a request to try out this module on a site I'm working on.
Same issue as before. Works on php 7.4 but not on 8.0.
After code review I came up with this patch.
The functionality of adding a segment seems to work now. Have yet to look into the rest of the module's functionality.
Comment #10
jucedogi commentedRemoved array type for class variable to remove the Typed properties are not supported in PHP 7.3 or earlier error.
Comment #11
jucedogi commentedComment #12
jucedogi commentedDid some changes so that phpunit tests passed locally.
Uploading new file to see how drupal's testbot sees it.
Comment #13
jucedogi commentedWell, that didn't seem to work. Leaving the previous one.
Comment #14
VirtualVasquez commentedI encountered the same AJAX error as well on Drupal 9.3.9 running on PHP 8.1.4.
Applying the smart_content-3210720-10.patch resolved the error. Functionality appears to have been restored.
Comment #15
aloknarwaria commentedThe patch attached work for me thanks
Comment #16
henry tran commentedThe patch works on our website using Drupal 9.5.3.
Thanks
Comment #17
marcusvsouza commentedI've tested the patch against the Drupal 9.3 version and works properly.
Comment #20
sonvir249 commentedComment #23
gantal commentedThe patch that was reviewed and tested by the community has been rolled in! The MR unfortunately has a lot of changes beyond the scope of this issue, so I'll go ahead and close it. Things like Drupal 10 compatibility are being addressed in separate issues (like #3298100: Automated Drupal 10 compatibility fixes)