Skip to main content
added 234 characters in body
Source Link
Mouneer
  • 178
  • 8

The Problem was that workbench_moderation_moderate() calls internally hook_workbench_moderation_transition() so I decided to do it with another technique that should cover the two ways that workbench moderation uses to change the state

First way to be covered, the links that exist in workbench moderation back end views. I implemented hook_menu_alter to intercept the request from those links to add my custom logic.

function my_custom_logic($node, $state){
   //add your logic here
}

/**
* Implements hook_menu_alter()
*/
function workflow_handler_menu_alter(&$items){
  $items["node/%node/moderation/%/change-state/%"] = array(
    'page callback' => 'workflow_handler_moderate_callback',
    'title' => 'Change moderation state',
    'page arguments' => array(1, 5),
    'load arguments' => array(3),
    'access callback' => 'workflow_handler_moderate_access',
    'access arguments' => array(1, 5),
    'type' => MENU_CALLBACK,
  );
}

function ei_workflow_handler_moderate_access($node, $state){
  return _workbench_moderation_moderate_access($node, $state);
}

function workflow_handler_moderate_callback($node, $state){
  my_custom_logic($node, $state);
  workbench_moderation_moderate_callback($node, $state);
}

Second way to be handled, the form that workbench adds in every node details page. I implemented hook_form_alter to add my submit handler before workbench moderation one and I added my logic again there.

/**
* Implements hook_form_alter()
*/
function ei_workflow_handler_form_alter(&$form, &$form_state,$form_id){
    if($form_id == 'workbench_moderation_moderate_form'){
      $form['submit']['#submit'][] ='my_custom_logic_handler';
    }
}

function my_custom_logic_handler ($form, &$form_state) {
  my_custom_logic($form_state['values']['node'], $form_state['values']['state']);
}

Hopefully this helps anyone who encounter that issue in the future.

The Problem was that workbench_moderation_moderate() calls internally hook_workbench_moderation_transition() so I decided to do it with another technique that should cover the two ways that workbench moderation uses to change the state

First way to be covered, the links that exist in workbench moderation back end views. I implemented hook_menu_alter to intercept the request from those links to add my custom logic.

/**
* Implements hook_menu_alter()
*/
function workflow_handler_menu_alter(&$items){
  $items["node/%node/moderation/%/change-state/%"] = array(
    'page callback' => 'workflow_handler_moderate_callback',
    'title' => 'Change moderation state',
    'page arguments' => array(1, 5),
    'load arguments' => array(3),
    'access callback' => 'workflow_handler_moderate_access',
    'access arguments' => array(1, 5),
    'type' => MENU_CALLBACK,
  );
}

function ei_workflow_handler_moderate_access($node, $state){
  return _workbench_moderation_moderate_access($node, $state);
}

function workflow_handler_moderate_callback($node, $state){
  my_custom_logic($node, $state);
  workbench_moderation_moderate_callback($node, $state);
}

Second way to be handled, the form that workbench adds in every node details page. I implemented hook_form_alter to add my submit handler before workbench moderation one and I added my logic again there.

/**
* Implements hook_form_alter()
*/
function ei_workflow_handler_form_alter(&$form, &$form_state,$form_id){
    if($form_id == 'workbench_moderation_moderate_form'){
      $form['submit']['#submit'][] ='my_custom_logic_handler';
    }
}

Hopefully this helps anyone who encounter that issue in the future.

The Problem was that workbench_moderation_moderate() calls internally hook_workbench_moderation_transition() so I decided to do it with another technique that should cover the two ways that workbench moderation uses to change the state

First way to be covered, the links that exist in workbench moderation back end views. I implemented hook_menu_alter to intercept the request from those links to add my custom logic.

function my_custom_logic($node, $state){
   //add your logic here
}

/**
* Implements hook_menu_alter()
*/
function workflow_handler_menu_alter(&$items){
  $items["node/%node/moderation/%/change-state/%"] = array(
    'page callback' => 'workflow_handler_moderate_callback',
    'title' => 'Change moderation state',
    'page arguments' => array(1, 5),
    'load arguments' => array(3),
    'access callback' => 'workflow_handler_moderate_access',
    'access arguments' => array(1, 5),
    'type' => MENU_CALLBACK,
  );
}

function ei_workflow_handler_moderate_access($node, $state){
  return _workbench_moderation_moderate_access($node, $state);
}

function workflow_handler_moderate_callback($node, $state){
  my_custom_logic($node, $state);
  workbench_moderation_moderate_callback($node, $state);
}

Second way to be handled, the form that workbench adds in every node details page. I implemented hook_form_alter to add my submit handler before workbench moderation one and I added my logic again there.

/**
* Implements hook_form_alter()
*/
function ei_workflow_handler_form_alter(&$form, &$form_state,$form_id){
    if($form_id == 'workbench_moderation_moderate_form'){
      $form['submit']['#submit'][] ='my_custom_logic_handler';
    }
}

function my_custom_logic_handler ($form, &$form_state) {
  my_custom_logic($form_state['values']['node'], $form_state['values']['state']);
}

Hopefully this helps anyone who encounter that issue in the future.

Source Link
Mouneer
  • 178
  • 8

The Problem was that workbench_moderation_moderate() calls internally hook_workbench_moderation_transition() so I decided to do it with another technique that should cover the two ways that workbench moderation uses to change the state

First way to be covered, the links that exist in workbench moderation back end views. I implemented hook_menu_alter to intercept the request from those links to add my custom logic.

/**
* Implements hook_menu_alter()
*/
function workflow_handler_menu_alter(&$items){
  $items["node/%node/moderation/%/change-state/%"] = array(
    'page callback' => 'workflow_handler_moderate_callback',
    'title' => 'Change moderation state',
    'page arguments' => array(1, 5),
    'load arguments' => array(3),
    'access callback' => 'workflow_handler_moderate_access',
    'access arguments' => array(1, 5),
    'type' => MENU_CALLBACK,
  );
}

function ei_workflow_handler_moderate_access($node, $state){
  return _workbench_moderation_moderate_access($node, $state);
}

function workflow_handler_moderate_callback($node, $state){
  my_custom_logic($node, $state);
  workbench_moderation_moderate_callback($node, $state);
}

Second way to be handled, the form that workbench adds in every node details page. I implemented hook_form_alter to add my submit handler before workbench moderation one and I added my logic again there.

/**
* Implements hook_form_alter()
*/
function ei_workflow_handler_form_alter(&$form, &$form_state,$form_id){
    if($form_id == 'workbench_moderation_moderate_form'){
      $form['submit']['#submit'][] ='my_custom_logic_handler';
    }
}

Hopefully this helps anyone who encounter that issue in the future.