hook_node_api: Move code inside the conditional

Todd Nienkerk - February 11, 2009 - 09:23
Project:Read More link (Drupal 6 and earlier)
Version:6.x-3.x-dev
Component:Code
Category:bug report
Priority:normal
Assigned:Todd Nienkerk
Status:closed
Description

The current 3.0 version does a bunch of stuff before checking if the module should move the link:

<?php
function ed_readmore_nodeapi(&$node, $op, $teaser, $page) {
 
$enabled = variable_get('ed_readmore_readmore_tweak', 1);
 
$inlineflag = variable_get('ed_readmore_readmore_inline', 1);
 
$strong = variable_get('ed_readmore_readmore_strong', 1);

  if (
$strong) {
   
$strong_l = '<strong>';
   
$strong_r = '</strong>';
  }
  else {
   
$strong_l = '';
   
$strong_r = '';
  }
 
$link_text = $strong_l . t(variable_get('ed_readmore_text', ED_READMORE_TEXT_DEFAULT)) . $strong_r;
 
$options = array('html' => true);
 
$readmore_url = l($link_text, "node/$node->nid", $options);
  if (
$enabled) {

    ...
?>

It should probably look like this:

<?php
function ed_readmore_nodeapi(&$node, $op, $teaser, $page) {
  if (
variable_get('ed_readmore_readmore_tweak', 1)) {
   
$inlineflag = variable_get('ed_readmore_readmore_inline', 1);
   
$strong = variable_get('ed_readmore_readmore_strong', 1);

    if (
$strong) {
     
$strong_l = '<strong>';
     
$strong_r = '</strong>';
    }
    else {
     
$strong_l = '';
     
$strong_r = '';
    }
   
$link_text = $strong_l . t(variable_get('ed_readmore_text', ED_READMORE_TEXT_DEFAULT)) . $strong_r;
   
$options = array('html' => true);
   
$readmore_url = l($link_text, "node/$node->nid", $options);

    ...
?>

#1

Todd Nienkerk - February 11, 2009 - 09:24
Title:hooke_node_api: Move code inside the conditional» hook_node_api: Move code inside the conditional

Fixing typo in title.

#2

Todd Nienkerk - February 13, 2009 - 08:18
Version:6.x-3.0» 6.x-3.x-dev
Status:active» fixed

Fixed in the 3.x-dev branch.

#3

Todd Nienkerk - February 14, 2009 - 22:10
Assigned to:Anonymous» Todd Nienkerk

#4

System Message - February 28, 2009 - 22:20
Status:fixed» closed

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

 
 

Drupal is a registered trademark of Dries Buytaert.