-
Notifications
You must be signed in to change notification settings - Fork 638
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]: Entry Condition not working properly on Matrix fields. #15260
Comments
Matrix entries belong to their owner element, not a section, which is why the Section condition rule doesn’t work for them. I don’t think it would make sense to loosen the condition rule up to include entries whose root-level owner is an entry that belongs to the selected section, for two reasons:
We’ll keep the use case in mind as we explore ways to improve conditions/conditional fields down the road, but in the meantime, I just added a new event for Craft 5.3, which you can use to supply your own conditional logic from a custom module: use craft\base\FieldLayoutComponent;
use craft\elements\Entry;
use craft\events\DefineShowFieldLayoutComponentInFormEvent;
use craft\fieldlayoutelements\CustomField;
use yii\base\Event;
Event::on(
CustomField::class,
FieldLayoutComponent::EVENT_DEFINE_SHOW_IN_FORM,
function (DefineShowFieldLayoutComponentInFormEvent $event) {
/** @var CustomField $layoutElement */
$layoutElement = $event->sender;
if (
$layoutElement->field->handle === 'narrowWidth' &&
$event->element instanceof Entry &&
$event->element->field?->handle === 'contentBlocks'
) {
$owner = $event->element->getOwner();
if ($owner instanceof Entry) {
$event->showInForm = $owner->section?->handle === 'exhibits';
}
}
}
); If you want to test that out, you can change your "craftcms/cms": "5.3.x-dev as 5.3.0-alpha", Then run |
...I was taking the 5.3.x branch for a spin, and I'm getting the below exception on all element edit pages, which seems related to this change. I apologise for the noise in case this is already on your radar; I'm aware 5.3 isn't even a beta at this point 😌
|
@brandonkelly On further inspection, the exception seems related to the |
@brandonkelly Finding we're hitting this use case a fair amount now. Would it be practical to have another condition in the UI where you can choose the Owner Entry section (where the layout is attached to an Entry element)? |
What happened?
Description
The "Entry Condition" for fields in a Matrix does not work correctly when setting the condition to "Section -> Is one of -> 'Desired section'". This issue was tested on the latest Craft CMS version (5.2.3) and the demo version (europa.museum 5.1.9), both exhibiting the same problem.
Steps to reproduce
Expected behavior
The field should be visible only in the selected section when editing an entry.
Actual behavior
The field does not appear in any section, including the specified "Desired section".
Craft CMS version
5.2.3
PHP version
8.2
Operating system and version
No response
Database type and version
No response
Image driver and version
No response
Installed plugins and versions
The text was updated successfully, but these errors were encountered: