Extending Craft's User element #17315
Unanswered
janhenckens
asked this question in
Q&A
Replies: 2 comments 2 replies
-
You can create whatever custom sources you want for users using use craft\controllers\UsersController;
use craft\events\DefineEditUserScreensEvent;
use yii\base\Event;
Event::on(
UsersController::class,
UsersController::EVENT_DEFINE_EDIT_SCREENS,
function(DefineEditUserScreensEvent $event) {
if (!$event->editedUser->isCredentialed) {
unset($event->screens['permissions']);
}
},
); Seems like that would get you most of the way there? |
Beta Was this translation helpful? Give feedback.
1 reply
-
@janhenckens This might be useful as well… https://dev-diary.newism.com.au/posts/user-profile-urls-in-craft-cms.html I haven't tested it in a while or on craft 5 tho. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
We have a couple of clients that like to use (or would like to use) their Craft website as sort of a low-level CRM for their contacts (which sometimes also are frontend users in their website
In the past I've done this by adding my own Element, linking it to the User element through a property and setting the same fields on the custom element to match the User element exactly. That works but it isn't very repeatable and brings a bit of a maintenance burden to keep both element types in sync.
The main goal we'd like to achieve here is showing all these users/contacts in a view where we can defined our own sources - outside of the user groups that our shown on /users - since we're viewing them as CRM contacts, not as website accounts. Likewise on the detail page, we'd like to not show the permissions, login information, etc.
My latest idea how to tackle this is by creating a custom element that extends the
craft\elements\User
class. That gives allows me a view with my own sources, my own detail pages - while still showing the User elements.Only thing that doesn't in this case is that my elements don't know about the custom fields that my users have - making the inaccessible for element overview tables & overview filter conditions - both of which are of course crucial.
Which could bring us back to mirroring the fields on our element, but I'd rather avoid that if at all possible.
Thanks for reading along, hoping anyone has tried this before and/or knows how to accomplish this!
Beta Was this translation helpful? Give feedback.
All reactions