Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
When I trying to see the new node in preview mode, the notice appear:
Notice: Trying to get property of non-object in plus1_build_node_jquery_widget() (line 282 of plus1.module)
It is because $node->nid is NULL in preview mode, but the function plus1_node_view did not consider this case.
This patch adds a checking value of $node->nid.
function plus1_node_view($node, $view_mode) {
// Only show the voting widget in allowed content types.
- if (in_array($node->type, variable_get('plus1_node_types', array()))) {
+ if ($node->nid && in_array($node->type, variable_get('plus1_node_types', array()))) {
if (($view_mode == 'teaser' && variable_get('plus1_node_in_teaser', 0)) || ($view_mode == 'full' && variable_get('plus1_node_in_full_view', 1))) {
$node->content['plus1_widget'] = plus1_build_node_jquery_widget($node->nid);
}
PS: sorry for my writing mistakes.
Comment | File | Size | Author |
---|---|---|---|
plus1-nid-is-null.patch | 729 bytes | ser_house |
Comments
Comment #1
rogical CreditAttribution: rogical commentedIn this way, the plus1 will never show in teaser mode, it's not good.
We need the plus1 also shows well on teaser mode.
Comment #2
rogical CreditAttribution: rogical commentedJust tested in the node preview, the dev seems working.
Comment #3
ser_house CreditAttribution: ser_house commentedUnfortunately (7.x-1.x-dev):
Comment #4
rogical CreditAttribution: rogical commentedCommitted, the patch runs quite well.