1

I have a little issue on drupal 7. I want a little object/field on the userprofile. This object/field shoud show special roles of the user (special = "admin, moderator ..."). And is it possible that this object comes directly after the username ?

(I am very sorry for my bad english. I hope you understand my question)

1 Answer 1

0

So I found a solution that works for me.

Modules used:

  • Display Suit
  • Display Suit Extra
  • PHP filter (I hope I didn´t forget one)

Here is how I did it ...

1.Go to a Profil

2.Click on "Edit"

3.Switch to the tab "Manage display" (right upper corner of the overlay)

4.scroll down to "custom fields" and click it

5.click "Add a code field"

6.check "User" on "Entities" and change the Text format in the "Field code" to "PHP code"

7.Now type the following in the "Field code" (Add/Change the Roles You have)

<?php $account = user_load(arg(1));?>
<div class="user-roles">
    <ul>
        <?php foreach($account->roles as $role): ?>
            <?php if($role != "authenticated user"): ?>
<?php //--------------HERE YOU NEED TO ADD/CHANGE THE ROLES YOU HAVE------------------- ?>
                    <li class="user-role- <?php 
                    if($role == '[Your Role]'){ echo 'user-role-[your role]'; }
                    elseif($role == '[Your Role]'){ echo 'user-role-[your role]'; }
                    elseif($role == '[Your Role]'){ echo 'user-role-[your role]'; }?>">
<?php //------------------------------------------------------------------------------- ?>
                    <?php print $role; ?>
                </li>
            <?php endif; ?>
        <?php endforeach; ?>
    </ul>
</div>
  1. Press "Save"

That´s it. I hope it works for You too.

(Again I apologize for my bad English. It can gladly edit for correcting my grammar)

1
  • good you find the solution on your own :) Commented Feb 18, 2015 at 10:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.