premium_node_level_data() doesn't check to see if $node->nid exists, so you get the message

Notice: Undefined property: stdClass::$nid in premium_node_level_data() (line 319)

when you create a node (not when you edit an existing node because $node->nid is then set)

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

dgtlmoon’s picture

Status: Active » Needs review
mikl’s picture

Status: Needs review » Reviewed & tested by the community

Looks good to me.

dgtlmoon’s picture

Status: Reviewed & tested by the community » Fixed

comitted

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

rurri’s picture

Status: Closed (fixed) » Needs work

This patch needs some work. While it correctly causes the error message to disappear it breaks the default premium type selection for the new node.

It also hides the fact that there is a bug in the way that the value for the premium select box is being selected.

The following code seems to fix both of these problems:

function premium_form_alter(&$form, $form_state, $form_id) {
  if (isset($form['type']['#value']) && $form['type']['#value'] . '_node_form' == $form_id) {
    if (user_access('administer node premium status')) {
      $node = $form['#node'];
      if (isset($node->nid)) {
        $premium_level = premium_node_level($node);
      } else {
        $premium_level = premium_node_level($node->type);
      }
      
      $form['options']['premium'] = array(
        '#type' => 'select',
        '#title' => t('Premium content level'),
        '#default_value' => $premium_level,
        '#options' => array(0 => t('None')) + premium_level_option_list(),
      );
    }
  }
}
dgtlmoon’s picture

can you provide as a patch?

Yoran Scholiers’s picture

This is still a issue, or am I wrong?
I ask this because I get the same notice when I'm creating a node.

Anonymous’s picture

#5 fixed the problem for me, fwiw

I was getting the following errors on the add content form, but no longer there, and the premium_content level that the content type is set to default to is appearing as it should:

Notice: Undefined property: stdClass::$nid in premium_node_level_data() (line 319 of .../premium_content/premium.module).
Notice: Undefined index: machine_name in premium_form_alter() (line 160 of .../premium_content/premium.module).
vparfaniuc’s picture

Status: Needs work » Needs review
FileSize
1.83 KB

Since the latest version of the module still has this issue, here is a patch which fixed the error on my projects

dgtlmoon’s picture

Status: Needs review » Needs work

@vparfaniuc code style has broken indentation

pjcdawkins’s picture

Issue summary: View changes
Status: Needs work » Needs review
FileSize
1.64 KB
pjcdawkins’s picture

FileSize
857 bytes

Trimmed irrelevant changes