-
Notifications
You must be signed in to change notification settings - Fork 641
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
Allow element types to set additional query params used in getElementById() #3117
Comments
Even if we did, you wouldn’t be able to override the code that calls |
I don’t need to override that code that calls it. What I want to do is to override the default |
A default In my use case a default |
OK, just so I’m clear, you are asking for a way to register custom query params that are only applied when What if instead you just don’t set the protected function beforePrepare(): bool
{
// ...
// Determine the environment
$env = $this->environment ?? (empty($this->id)
? Plugin::getInstance()->getEnvironments()->getCurrentEnvironment()
: null);
// Now use $env instead of $this->environment ...
} |
Yes, exactly.
Well, it still must be possible to set the param to This is what I currently do to work around errors being thrown by if (
!Craft::$app->getRequest()->getIsConsoleRequest() &&
Craft::$app->getRequest()->getActionSegments() === ['maintenance', 'tasks', 'save-task']
) {
$this->environmentId = null;
} With both workaround solutions my element type isn’t really compatible to expected behavior of |
Maybe a better option would be for us to add a new method to ElementQuery, perhaps called Then you could just override that method, and null out your public function nofilter()
{
$this->environment = null;
return parent::nofilter();
} |
This would be perfect. |
Or a 3rd argument for the constructor? public function __construct($elementType, array $config = [], bool $nofilter = false); |
Thought about that, but a lot of the places we currently null-out the |
All set now. We decided to call it |
Thank you Brandon! When I said perfect I lied a little bit, I didn't like the name. With naming it |
Hah, good to head! We had to debate it for a bit; the only issue we had with |
Well I consider it a status-like property of my element. It is just another way to disable it under certain conditions, I think you can say it is defining its status. |
In my element type I have a query parameter which conceptually works very similar to
status
, where if it isn’t explicitly set it defaults to a specific value.I’m now running into issues with the
Elements::getElementById()
function, which doesn’t always return my elements because I’d need to set/override my param tonull
for it to work. I am not callinggetElementById()
myself, it’s called byElements::propagateElement()
when I save my element.It would be nice if it was possible to set additional query params used in
getElementById()
, maybe via a static function that I could add to my element class or via an event listener.This is the code I have in the constructor of my
ElementQuery
:The text was updated successfully, but these errors were encountered: