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

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

Open
mikesnoeren opened this issue Nov 20, 2024 · 1 comment
Labels

Comments

@mikesnoeren
Copy link

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
@humandevs
Copy link

We also could use more conditions for nested entries. It's a bit confusing because there are parent and children fields but that only applies to Structures, and then there is RelatedTo (and RelatedToEntries in element queries and GraphQL filters), but I'm not aware of a way to do multi joins and specify a join distance. You can use RelatedTo in a condition and specify the field that the RelatedTo is joined by (see https://craftcms.stackexchange.com/questions/30544/related-to-query), but either nestedParent and nestedChildren fields or adding nested children and parents to the existing parent and children fields would be helpful, I think.

I really like the way FileMaker does this with an actual relationship database ERD diagram and then you add a view "field" to a layout, which is like an iframe into a related table, where you can choose the fields you want from that joined table (Entry Type), and if you want to go multiple joins deep, you create a view inside the view that you choose how to relate another table (1 join away), so you end up with this multi nest but it's visually logical.

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

No branches or pull requests

2 participants