0

In admin/content page we have some update options. I want to execute a Php code only when I use publish selected content or unpublished selected content on that page.

This rules should be fired JUST when I publish/unpublished selected content

1
  • What do you want to happen if some selected content gets published (or unpublished) without using "admin/content" (eg simply using a node edit form to do so)? Jul 11 '16 at 14:01
0

You can use drupal's hook_form_alter() for firing your PHP code. Check below example:

function contr_form_alter(&$form, &$form_state, $form_id) {
  if($form_id == 'node_admin_content'){
    $form['admin']['options']['submit']['#submit'][] = 'CUSTOM_SUBMIT_HANDLER';
  }
}

and then you can write your PHP code in CUSTOM_SUBMIT_HANDLER function as below:

function CUSTOM_SUBMIT_HANDLER($form, $form_state){
  if($form_state['values']['operation'] == 'publish'){
    // Do your stuff when PUBLISH here.
  }elseif ($form_state['values']['operation'] == 'unpublish') {
    // Do your stuff when UNPUBLISH here.    
  }
}
0

You probably need to alter the action performed on publish or unpublish of the node.

Try using hook_action_info_alter to alter the existing actions.

https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_action_info_alter/7.x

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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