Guest User

Untitled

a guest
May 26th, 2018
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1. Event::on(
  2. Cp::class,
  3. Cp::EVENT_REGISTER_CP_NAV_ITEMS,
  4. function(RegisterCpNavItemsEvent $event){
  5. // the 4th element is the "User", you can change the URL to your
  6. // custom controller instead of the default template
  7. // I suggest you to loop all `navItems` and find
  8. // the correct user instead of assuming it's the 4th
  9. // Craft::dd($event->navItems);
  10. $event->navItems[4]['url'] = ['template' => 'path/to/template/user'],
  11. });
  12.  
  13. {% if CraftEdition != CraftPro %}
  14. {% exit 404 %}
  15. {% endif %}
  16.  
  17. {% requirePermission 'editUsers' %}
  18.  
  19. {% extends "_layouts/elementindex" %}
  20. {% set title = "Users"|t('app') %}
  21. // changes start
  22. // replace the elementType with your custom element type
  23. {% set elementType = 'prefix\namespace\elements\User' %}
  24. // changes end
  25. {% block actionButton %}
  26. {% if currentUser.can('registerUsers') %}
  27. <a class="btn submit add icon" href="{{ url('users/new') }}">{{ "New user"|t('app') }}</a>
  28. {% endif %}
  29. {% endblock %}
  30.  
  31. class User extends craftelementsUser{ //<-- extend the default User element
  32.  
  33. /**
  34. * @inheritdoc
  35. */
  36. protected static function defineSources(string $context = null): array
  37. {
  38. $sources = [
  39. [
  40. 'key' => '*',
  41. 'label' => Craft::t('app', 'All users'),
  42. 'criteria' => ['status' => null],
  43. 'hasThumbs' => true
  44. ]
  45. ];
  46.  
  47. // Overwrite the sources / usergroups...
  48. // usually Craft will search for usergroups at this place..
  49. // just leave it empty, so you'll only see the "default" group
  50.  
  51. return $sources;
  52. }
  53. }
Add Comment
Please, Sign In to add comment