Giter Site home page Giter Site logo

Comments (1)

brandonkelly avatar brandonkelly commented on July 2, 2024

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:

  • It would be a breaking change in behavior, as some conditions could be using the same entry type for section entries and Matrix/CKEditor entries, and expecting that the condition rule would exclude the Matrix/CKEditor entries.
  • It would open a can of worms, as Matrix/CKEditor fields can be added to other element types besides entries. What if you wanted to show a field based on whether the Matrix field is within a certain category group? Or a certain global set? Etc.

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 requirement in composer.json to:

"craftcms/cms": "5.3.x-dev as 5.3.0-alpha",

Then run composer update.

from cms.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.