-
-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cannot assign null to property nystudio107\similar\services\Similar::$preOrder of type array|string #49
Comments
If I had to guess, probably |
The code snippet I shared above lives on an entry page, so I would be surprised if it were null. Doesn't the following suggest nothing is null?
|
mmmm yes it does... here's where it is going wrong (somehow): // Get an ElementQuery for this Element
$elementClass = is_object($element) ? $element::class : $element;
/** @var EntryQuery $query */
$query = $this->getElementQuery($elementClass, $criteria);
// Stash any orderBy directives from the $query for our anonymous function
$this->preOrder = $query->orderBy; |
Somehow Here's what protected function getElementQuery(string|ElementInterface $elementType, array $criteria): ElementQueryInterface
{
/** @var string|ElementInterface $elementType */
$query = $elementType::find();
Craft::configure($query, $criteria);
return $query;
} |
Try changing this: // Stash any orderBy directives from the $query for our anonymous function
$this->preOrder = $query->orderBy; to this: // Stash any orderBy directives from the $query for our anonymous function
$this->preOrder = $query->orderBy ?? []; ...and see if that doesn't solve the issue for you? |
That solved it. Thanks, Andrew. |
Addressed in the above commits |
Question
At some point in the last few weeks, the code below stopped working and started to show this error:
Cannot assign null to property nystudio107\similar\services\Similar::$preOrder of type array|string
None of the variables set up below return null that I can tell. I recently started 'entrifying' category groups on this site but since I'm not asking for category ids here, I don't think it's an issue -- just adding for context. I haven't 'entryfied' tags yet.
Stack Trace
Additional context
Craft CMS: 4.4.9
Similar: 4.0.0
The text was updated successfully, but these errors were encountered: