Hide register link for administrator role users in Drupal 8

Posted on Friday, April 7, 2017

While working on Drupal 8 one of the issues you might face is you won't get "Register" link for anonymous user. And you need to create this menu item in the user menu.

But with this approach one issue, you might face is this menu item will be visible to users who has "Administrator" role. There are two solutions for this problem:

  1. Use Menu item visibility module

    With Menu Item Visibility module you can give specific permission to roles who can access menu items. This can be used to hide "Register" link for authenticated users.
  2. Alter menu with hook_preprocess_menu()

    If using a module is an overkill then simply use hook_preprocess_menu() to alter the menu items which will be visible to the user.
<?php
function alshaya_user_preprocess_menu(&$variables) {
  
// Hide particular link for the authenticated user.
  
$items $variables['items'];
  foreach (
$items as $key => &$item) {
    
// Hide register link.
    
if ($item['url']->getRouteName() == 'user.register' && \Drupal::currentUser()->isAuthenticated()) {
      unset(
$variables['items'][$key]);
    }
  }
}
?>

 

Tags

Comments

edwardcross (not verified)

Wednesday, July 19, 2017

Research highly impacts the services offered by any online writing services. It normally observed that writers who do not investigate can hardly attract the users with their original writings. Effectual identification online custom writing company offer professional essay writing service. Disburse concentration to each modest detail and follows your orders cautiously.
It is independent on or after writing it themselves and secondly are the different statement made in satisfied by the convention top essay writing service like essay: custom essays are written by freelance author being a certified and specific individual in their own skill writing an essay by means of abilities and control greater than the subject. A non –derivative essay written on complete marital high quality research which assures the product is of top high excellence and sensible. Visit here: https://speedycustomessaywriting.org

Rene (not verified)

Saturday, August 5, 2017

I knoww this if off topic but I'm looking into starting
my own weblog and was wondering what all is required to get set up?
I'm assuming having a blog like yours would cost a pretty penny?
I'm not very internet savvy so I'm not 100% sure. Any recommndations or advice would be
greatly appreciated. Kudos

Also visit my webpage :: vape wholesale

fatihin nurul (not verified)

Tuesday, August 22, 2017

saha, dua di Constanta dan satu di Brasov. Pa Jual besi hollow
Jual besi hollow
Toko besi siku
Jual pipa besi
Toko pipa besi baja sch 40 sch 80
undangan pernikahan bentuk tas
Supplier Besi H beam
Agen Wiremesh Besi baja
Jual plat kapal besi baja
Pabrik besi beton master steel ms
Supplier besi hollow
Supplier besi hollow
Toko pipa besi baja sch 40 sch 80
Supplier pipa besi
Toko besi hollow
undangan pernikahan ada fotonya
Supplier Besi Beton
Toko Wiremesh Besi baja
Supplier plat kapal besi baja
Pabrik besi beton ksty
Toko besi hollow
Toko besi hollow
Toko Plat besi
Toko pipa besi
Toko besi beton Sni Ulir Polos
undangan pernikahan aneh
www.sentrabesibaja.com
Jual Wiremesh Besi baja
Toko plat kapal besi baja
Pabrik besi beton krakatau steel
Agen besi hollow
Agen besi hollow
Toko besi h beam
Agen pipa besi
Toko besi wf baja
undangan pernikahan amplop
Pabrik Welded Beam T beam King Queen Cross Castellated Beam
Harga Wiremesh Besi baja
Agen plat kapal besi baja
Pabrik besi beton jcac
Pabrik besi hollow
Pabrik besi hollow
Toko besi wf
Pabrik pipa besi
Toko besi unp
undangan pernikahan batik
Pabrik Bondek Cor
Pabrik Wiremesh Besi baja
Pabrik plat kapal besi baja
Pabrik besi beton interworld steel is
Distributor pipa besi
Distributor pipa besi
Toko wiremesh
Distributor sch 40
Toko besi siku
undangan pernikahan murah
Pabrik Atap Spandek Sni
Distributor Besi Siku Baja
Distributor besi siku baja
Pabrik besi beton gunung garuda
Harga pipa besi
Harga pipa besi
Toko besi unp
Harga sch 40
Toko Plat besi plat kapal
undangan pernikahan online
Pabrik Plat Bordes Kembang
Supplier Besi Siku Baja
Harga besi siku baja
Pabrik besi beton delcoprima
Jual pipa besi
Jual pipa besi
Toko besi cnp
Jual sch 40
Toko besi h beam baja
undangan pernikahan anti mainstream
Pabrik Plat Besi Hitam
Agen Besi Siku Baja
Jual besi siku baja
Pabrik besi beton cakra steel cs
Supplier pipa besi
Supplier pipa besi
Toko besi hollow
Supplier sch 40
Toko besi cnp
undangan pernikahan cantik dan murah
Pabrik Plat Kapal Bki Krakatau Steel
Toko Besi Siku Baja
Supplier besi siku baja
Pabrik besi beton bjku
Toko pipa besi
Toko pipa besi
Toko besi beton Sni Ulir Polos
Toko sch 40
www.gudangbesibaja.com
undangan pernikahan unik
Pabrik Jual Besi Siku Baja
Jual Besi Siku Baja
Toko besi siku baja
Pabrik besi beton Sni Ulir Polos
Agen pipa besi
Agen pipa besi
ironsteelcenter.com
Agen sch 40
Supplier besi Wf Baja
undangan pernikahan yang unik
Pabrik Besi Unp Baja Profil Kanal
Harga Besi Siku Baja
Agen besi siku baja
Pabrik besi beton ais
Pabrik pipa besi
Pabrik pipa besi
Supplier stainless steel
Pabrik sch 40
Supplier bondek
undangan pernikahan lucu
Pabrik Besi Cnp Profil Baja Gording
Pabrik Besi Siku Baja
Pabrik besi siku baja
Pabrik besi beton
Distributor sch 40
Distributor sch 40
Supplier atap spandek
Distributor besi Pipa sch 80 baja
Supplier wiremesh
undangan pernikahan bunga
Pabrik Besi Hollow
Distributor Besi Unp Baja
Distributor besi wf
jasa konstruksi baja
Harga sch 40
Harga sch 40
Supplier baja ringan
Harga besi Pipa sch 80 baja
Supplier pipa besi baja sch 40 sch 80
undangan pernikahan islami
Pabrik Wiremesh
Supplier Besi Unp Baja
Harga besi wf
www.pusatbesibaja.co.id
Jual sch 40
Jual sch 40
Supplier bondek
Jual besi Pipa sch 80 baja
Supplier besi hollow
undangan pernikahan ada foto
Pabrik Besi Pipa Baja Schedule 80
Agen Besi Unp Baja
Jual besi wf
www.pusatbesibaja.com
Jual Jaket Parka Jual Jaket Parka
Jaket Parka Jaket Parka
Jual Jaket Parka Jual Jaket Parka
Jaket Parka Jaket Parka
undangan pernikahan kalender
undangan pernikahan bahasa inggris islam
undangan pernikahan islami
undangan pernikahan unik dan murah
undangan pernikahan modern
undangan pernikahan online
undangan pernikahan
undangan pernikahan amplop surat
undangan pernikahan simple
undangan pernikahan murah
undangan pernikahan unik
undangan pernikahan artis
undangan pernikahan modern
undangan pernikahan artis
undangan pernikahan arab
undangan pernikahan
undangan pernikahan

LINK 7

Gia (not verified)

Wednesday, August 23, 2017

I'm really loving the theme/design of your site. Do you
ever run into any internet browser compatibility problems?
A few of my blog readers have complained about my website not working correctly in Explorer but looks
great in Safari. Do you have any tips to help fix this problem?

Visit my weblog; fa online

Add new comment

Restricted HTML

  • Allowed HTML tags: <a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.
CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.