Skip to content

Selectable Assets Condition - Add variables like in Routes and Asset Location #12026

Answered by brandonkelly
thisanimus asked this question in Q&A
Discussion options

You must be logged in to vote

Conditions aren’t inherently aware of their context so this wouldn’t really be possible. However you can supply your own custom condition rule from a module, which keeps its own reference to the entry being edited, and filters the assets accordingly.

We’re still working on condition documentation, but here’s what the rule would look like:

namespace mymodulenamespace;

use Craft;
use craft\base\conditions\BaseConditionRule;
use craft\base\ElementInterface;
use craft\elements\conditions\ElementConditionRuleInterface;
use craft\elements\db\AssetQuery;
use craft\elements\db\ElementQueryInterface;

class MyAssetConditionRule extends BaseConditionRule implements ElementConditionRuleInterface
{
…

Replies: 3 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@thisanimus
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
Q&A
Labels
None yet
2 participants