Override locked users status pill color #10313
-
One of our clients is nostalgic of a Craft 2 user index behavior: users with the (temporary) locked status (due to too many incorrect login attempts) would be displayed next to an orange pill. In Craft 3, they're given a green pill. Apparently this is a real problem for them ¯\(ツ)/¯ I thought I could solve this with a CSS override but unfortunately the only classes we get on the pill element are I've looked for events or hooks that I could use to change this behavior but didn't find anything. Would it be possible to add a |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
You could register a custom use craft\elements\User;
use craft\events\RegisterElementHtmlAttributesEvent;
use yii\base\Event;
Event::on(
User::class,
User::EVENT_REGISTER_HTML_ATTRIBUTES,
function(RegisterElementHtmlAttributesEvent $event) {
/** @var User $user */
$user = $event->sender;
if ($user->locked) {
$event->htmlAttributes['data-locked'] = '1';
}
}
); |
Beta Was this translation helpful? Give feedback.
-
I somehow found a dirty hack for the edit user page: Using the Craft::$app->view->hook('cp.users.edit.details', static function (&$context, &$handled) {
/** @var User $user */
$user = $context['user'];
if ($user->locked) {
return '
<style>
body.use-shapes.status.active {
background-color: transparent;
border-style: solid;
border-width: 0 5px 10px 5px;
border-color: transparent transparent #cb6e17 transparent;
border-radius: 1px;
}
.status.active{
background-color: #cb6e17;
}
</style>';
}
}); Not pretty but it gets the job done! |
Beta Was this translation helpful? Give feedback.
You could register a custom
data-locked
attribute on user elements using a custom module: