When saving a nodereference field (admin/content/types/composition/fields/field_composed_by), I get the message "This post can't be referenced" (line 108 nodereference_field), because in _nodereference_potential_references, line 367, this test fails:

>
if (isset($field['referenceable_types']))

This is cck from today (DRUPAL-5, so I think that is 5.x-1.x-dev), // $Id: nodereference.module,v 1.39.2.8 2007/01/29 20:43:49 yched Exp $

Here are my content types:

$content[type]  = array (
  'name' => 'Composer',
  'type' => 'composer',
  'description' => 'A person who writes music.',
  'title_label' => 'Summary',
  'body_label' => '',
  'min_word_count' => '0',
  'help' => '',
  'node_options' => 
  array (
    'status' => true,
    'promote' => true,
    'revision' => true,
    'sticky' => false,
  ),
  'comment' => '0',
  'old_type' => 'composer',
  'orig_type' => '',
  'module' => 'node',
  'custom' => '1',
  'modified' => '1',
  'locked' => '0',
  'ant' => 1,
  'ant_pattern' => '[field_last_name], [field_first_names]	([field_birth_date]-[field_death_date])',
  'ant_php' => 0,
);
$content[groups]  = array (
  0 => 
  array (
    'label' => 'Name',
    'settings' => 
    array (
      'collapsible' => 0,
      'collapsed' => 0,
    ),
    'description' => '',
    'weight' => '-10',
    'group_name' => 'group_name',
  ),
);
$content[fields]  = array (
  0 => 
  array (
    'widget_type' => 'date_select',
    'label' => 'Birth date',
    'weight' => '-8',
    'select_day' => '1',
    'select_month' => '1',
    'select_year' => '0',
    'years_back' => '3',
    'years_forward' => '3',
    'increment' => '1',
    'description' => '',
    'field_birth_date' => 
    array (
      0 => 
      array (
        'value' => 
        array (
          'mday' => '30',
          'mon' => '1',
          'year' => '2007',
        ),
      ),
    ),
    'timezone' => 'GMT',
    'default_value_php' => '',
    'group' => false,
    'required' => '1',
    'multiple' => '0',
    'granularity' => 
    array (
      'Y' => 'Y',
      'M' => 'M',
      'D' => 'D',
    ),
    'todate' => '',
    'input_format' => 'Y M j - H:i:s',
    'input_format_custom' => '',
    'output_format_date' => 'j F, Y',
    'output_format_zone' => '',
    'output_format_custom' => '',
    'output_format_date_long' => 'l, F j, Y - H:i',
    'output_format_zone_long' => '',
    'output_format_custom_long' => '',
    'output_format_date_medium' => 'D, m/d/Y - H:i',
    'output_format_zone_medium' => '',
    'output_format_custom_medium' => '',
    'output_format_date_short' => 'm/d/Y - H:i',
    'output_format_zone_short' => '',
    'output_format_custom_short' => '',
    'tz_handling' => 'site',
    'field_timezone' => 'GMT',
    'field_name' => 'field_birth_date',
    'field_type' => 'date',
    'module' => 'date',
    'default_value' => 
    array (
      0 => 
      array (
        'value' => '2007-01-30T00:00:00',
      ),
    ),
  ),
  1 => 
  array (
    'widget_type' => 'options_buttons',
    'label' => 'Gender',
    'weight' => '-6',
    'description' => '',
    'field_gender' => 
    array (
      'key' => false,
    ),
    'default_value_php' => '',
    'group' => false,
    'required' => '1',
    'multiple' => '0',
    'text_processing' => '0',
    'max_length' => '',
    'allowed_values' => '',
    'allowed_values_php' => 'return array(\'m\' => t(\'Male\'), \'f\' => t(\'Female\'));',
    'field_name' => 'field_gender',
    'field_type' => 'text',
    'module' => 'text, optionwidgets',
  ),
  2 => 
  array (
    'widget_type' => 'date_select',
    'label' => 'Death date',
    'weight' => '0',
    'select_day' => '1',
    'select_month' => '1',
    'select_year' => '0',
    'years_back' => '3',
    'years_forward' => '3',
    'increment' => '1',
    'description' => '',
    'field_death_date' => 
    array (
      0 => 
      array (
        'value' => 
        array (
          'mday' => '',
          'mon' => '',
          'year' => '',
        ),
      ),
    ),
    'timezone' => '',
    'default_value_php' => '',
    'group' => false,
    'required' => '0',
    'multiple' => '0',
    'granularity' => 
    array (
      'Y' => 'Y',
      'M' => 'M',
      'D' => 'D',
    ),
    'todate' => '',
    'input_format' => 'site-wide',
    'input_format_custom' => '',
    'output_format_date' => 'j F, Y',
    'output_format_zone' => '',
    'output_format_custom' => '',
    'output_format_date_long' => 'l, F j, Y - H:i',
    'output_format_zone_long' => '',
    'output_format_custom_long' => '',
    'output_format_date_medium' => 'D, m/d/Y - H:i',
    'output_format_zone_medium' => '',
    'output_format_custom_medium' => '',
    'output_format_date_short' => 'm/d/Y - H:i',
    'output_format_zone_short' => '',
    'output_format_custom_short' => '',
    'tz_handling' => 'site',
    'field_timezone' => 'GMT',
    'field_name' => 'field_death_date',
    'field_type' => 'date',
    'module' => 'date',
  ),
  3 => 
  array (
    'widget_type' => 'text',
    'label' => 'First names',
    'weight' => '0',
    'rows' => '1',
    'description' => 'One first name per field, e.g. "Wolfgang" and "Amadeus".',
    'field_first_names' => 
    array (
      0 => 
      array (
        'value' => '',
        'format' => 1,
      ),
      1 => 
      array (
        'value' => '',
        'format' => 1,
      ),
      2 => 
      array (
        'value' => '',
        'format' => 1,
      ),
    ),
    'default_value_php' => '',
    'group' => 'group_name',
    'required' => '0',
    'multiple' => '1',
    'text_processing' => '1',
    'max_length' => '',
    'allowed_values' => '',
    'allowed_values_php' => '',
    'field_name' => 'field_first_names',
    'field_type' => 'text',
    'module' => 'text',
  ),
  4 => 
  array (
    'widget_type' => 'text',
    'label' => 'Last name',
    'weight' => '1',
    'rows' => '1',
    'description' => 'Including labels like van, de or l\', e.g. "van Beethoven".',
    'field_last_name' => 
    array (
      0 => 
      array (
        'value' => '',
        'format' => 1,
      ),
    ),
    'default_value_php' => '',
    'group' => 'group_name',
    'required' => '1',
    'multiple' => '0',
    'text_processing' => '1',
    'max_length' => '',
    'allowed_values' => '',
    'allowed_values_php' => '',
    'field_name' => 'field_last_name',
    'field_type' => 'text',
    'module' => 'text',
  ),
);

and

$content[type]  = array (
  'name' => 'Composition',
  'type' => 'composition',
  'description' => 'A musical work that is written and can be performed.',
  'title_label' => 'Print title',
  'body_label' => '',
  'min_word_count' => '0',
  'help' => '',
  'node_options' => 
  array (
    'status' => true,
    'promote' => true,
    'revision' => true,
    'sticky' => false,
  ),
  'comment' => '0',
  'old_type' => 'composition',
  'orig_type' => '',
  'module' => 'node',
  'custom' => '1',
  'modified' => '1',
  'locked' => '0',
  'ant' => 0,
  'ant_pattern' => 'do this later',
  'ant_php' => 0,
);
$content[fields]  = array (
  0 => 
  array (
    'widget_type' => 'options_select',
    'label' => 'Catalog label',
    'weight' => '0',
    'description' => '',
    'field_catalog_label' => 
    array (
      'key' => false,
    ),
    'default_value_php' => '',
    'group' => false,
    'required' => '0',
    'multiple' => '0',
    'text_processing' => '0',
    'max_length' => '',
    'allowed_values' => '',
    'allowed_values_php' => 'return array(
\'K.\' => \'Köchel (Mozart)\',
\'BWV\' => \'Bach Werke Verzeichnis (J. S. Bach)\',
\'Hob.\' => \'Hoboken (Haydn)\',
\'D.\' => \'Deutsch number (Schubert)\',
);',
    'field_name' => 'field_catalog_label',
    'field_type' => 'text',
    'module' => 'text, optionwidgets',
    'default_value' => 
    array (
    ),
  ),
  1 => 
  array (
    'widget_type' => 'nodereference_autocomplete',
    'label' => 'Composed by',
    'weight' => '0',
    'description' => '',
    'field_composed_by' => 
    array (
      0 => 
      array (
        'node_name' => '',
      ),
    ),
    'default_value_php' => '',
    'group' => false,
    'required' => '0',
    'multiple' => '0',
    'referenceable_types' => 
    array (
      'composer' => false,
      'composition' => false,
      'poll' => false,
    ),
    'advanced_view' => '--',
    'field_name' => 'field_composed_by',
    'field_type' => 'nodereference',
    'module' => 'nodereference',
  ),
  2 => 
  array (
    'widget_type' => 'options_select',
    'label' => 'Key',
    'weight' => '0',
    'description' => '',
    'field_key' => 
    array (
      'key' => false,
    ),
    'default_value_php' => '',
    'group' => false,
    'required' => '0',
    'multiple' => '0',
    'text_processing' => '0',
    'max_length' => '',
    'allowed_values' => 'A
B
C
D
E
F
G',
    'allowed_values_php' => '',
    'field_name' => 'field_key',
    'field_type' => 'text',
    'module' => 'text, optionwidgets',
  ),
  3 => 
  array (
    'widget_type' => 'options_buttons',
    'label' => 'Major Minor',
    'weight' => '0',
    'description' => '',
    'field_major_minor' => 
    array (
      'key' => false,
    ),
    'default_value_php' => '',
    'group' => false,
    'required' => '0',
    'multiple' => '0',
    'text_processing' => '0',
    'max_length' => '',
    'allowed_values' => '',
    'allowed_values_php' => 'return array(\'maj\' => t(\'Major\'), \'min\' => t(\'Minor\'));',
    'field_name' => 'field_major_minor',
    'field_type' => 'text',
    'module' => 'text, optionwidgets',
  ),
  4 => 
  array (
    'widget_type' => 'number',
    'label' => 'Number',
    'weight' => '0',
    'description' => 'Examples:
<ul>
<li>Piano Trio no. <strong>1</strong> in B major, op.8</li>
<li>String Quartet no. <strong>19</strong> in C major, K.465</li>
<li>Symphony no. <strong>94</strong> in G major, Hob.I-94 "The Surprise"</li>
</ul>
Note: just enter the number, no other characters.',
    'field_number' => 
    array (
      0 => 
      array (
        'value' => '',
      ),
    ),
    'default_value_php' => '',
    'group' => false,
    'required' => '0',
    'multiple' => '0',
    'min' => '0',
    'max' => '',
    'prefix' => 'No. ',
    'suffix' => '',
    'allowed_values' => '',
    'allowed_values_php' => '',
    'field_name' => 'field_number',
    'field_type' => 'number_integer',
    'module' => 'number',
  ),
  5 => 
  array (
    'widget_type' => 'number',
    'label' => 'Opus',
    'weight' => '0',
    'description' => 'Piano Quintet in A major, op. <strong>32</strong> D.667 "Trout"

Note: just the number, other characters.',
    'field_opus' => 
    array (
      0 => 
      array (
        'value' => '',
      ),
    ),
    'default_value_php' => '',
    'group' => false,
    'required' => '0',
    'multiple' => '0',
    'min' => '0',
    'max' => '',
    'prefix' => 'op. ',
    'suffix' => '',
    'allowed_values' => '',
    'allowed_values_php' => '',
    'field_name' => 'field_opus',
    'field_type' => 'number_integer',
    'module' => 'number',
  ),
  6 => 
  array (
    'widget_type' => 'options_select',
    'label' => 'Posthumus',
    'weight' => '0',
    'description' => '',
    'field_posthumus' => 
    array (
      'key' => 'posthumus',
    ),
    'default_value_php' => '',
    'group' => false,
    'required' => '1',
    'multiple' => '0',
    'text_processing' => '0',
    'max_length' => '',
    'allowed_values' => 'no
yes',
    'allowed_values_php' => '',
    'field_name' => 'field_posthumus',
    'field_type' => 'text',
    'module' => 'text, optionwidgets',
  ),
  7 => 
  array (
    'widget_type' => 'options_select',
    'label' => 'Print title pattern',
    'weight' => '0',
    'description' => 'Choose the pattern that will be used as the title of this work.',
    'field_print_title_pattern' => 
    array (
      'key' => 'test',
    ),
    'default_value_php' => '',
    'group' => false,
    'required' => '1',
    'multiple' => '0',
    'text_processing' => '0',
    'max_length' => '',
    'allowed_values' => '[type-name] :: [field_title]
[field_title] << [type-name]',
    'allowed_values_php' => '',
    'field_name' => 'field_print_title_pattern',
    'field_type' => 'text',
    'module' => 'text, optionwidgets',
  ),
  8 => 
  array (
    'widget_type' => 'text',
    'label' => 'Subtitle',
    'weight' => '0',
    'rows' => '1',
    'description' => 'Examples:
<ul>
<li>Piano Sonata no.23 in F minor, op.57 "<strong>Appasionata</strong>"</li>
<li>Piano Quintet in A major, op.32/D.667 "<strong>Trout</strong>"</li>
</ul>',
    'field_subtitle' => 
    array (
      0 => 
      array (
        'value' => '',
        'format' => 1,
      ),
    ),
    'default_value_php' => '',
    'group' => false,
    'required' => '0',
    'multiple' => '0',
    'text_processing' => '1',
    'max_length' => '',
    'allowed_values' => '',
    'allowed_values_php' => '',
    'field_name' => 'field_subtitle',
    'field_type' => 'text',
    'module' => 'text',
  ),
  9 => 
  array (
    'widget_type' => 'text',
    'label' => 'Title',
    'weight' => '0',
    'rows' => '1',
    'description' => 'Examples (the bold text would be the Title):
<ul><li><strong>Passacaglia and Fugue</strong> in C minor, BWV.582</li>
<li><strong>String Quartet</strong> no.2 in D major</li>
<li><strong>Piano Sonata</strong> no.23 in F minor, op.57 "Appasionata".</li>
</ul>',
    'field_title' => 
    array (
      0 => 
      array (
        'value' => '',
        'format' => '1',
      ),
    ),
    'default_value_php' => '',
    'group' => false,
    'required' => '0',
    'multiple' => '0',
    'text_processing' => '1',
    'max_length' => '',
    'allowed_values' => '',
    'allowed_values_php' => '',
    'field_name' => 'field_title',
    'field_type' => 'text',
    'module' => 'text',
  ),
);

Comments

robertDouglass’s picture

You'll never complain about too little information in a bug report from me ;-)

Here is the $_POST that causes that error:

Array
(
    [widget_type] => nodereference_autocomplete
    [label] => Composed by
    [field_composed_by] => Array
        (
            [0] => Array
                (
                    [node_name] => 
                )

        )

    [default_value_php] => 
    [weight] => 0
    [group] => 0
    [description] => 
    [referenceable_types] => Array
        (
            [composer] => composer
        )

    [advanced_view] => --
    [op] => Save field settings
    [form_token] => 4a79ebd287c27e0ce50469148223f9e0
    [form_id] => _content_admin_field
)

and here are the variables that come into nodereference_field($op, &$node, $field, &$items, $teaser, $page):

Array
(
    [op] => validate
    [node] => Array
        (
            [field_composed_by] => Array
                (
                    [0] => Array
                        (
                            [node_name] => 
                        )

                )

        )

    [field] => Array
        (
            [field_name] => field_composed_by
            [type] => nodereference
            [required] => 
            [multiple] => 0
            [db_storage] => 1
            [widget] => Array
                (
                    [type] => nodereference_autocomplete
                    [weight] => 0
                    [label] => Composed by
                    [description] => 
                )

            [type_name] => composition
            [display_settings] => Array
                (
                )

        )

    [items] => Array
        (
            [0] => Array
                (
                    [node_name] => 
                )

        )

    [teaser] => 
    [page] => 
)
yched’s picture

I just committed a fix to all branches.
Could you check it works for you ?

robertDouglass’s picture

Wheee! That's what I call amazing support! =)

Thanks. It works on my installation.

yched’s picture

Status: Active » Fixed

This was a bug in a commit I did yesterday.
I guess I'd rather avoid breaking the code just before packing a release, like I did the for the previous one.
So thanks for reporting this :-)

yched’s picture

An additional fix was needed for select widgets.
Should be ok now

Anonymous’s picture

Status: Fixed » Closed (fixed)
gemini’s picture

Version: 5.x-1.x-dev » 5.x-1.6-1
Status: Closed (fixed) » Active

I'm reactivating this since I get the same error when I use this line in my "edit" template for theming purposes:

$form['field_business_listing']['nids']['#attributes'] = array('disabled' => 'disabled');

"business_listing" is a reference field. I'm trying to make it read-only since node id is being selected via $_GET method and it all works just fine - it even shows the right selection when input field is disabled, but gives an error message on "save". Since "disabled" is just an HTML attribute, I don't see a reason it should affect anything.

Any ideas on how to fix this are greatly appreciated! Thanks!

liquidcms’s picture

Priority: Normal » Critical

i am also getting same error but in different manner.

using 5.x-1.6-1

when i use drupal_execute to add a node i use the following:

      $node = array('type'=>'artist');                           
      $values['title'] = $info['artist'];
      $values['field_primary_label'][0]['nid'] = 127;
      $result = drupal_execute('artist_node_form', $values, $node);

keeps failing and even though drupal_execute is supposed to return execute errors, it doesnt really work very well.

but after a bit of debugging i see error at form_set_error function as:

"<em>Primary Label</em> : This post can't be referenced."

and, this is the oddest part, function returns $form array and the index of the error msg entry in this array is:

field_primary_label][nids

yup, missing brackets and all.

liquidcms’s picture

i also get the same error when i try to use the cck export feature - copying any node type that uses noderef dies with this error.

bestknight’s picture

I get this error as well, when I try to disable a select control so that a specific role is not able to edit the value.

In the node/add/ccknodetype page I have a nodereference field to ccknodetype2 as a select box.
My goal is to dim out (disable) the cck node reference field for a particular role.
I have the following code in template.php:

function phptemplate_ccknodetype_node_form($form) {
  $output = '';
  
  global $user;
  if (in_array('contententry',$user->roles)) {
      $form['field_ccknodetype_fk_ccknodetype2']['nids']['#attributes']['disabled']= 'disabled';
  }
  else {
  '';   
  }
  
  $output .= drupal_render($form);
  return $output;
}

The default value is shown in the dimmed control (select box) but on preview / submission the following error appears:
ccknodetype2: This post can't be referenced.

Cross-referncing with http://drupal.org/node/250411

sun’s picture

Version: 5.x-1.6-1 » 5.x-1.7

Similar issue (to the original one) here. I'm unable to save a node containing a nodereference. While the autocomplete widget works and allows me to select a node, the message This post can't be referenced is displayed after submit.
There is nothing special about this nodereference field, so I really wonder whether there is a critical bug in nodereference.

sun’s picture

Sorry, that error was caused by myself.

gemini’s picture

Version: 5.x-1.7 » 5.x-1.x-dev

[self moderated, 'cause I'm an idiot]

KarenS’s picture

Status: Active » Closed (duplicate)

To the extent that this error is coming from either using Content Copy or drupal_execute() on the form, this is related to #128038: Critical failures using drupal_execute() on nodes with CCK fields, so I'll call this a duplicate.

adamtyoung’s picture

Did you find a fix for this? I just want to edit a node programmatically exactly like this but keep ending up with the same error message.

mwangi’s picture

I am getting the error when I truy to use node import but can enter data okay under node/add.

am using drupal 6.19 and CCK 6.x-2.8 any help would be appreciated

hutch120’s picture

I was using the import content module, so maybe this is in the wrong section, but I think it is the same issue, and google search led me here, so hopefully this is helpful for others.

So I think the basic problem was that two nodes had the same title but different content types. I assumed that the import would have matched against the content type as well as the title, but looks like it doesn't from my testing, one day I'll take a look at the source code, but unfortunately I have no time right now.

So firstly to troubleshoot, I found the node id by looking at the import preview screen and setting preview to 200 and searching for "this post can't be referenced".

So to fix this I called the node up in the url "node/1234/edit" and set the title to something more descriptive, and then found the same node of the correct content type and also renamed that title (although maybe not required as I'd renamed the other one) and then altered the CSV to match the new title. Re-imported, problem solved.

mwangi’s picture

i think this is a caching issue -- at least for me.

when I rename the post am referencing to and do a manual refresh - I can do the reference without a problem.

Hope this helps someone

vivdrupal’s picture

In my case this happened when there was no content created for some of the referenced content.

eg in reference from Matchday -> League -> season
when there was no content yet defined for some of the content of type league. Obviously the reference was created after creating the league - else this error would not be possible.

christianchristensen’s picture

msamavi’s picture

Exactly the same issue here, thanks hutch120 for the temporary troubleshooting!