craftcms / craftcms/cms

[5.x]: Matrix field conditions evaluated against block instead of parent entry

Open
#16,159 1 comment 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
PHP
Stars
3.6k
Forks
705
Avg merge
1d 5h
Merged PRs (30d)
134

Description

What happened?
Description

When adding conditions to fields within a matrix block, they often don't work as expected because the conditions are evaluated against the matrix block itself rather than the parent entry. In most cases, these conditions should be based on the parent entry, not the matrix block.

Example:
A matrix block contains an image field.
Set a condition to hide the image field if the parent entry's level equals 1 (level == 1).
The image field never shows because block.level is null.

Thoughts:
I understand why this happens — because everything in CraftCMS is considered an entry now, and entry types can also be used as a standalone section. In such cases, conditions work as expected. However, in the context of a matrix block within another entry, it would be more intuitive if the conditions evaluated the parent entry rather than the block itself. Ideally, the behavior should adapt based on how the entry type is being used, OR we need an aditional condition field "Entry Parent Condition".

Steps to reproduce
  1. Create a matrix field.
  2. Add a field to the matrix block and configure a condition based on the parent entry (e.g., level == 1).
  3. Test to see if the field is shown or hidden as expected.
Craft CMS version

5.5.2

PHP version

8.2.24

Operating system and version

Linux 6.11.9-orbstack-00279-g4cf512143f2e

Database type and version

MySQL 8.0.36

Image driver and version

Imagick 3.7.0 (ImageMagick 6.9.11-60)

Installed plugins and versions
Name Handle Package Name Version
CKEditor ckeditor craftcms/ckeditor 4.4.0
DigitalOcean Spaces Filesystem dospaces vaersaagod/dospaces 3.0.0
Expanded Singles expanded-singles verbb/expanded-singles 3.0.1
Hyper hyper verbb/hyper 2.2.0
Kint kint verbb/kint 4.0.1
Matrix Extended matrix-extended vandres/craft-matrix-extended v3.6.1
Navigation navigation verbb/navigation 3.0.5
Retour retour nystudio107/craft-retour 5.0.3
SEOmatic seomatic nystudio107/craft-seomatic 5.1.6
Vite vite nystudio107/craft-vite 5.0.1

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the matrix-field condition case described in the issue using a parent entry level and a matrix block field. Start by tracing where conditions are evaluated for matrix blocks versus their parent entry; done means the documented parent-entry condition behaves as expected without breaking standalone entry-type conditions.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
backend
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.