I have a requirement which I feel quiet complex. I am using Entity reference in X content type to reference a content type(assume Y). This works fine by displaying all the values of Y in X.
Y content type is having one field that is true or false type. So I want to display values in select list of X content type only which is having true value in the Y content type.So how can I achieve that, any suggestions will be appreciated.

  • answer this two questions : 1 .where do you want achieve this ? in node full view mode? in views ? where? 2. you want if boolean field of content type Y is true show entity_referece field ( I mean a field that is in X content type) ?
    – Yuseferi
    Sep 7, 2016 at 11:23
  • @zhilevan , 1. I want to achieve this in admin panel only may be that is only called as node full view mode. 2) Actually that is a text field only,but while adding content we will write true or false
    – Suraj
    Sep 7, 2016 at 12:38

1 Answer 1


You'll have to dynamically create that select list based on the field's values which are TRUE from the CT Y. I suppose that this select list belongs to a from, and what a convenient hook hook_form_alter is!

 * Implements hook_form_alter.
function module_name_form_alter(&$form, &$form_state, $form_id) {
  if ($form_id == 'node_xyz_form_id') {
    // Find all referenced items
    $target_ids = $form['field_reference_to_ct_y'][LANGUAGE_NONE][0]['#options'];
    // Load all referenced items
    $nodes = node_load_multiple(array_keys($target_ids));
    foreach ($nodes as $node) {
      if ($node->field_to_check_if_true[LANGUAGE_NODE][0]['value']) {
         // Alter the select list options
         $form[field_select_list][LANGUAGE_NONE]['#options'][$node->nid] = $node->title;

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.