[4.x]: Issue with Element::EVENT_AUTHORIZE_DELETE
?
#11759
-
What happened?DescriptionI don't quite understand how the event I'm trying to prevent elements deletions in a custom plugin (when the element is referenced in another element). For entries for example, the event's attribute Shouldn't the system have a default value for I can prevent deletions using the event Steps to reproduce
Expected behaviorThe button Delete on an element index page should be disabled ? Actual behaviorThe Delete button on an element index page is still active. Craft CMS version4.2.1 PHP version8.1.2 Operating system and versionLinux Mint 20.2 Database type and versionMysql 5.7 Image driver and versionNo response Installed plugins and versions |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Moved this to a discussion because it’s currently working as intended. The event is only called if something in the element type hasn’t already authorized it. There’s not currently any way to override the existing authorization if granted. It wouldn’t be possible to have the event take precedence without adding complexity to each of the elements’ authorization methods, which I wanted to avoid. We could possibly introduce new authorization service methods that are the source of truth, and fire their own events that take precedence over the element’s authorization methods. Not sure how I feel about that though. |
Beta Was this translation helpful? Give feedback.
-
This is resolved for Craft 4.3. All internal element authorization checks have been updated to call new methods in the Elements service, which support preventing authorization when See details in the PR (#11808). |
Beta Was this translation helpful? Give feedback.
This is resolved for Craft 4.3. All internal element authorization checks have been updated to call new methods in the Elements service, which support preventing authorization when
AuthorizationCheckEvent::$authorized
is set tofalse
.See details in the PR (#11808).