0

Using the Publish Button module, I added Publish/Unpublish buttons to some of my nodes. I want the site to perform an action every time an admin clicks "Publish" after editing a node.

I followed some instructions from this answer, but my php code always evaluates to false. Since $form_state['clicked_button']['#value'] is deprecated, I tried another approach. I added a #name attribute ('publish') to the button (line 103 of publish_button.module) and wrote this function inside the Rules interface (execute custom php code):

function button_check() {
$values = $form_state['input'];
  if (isset($values['publish']) {
    return true;
  } else {
    return false;
  }
}

This is the code from the module file (line 103):

    function publish_button_render_publish_button() {
  $publish_button = array(
    '#type' => 'submit',
    '#access' => TRUE,
    '#value' => t('Publish'),
    '#weight' => '30',
    '#name' => 'publish',
    // Add the submit handler.
    '#submit' => array('_publish_button_publish_node'),
  );
  return $publish_button;
}

I am aware that I might be making some serious beginner's mistakes here, but I am new to Drupal and php.

9
  • Hi, why not just use rules > groups.drupal.org/node/97454#comment-940263? Or, do you a specific trigger when the publish button is used rather than say marking the publish checkbox and clicking save?
    – Jason
    May 7, 2014 at 19:59
  • Your suggestion is good and I can solve my problem that way, but I would like to implement this button as a custom button with a specific purpose - to at once publish the node and perform some other actions. I would like to know why the above code isn't working and what the proper way would be. If I don't find a solution, I will certainly do as you suggested.
    – alouette
    May 7, 2014 at 20:22
  • Ok, can you clarify what you mean by "wrote this function inside the Rules interface"? As execute custom php code?
    – Jason
    May 7, 2014 at 20:28
  • Yes, that's exactly what I meant.
    – alouette
    May 7, 2014 at 20:29
  • Is that all of the code you're using the execute custom php? If so, then nothing is calling your function. Even if you do call your function, you're not passing the $form_state variable...I'm not even sure $form_state is going to be available. What trigger or reaction are using in your rule? I'm thinking you may need to take a completely different approach.
    – Jason
    May 7, 2014 at 20:35

0

Your Answer

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

Browse other questions tagged or ask your own question.