Different entity types for one field value


  1. The "author" field would be a User Reference field.
  2. You can use hook_form_alter to limit this fields allowed $options to be either the logged in user, or the list of users of Developers.

Something similar too ...

function MYMODULE_hook_form_alter(&$form, &$form_state, $form_id) {
  global $user;
  if ($form_id == 'node_add_application') {
    if (in_array('Developer', $user->roles)) {
      // Set the default value of the author field to the logged in users uid.
      $form['field_AUTHOR_FIELDNAME']['options']['#default_value'] = $user->uid;
    if (in_array('Site Administrator', $user->roles)) {
      // Overwrite the general users list with UIDs only of a specific role.

      // Get uids of a specific role.
      $query = 'SELECT DISTINCT(ur.uid) 
          FROM {users_roles} AS ur
          LEFT JOIN roles r on ur.rid = r.rid
          WHERE r.name = :role';
      $result = db_query($query, array(':role' => 'Developer'));
      foreach ($result as $row) {
        $developer_uids[] = $row->uid;
      foreach ($form['field_AUTHOR_FIELDNAME']['options'] as $uid => $label) {
        if (!in_array($uid, $developer_uids)) {

This is a rough example of the logic and code it would take to alter the select list of user names for the author field to either default to the logged in developer, or show "site admins" only developers.

I have written such code before, this exact code is only an example based upon the details given in your question. It is un-tested.

Tags: Drupal 7 / Entities

Similar questions

drupal template files in different folders for different content types
I'm trying to get Drupal to scan multiple directories to find template files for pages and nodes. I have a content type called "contest". I have a node with the path of "http://mysite.com/contest/test I'd like to have a folder structure like: Drupal is not finding contest tpl's.
How to use different fields for different content types in a view
I want to construct a view which will include nodes from several content types. For each different content type, I want to display different fields (say an image for a type, a video for another, some different text for others) Let me show you the example I want to achieve: row 1 is "image", row 2 is "video", row 3 is "event" content type. So, John ...
Different payment methods for different product types
Is there a way to have different payment methods available for different product types? This is my scenario and what I've figured out so far: I have two product types on my Drupal Commerce site, for selling bus travel passes. One type is just to book the bus pass where you select the date and times (custom line items) for your buss tickets. The oth...
Can a Calendar, based on two different content types, output different html based on content type
I built a calendar based on two different content type, let's call them A and B. For each type I output the Title field and, along with it, I'd like to have a link to the node if the Title field belongs to type A and just plain text if it belongs to type B. Is there a way to do this?
how to select different colorbox styles for different content types in drupal 7?
i tried to select different colorbox styles for different content types but i couln't. because we can select only one colorbox style for all using. if onybody know how can select different colorbox style for different content type please help me
Avoiding content-type overkill: 5 slightly different pages = 5 different content types?
My drupal 7 site mainly consists of a main menu with 5 entries, each linking to a more or less simple page. These 5 pages have a lot of common fields, simply some fields are slightly different. Normally, i would have to create a content type and an actual node to accomplish this — but since there is only one actual node for each of the content type...

Also ask

We use cookies to deliver the best possible experience on our website. By continuing to use this site, accepting or closing this box, you consent to our use of cookies. To learn more, visit our privacy policy.