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

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

capellic created an issue. See original summary.

capellic’s picture

Issue summary: View changes

Formatting update.

capellic’s picture

Issue summary: View changes

Added Drupal version.

capellic’s picture

StatusFileSize
new670 bytes

This patch only executes usort if $this->segments is defined. This allows me to add to get behind adding the segment set label.

capellic’s picture

Status: Active » Needs review
mrosati’s picture

StatusFileSize
new178.05 KB

i 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.

capellic’s picture

Hello @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.

jucedogi’s picture

As 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.

jucedogi’s picture

StatusFileSize
new1.1 KB

I 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.

jucedogi’s picture

StatusFileSize
new1.27 KB

Removed array type for class variable to remove the Typed properties are not supported in PHP 7.3 or earlier error.

jucedogi’s picture

jucedogi’s picture

StatusFileSize
new3.68 KB

Did some changes so that phpunit tests passed locally.
Uploading new file to see how drupal's testbot sees it.

jucedogi’s picture

Well, that didn't seem to work. Leaving the previous one.

VirtualVasquez’s picture

Status: Needs review » Reviewed & tested by the community

I 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.

aloknarwaria’s picture

The patch attached work for me thanks

henry tran’s picture

The patch works on our website using Drupal 9.5.3.
Thanks

marcusvsouza’s picture

I've tested the patch against the Drupal 9.3 version and works properly.

sonvir249 made their first commit to this issue’s fork.

sonvir249’s picture

Status: Reviewed & tested by the community » Needs review

  • gantal committed 178886aa on 3.x authored by jucedogi
    Issue #3210720 by sonvir249, jucedogi, capellic, mrosati, VirtualVasquez...

gantal’s picture

Status: Needs review » Fixed

The 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)

Status: Fixed » Closed (fixed)

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