1

I have a Pay2Publish module, which gets no support these days, so I have to turn to the community for the help. I guess this is a simple PHP question:

I want to take the messages generated by Pay2Publish module and display them bellow each node teaser.

Here's the code from the module:

/**
 * Implements hook_node_view()
 * 
 * Displays the Message for the author of a node
 */
function ms_paypublish_node_view($node, $view_mode, $langcode) {
  $plans = variable_get('ms_paypublish_plan_' . $node->type, array());
  $pp_node = ms_paypublish_load_node_nid($node->nid);

  if ($pp_node AND !empty($plans)) {
    if ($view_mode == 'full' AND user_access('renew own pay to publish nodes')) {
      global $user;
      if ($node->uid == $user->uid) {
        switch ($pp_node->status) {
          case 0: // Not Published
            drupal_set_message(
              str_replace(
                '!link', 
                l(t('Publish'), 'ms_paypublish/publish/' . $node->nid), 
                variable_get('ms_paypublish_not_published_text', 'This content is not published. To publish, please click here: !link')
              )
            );
            break;

          case 1: // Published
            if ($pp_node->expiration_date) {
              drupal_set_message(
                str_replace(
                  array('!days','!link'), 
                  array(
                    ms_paypublish_get_expiration_string(ms_paypublish_get_expiration($node->nid)),
                    l(t('Promote / Extend'), 'ms_paypublish/publish/' . $node->nid)
                  ), 
                  variable_get('ms_paypublish_published_text', 'This content will expire in !days days. To Promote / Extend, please click here: !link')
                )
              );
            }
            break;

          case 2: // Awaiting Admin Approval
          case 5:
            drupal_set_message(variable_get('ms_paypublish_approval_text', 'This content is Awaiting Admin Approval. It will be published shortly.'));
            break;

          case 3: // Not yet published
            drupal_set_message(str_replace('!link', l(t('Publish'), 'ms_paypublish/publish/' . $node->nid), variable_get('ms_paypublish_publish_text', 'This content has not been published yet. To publish, please click here: !link')));
            break;
        }
      }
    }
  }
} 

What do I need to put inside my custom node--content-type.tpl.php so that these messages are displayed below each teaser?

1 Answer 1

1

My suggestion is:

  1. Change this line in hook_node_view() if ($view_mode == 'full' AND user_access('renew own pay to publish nodes')) { and add $view_mode == 'teaser' to it. Then you can create a patch and submit to community, if you think that this feature may be needed by other users.

  2. You can create a template file for this content type, store the messages in a theme variable and display them in template file, just use <?php print $VARIBALE_NAME ?> You also have to write a template preprocess function where you will write code to get message body.

I think second option is the best. The requirement is not generic and changing the module is not right in this case. However, you can search the module's issue queue for this.

References

2
  • I pasted that code inside my_theme_preprocess_node of the template.php, but what do I need to replace "drupal_set_message"??? What is the correct syntax? And what do I need to put inside the node--content-type.tpl.php
    – drupalina
    Oct 17, 2013 at 7:04
  • I have changed the answer see if that helps Oct 17, 2013 at 7:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.