Skip to content
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

Querying for relatedTo category causes Yii error when entry's category isn't set #5242

Closed
ccsantos23 opened this issue Nov 18, 2019 · 4 comments

Comments

@ccsantos23
Copy link

Description

Current entry's search for other entries with related categories fails if the current entry doesn't have anything selected for those categories.

Steps to reproduce

My page has this query that looks for logos related to the page:

{% set logoEntries = craft.entries
  .with([
    ['featuredImage', { withTransforms: ['thumbFit'] }],
  ])
  .site(entry.site.handle)
  .section('logos')
  .relatedTo([
    entry.categoryIndustry,
    entry.categorySolution,
    entry.categoryProduct
  ])
  .limit(20)
  .all()
%}

If the page's entry has all its categories set (categoryIndustry, categorySolution, categoryProduct), then the page will render fine. If the entry has no selected value for one or more of those categories, then it gives this error:

PHP Warning – yii\base\ErrorException
array_push() expects at least 2 parameters, 1 given
1. in /var/www/usi-craftcms/vendor/craftcms/cms/src/elements/db/ElementRelationParamParser.php at line 216

                    $relElementIds[] = $element->getSourceId();
                } else {
                    $relElementIds[] = $element->id;
                    if ($elementParam === 'element') {
                        $relSourceElementIds[] = $element->getSourceId();
                    }
                }
            } else if ($element instanceof ElementQueryInterface) {
                $ids = $element->ids();
                array_push($relElementIds, ...$ids);
                if ($elementParam === 'element') {
                    array_push($relSourceElementIds, ...$ids);
                }
            }
        }

        break;
    }
}

Additional info

This worked fine in Craft 3.3.13. The error appeared when I updated to 3.3.15. (And reverting to 3.3.13 makes everything work again.)

  • Craft version: 3.3.15
  • PHP version: 7.2.21
  • Database driver & version: MySQL 5.7.27
  • Plugins & versions:
    Element Map 1.2.1
    Feed Me 4.1.2
    Field Reveal 1.0.1
    Fractal 1.0.8
    Logs 3.0.2
    Matrix Toolbar 1.0.6
    Recaptcha Verify 1.0.0
    Redactor 2.4.0
    Redirect plugin for Craft 3 1.0.23
    SEOmatic 3.2.29
    Smith 1.0.0
    Snitch 3.0.0
    Workflow 1.2.3
@janhenckens
Copy link
Contributor

I've ran into this same issue a couple of times over the past weeks and I've found that this does work in PHP 7.3 (see changelog here).

@ccsantos23
Copy link
Author

I checked the server requirements page, which says PHP 7.0+. Should it say PHP 7.3+ now?
And regardless of the PHP version, it was working fine in Craft 3.3.13 (I ended up not upgrading to 3.3.15 until I got more guidance here).

@janhenckens
Copy link
Contributor

Looks like this got introduced in this commit 67e2880, which got released with 3.3.14

@brandonkelly
Copy link
Member

Thanks for reporting that. It’s now fixed for the next release.

To get the fix early, change your craftcms/cms requirement in composer.json to:

"require": {
  "craftcms/cms": "dev-develop#a4c5a329b5cc0667ba236c15ea67afc091a7aa37 as 3.3.15",
  "...": "..."
}

Then run composer update.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants