Created
September 19, 2012 06:38
-
-
Save and1truong/3748033 to your computer and use it in GitHub Desktop.
Workflow Feature
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| … |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * @file wbm_vocab.admin.inc | |
| * | |
| * Function for admin pages. | |
| */ | |
| /** | |
| * Alter to node type settings form. | |
| */ | |
| function _wbm_vocab_form_node_type_form_alter(&$form, &$form_state) { | |
| // No fields, no vocab will be found | |
| if (!$bundle = $form['type']['#default_value']) return; | |
| $vocabularies = array(); | |
| // Loop throught fields | |
| foreach (field_info_instances('node', $bundle) as $field_name => $field_info) { | |
| $label = $field_info['label']; | |
| if ($field_info['deleted']) continue; | |
| if (!$field_info = field_read_field($field_name)) continue; | |
| if ('taxonomy' !== $field_info['module']) continue; | |
| $vocabularies[$field_name] = $label; | |
| } | |
| if (empty($vocabularies)) return; | |
| $form['workflow']['moderation_vocabs'] = array( | |
| '#type' => 'fieldset', | |
| '#title' => t('Moderation State - Vocabulary'), | |
| '#description' => t('Vocabulary to attaches with moderation state. Vocabularied used here, will not visible on node editing form.'), | |
| '#weight' => 100, | |
| ); | |
| foreach (workbench_moderation_state_labels() as $state => $label) { | |
| $form['workflow']['moderation_vocabs']["wbm_vocab_{$state}"] = array( | |
| '#type' => 'checkboxes', | |
| '#multiple' => TRUE, | |
| '#title' => t($label), | |
| '#options' => $vocabularies, | |
| '#default_value' => variable_get("wbm_vocab_{$state}_{$bundle}"), | |
| '#states' => array('visible' => array(':input[name="node_options[moderation]"]' => array('checked' => TRUE))), | |
| ); | |
| } | |
| } | |
| /** | |
| * Alter to workbench moderation form. | |
| */ | |
| function _wbm_vocab_form_workbench_moderation_moderate_form_alter(&$form, &$form_state) { | |
| $node = &$form['node']['#value']; | |
| if (!isset($node->workbench_moderation['current']->state)) return; | |
| $vocab_fields = "wbm_vocab_{$node->workbench_moderation['current']->state}_{$node->type}"; | |
| if (!$vocab_fields = variable_get($vocab_fields)) return; | |
| foreach ($vocab_fields as $vocab_field) { | |
| if (!$field_instance = field_info_instance('node', $vocab_field, $node->type)) return; | |
| if (!$field = field_read_field($vocab_field)) return; | |
| // Submit handler need not to reload this | |
| $form['#wbm_vocab_fields'][] = $vocab_field; | |
| $widget_form = "{$field_instance['widget']['module']}_field_widget_form"; | |
| $form['wbm_vocab'][$vocab_field] = $widget_form($form, $form_state, $field, $field_instance, $node->language, $node->{$vocab_field}[LANGUAGE_NONE], 0, $element = array()); | |
| $form['wbm_vocab'][$vocab_field]['#title'] = $field_instance['label']; | |
| } | |
| if (!empty($form['wbm_vocab'])) { | |
| $form['wbm_vocab'] += array( | |
| '#type' => 'container', | |
| '#title' => t('Vocabularies'), | |
| ); | |
| } | |
| $form['submit']['#weight'] = 100; | |
| array_unshift($form['#submit'], 'wbm_vocab_form_workbench_moderation_moderate_form_submit'); | |
| } | |
| /** | |
| * Custom submit handler for workbench moderation form. | |
| */ | |
| function wbm_vocab_form_workbench_moderation_moderate_form_submit($form, &$form_state) { | |
| // Make sure the node is not out of date | |
| $node = node_load($form_state['values']['node']->nid); | |
| foreach ($form['#wbm_vocab_fields'] as $vocab_field) { | |
| $node->{$vocab_field}[LANGUAGE_NONE] = array(); | |
| foreach ($form_state['values'][$vocab_field] as $v) { | |
| $node->{$vocab_field}[LANGUAGE_NONE][] = $v; | |
| } | |
| } | |
| node_save($node); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name = VC Workbench | |
| version = 7.x-1.0-alpha1 | |
| description = Add taxonomy widget to moderation forms | |
| package = Workbench | |
| core = 7.x | |
| files[] = wbm_vocab.module | |
| files[] = wbm_vocab.install | |
| dependencies[] = taxonomy | |
| dependencies[] = workbench | |
| dependencies[] = workbench_moderation |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * @file wbm_vocab.install | |
| * TODO: Enter file description here. | |
| */ | |
| /** | |
| * Implements hook_uninstall(). | |
| */ | |
| function wbm_vocab_uninstall() { | |
| foreach (array_keys($GLOBALS['config']) as $name) { | |
| if (strpos($name, 'wbm_vocab') === 0) { | |
| variable_del($name); | |
| } | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * @file wbm_vocab.module | |
| * | |
| * Attach vocabulary to workbench moderation form. | |
| * | |
| * @TODO: Hook to workbench state delete. The module does not provide the hook yet. | |
| */ | |
| /** | |
| * Implements hook_form_FORM_ID_alter(). | |
| * | |
| * Alter to workbench moderation form. | |
| */ | |
| function wbm_vocab_form_workbench_moderation_moderate_form_alter(&$form, &$form_state) { | |
| module_load_include('admin.inc', 'wbm_vocab', 'wbm_vocab'); | |
| return _wbm_vocab_form_workbench_moderation_moderate_form_alter($form, $form_state); | |
| } | |
| /** | |
| * Implements hook_form_FORM_ID_alter(). | |
| * | |
| * Alter to node type settings form. | |
| */ | |
| function wbm_vocab_form_node_type_form_alter(&$form, &$form_state) { | |
| module_load_include('admin.inc', 'wbm_vocab', 'wbm_vocab'); | |
| return _wbm_vocab_form_node_type_form_alter($form, $form_state); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment