Add ability to save filters for authors that have common views #16735
-
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
You can create custom sources with predefined filters, from your dev environment (where Alternatively, you could write a plugin that defines additional sources for each category using use craft\base\Event;
use craft\elements\Entry;
use craft\events\RegisterElementSourcesEvent;
Event::on(
Entry::class,
Entry::EVENT_REGISTER_SOURCES,
function(RegisterElementSourcesEvent $event) {
$event->sources[] = ['heading' => 'Categories'];
$categories = Entry::find()->section('categories')->all();
foreach ($categories as $category) {
$event->sources[] = [
'key' => "category:$category->id",
'label' => $category->getUiLabel(),
'criteria' => [
'myCategoriesField' => $category->id,
],
];
}
},
); That’s probably the better way overall, since the sources will always reflect category entry changes. |
Beta Was this translation helpful? Give feedback.
You can create custom sources with predefined filters, from your dev environment (where
allowAdminChanges
is enabled). The caveat is that relations aren’t as easy, since elements are created per environment, not as part of the project config. So instead of choosing the related entry, you must enter its ID – or if the ID is going to be different depending on the environment, you can set it to an environment variable.Alternatively, you could write a plugin that defines additional sources for each category using
craft\base\element::EVENT_REGISTER_SOURCES
: