Skip to content

Restrict available parent entries when editing entry in Craft 4 #12475

Closed Answered by brandonkelly
paulgoodfield asked this question in Ideas
Discussion options

You must be logged in to vote

Just added a new EVENT_DEFINE_PARENT_SELECTION_CRITERIA event to craft\elements\Entry for Craft 4.4 (#12485). With it you’ll be able to do this:

use craft\elements\Entry;
use craft\events\ElementCriteriaEvent;
use yii\base\Event;

Event::on(
    Entry::class,
    Entry::EVENT_DEFINE_PARENT_SELECTION_CRITERIA,
    function(ElementCriteriaEvent $event) {
        $event->criteria['id'] = $availableParentId;
        $event->criteria['level'] = '<= 2';
    },
);

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@paulgoodfield
Comment options

@brandonkelly
Comment options

Answer selected by brandonkelly
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Ideas
Labels
None yet
2 participants