first import
This commit is contained in:
177
sites/all/modules/mb/mb_comment/mb_comment.admin.inc
Normal file
177
sites/all/modules/mb/mb_comment/mb_comment.admin.inc
Normal file
@@ -0,0 +1,177 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* @file
|
||||
* Function file to administer the MB Comment module settings.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Provides the central MB Content settings form.
|
||||
*/
|
||||
function mb_comment_admin() {
|
||||
$module = 'mb_comment';
|
||||
$mb_comment_mappings = mb_get_mappings($module);
|
||||
$mb_comment_values = mb_get_values($module);
|
||||
|
||||
$form['#mappings'] = $mb_comment_mappings;
|
||||
|
||||
foreach ($mb_comment_mappings as $type => $v) {
|
||||
// It makes no sense to use the MB Content module with the content type panel.
|
||||
if ($type == 'panel') {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Provide "Cancel" button settings.
|
||||
$form[$module][$type][$module . '_cancel_' . $type] = array(
|
||||
'#type' => 'select',
|
||||
'#options' => mb_cancel_button_positions(),
|
||||
'#default_value' => variable_get($module . '_cancel_' . $type, 0),
|
||||
);
|
||||
}
|
||||
|
||||
$form['submit']['save'] = array(
|
||||
'#type' => 'submit',
|
||||
'#name' => 'save',
|
||||
'#value' => t('Save')
|
||||
);
|
||||
$form['submit']['reset'] = array(
|
||||
'#type' => 'submit',
|
||||
'#name' => 'reset',
|
||||
'#value' => t('Reset to defaults'),
|
||||
);
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a central MB Content settings form page.
|
||||
*
|
||||
* @return
|
||||
* The complete HTML formatted administer page.
|
||||
*/
|
||||
function theme_mb_comment_admin($variables) {
|
||||
_mb_load_css('admin');
|
||||
|
||||
$module = 'mb_comment';
|
||||
$mappings = array();
|
||||
$output = '';
|
||||
$extra_info = '';
|
||||
$rows = array();
|
||||
|
||||
$form = drupal_get_form($module . '_admin');
|
||||
$mappings = $form['#mappings'];
|
||||
|
||||
$output = '<h3>' . t('Comment settings') . '</h3>';
|
||||
$output .= '<p>' . t('Which %module functions are used by different content type pages.', array('%module' => t('More Buttons Comment'))) . '</p>';
|
||||
|
||||
$header = array(t('Cancel'));
|
||||
|
||||
$i = 1;
|
||||
foreach ($mappings as $type => $maps) {
|
||||
// It makes no sense to use the MB Comment module with the content type panel.
|
||||
if ($type == 'panel') {
|
||||
// Define an additional information.
|
||||
$extra_info .= '<p>' . t('For the content type %type no settings can be made.', array('%type' => t($mappings['panel']['name']))) . '</p>';
|
||||
continue;
|
||||
}
|
||||
|
||||
// Convert underscores in the machine redeable type names to hyphen for right path building.
|
||||
$parsed_type = str_replace('_', '-', $type);
|
||||
|
||||
// Provide own odd/even functionality.
|
||||
$evenodd = $i % 2 ? 'odd-mb' : 'even-mb';
|
||||
$evenodd = $i & 1 ? 'odd-mb' : 'even-mb';
|
||||
|
||||
$type_link = 'admin/structure/types/manage/' . $parsed_type;
|
||||
$link = l($maps['name'], $type_link, array('query' => array('destination' => 'admin/config/mb/buttons/more-buttons-comment'), 'attributes' => array('title' => t('Edit this content type'))));
|
||||
|
||||
// The content type row; Include an link to directly edit the MB Content settings in the content type.
|
||||
$rows[] = array('data' => array($link), 'class' => array($evenodd . ' ' . $evenodd . '-type'));
|
||||
|
||||
// The row contains the form elements.
|
||||
$rows[] = array(
|
||||
'data' => array(
|
||||
drupal_render($form[$module][$type][$module . '_cancel_' . $type])
|
||||
),
|
||||
'class' => array($evenodd . ' ' . $evenodd . '-elements')
|
||||
);
|
||||
|
||||
unset($form[$module][$type]);
|
||||
++$i;
|
||||
}
|
||||
|
||||
$output .= theme('table', array(
|
||||
'header' => $header,
|
||||
'rows' => $rows,
|
||||
'attributes' => array('class' => array('mb-admin-table', $module . '-admin-table'))
|
||||
));
|
||||
|
||||
// Display additional informations.
|
||||
if ($extra_info != '') {
|
||||
$output .= $extra_info;
|
||||
}
|
||||
|
||||
$output .= drupal_render($output);
|
||||
$output .= drupal_render_children($form);
|
||||
$output .= '<p style="text-align: right">' . t('Module development by <a href="@development-url">Quiptime Group</a>.', array('@development-url' => url('http://www.quiptime.com'))) . '</p>';
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save settings from admin form.
|
||||
*/
|
||||
function mb_comment_admin_submit($form, &$form_state) {
|
||||
$module = 'mb_comment';
|
||||
$mappings = $form['#mappings'];
|
||||
|
||||
if ($form_state['clicked_button']['#id'] == 'edit-save') {
|
||||
// Save the MB Comment button settings.
|
||||
foreach ($mappings as $type => $maps) {
|
||||
if ($type == 'panel') {
|
||||
continue;
|
||||
}
|
||||
variable_set($module . '_cancel_' . $type, $form_state['values'][$module . '_cancel_' . $type]);
|
||||
}
|
||||
|
||||
drupal_set_message(t('The %module settings have been saved.', array('%module' => t('More Buttons Comment'))), 'status');
|
||||
}
|
||||
elseif ($form_state['clicked_button']['#id'] == 'edit-reset') {
|
||||
$form_state['redirect'] = 'admin/config/mb/buttons/more-buttons-comment/reset';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Menu callback to define the confirm form output.
|
||||
*
|
||||
* @return
|
||||
* The confirm form.
|
||||
*/
|
||||
function mb_comment_reset() {
|
||||
$question = t('Are you sure you want to reset all %module settings?', array('%module' => t('More Buttons Comment')));
|
||||
|
||||
$information = '<p>' . t('This action disables the settings for all buttons. This action cannot be undone.') . '</p>';
|
||||
|
||||
return confirm_form(array(),
|
||||
$question,
|
||||
array('path' => 'admin/config/mb/buttons/more-buttons-comment', 'attributes' => array('class' => 'button')), $information,
|
||||
t('Reset'),
|
||||
t('Cancel')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Resave all system variables of the MB Content module to reset the module settings.
|
||||
*/
|
||||
function mb_comment_reset_submit($form, &$form_state) {
|
||||
// Resave variables.
|
||||
$node_types = array_keys(node_type_get_types());
|
||||
foreach ($node_types as $type) {
|
||||
variable_set('mb_comment_cancel_' . $type, 0);
|
||||
}
|
||||
|
||||
drupal_set_message(t('The %module settings have been set back.', array('%module' => t('More Buttons Content'))), 'status');
|
||||
watchdog('More Buttons Comment', 'The %module settings have been set back.', array('%module' => t('More Buttons Comment')), WATCHDOG_NOTICE, l(t('view'), 'admin/config/mb/buttons/more-buttons-comment'));
|
||||
|
||||
$form_state['redirect'] = 'admin/config/mb/buttons/more-buttons-comment';
|
||||
}
|
15
sites/all/modules/mb/mb_comment/mb_comment.info
Normal file
15
sites/all/modules/mb/mb_comment/mb_comment.info
Normal file
@@ -0,0 +1,15 @@
|
||||
name = More Buttons Comment
|
||||
description = "Provides an <em>Cancel</em> button for comments."
|
||||
package = "More Buttons"
|
||||
dependencies[] = comment
|
||||
dependencies[] = mb
|
||||
core = 7.x
|
||||
files[] = mb_comment.module
|
||||
files[] = mb_comment.admin.module
|
||||
|
||||
; Information added by drupal.org packaging script on 2011-02-25
|
||||
version = "7.x-1.x-dev"
|
||||
core = "7.x"
|
||||
project = "mb"
|
||||
datestamp = "1298619614"
|
||||
|
17
sites/all/modules/mb/mb_comment/mb_comment.install
Normal file
17
sites/all/modules/mb/mb_comment/mb_comment.install
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Installs, updates, and uninstalls More Buttons Comment.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_uninstall().
|
||||
*/
|
||||
function mb_comment_uninstall() {
|
||||
// Remove variables.
|
||||
$node_types = array_keys(node_type_get_types());
|
||||
foreach ($node_types as $type) {
|
||||
variable_del('mb_comment_cancel_' . $type);
|
||||
}
|
||||
}
|
200
sites/all/modules/mb/mb_comment/mb_comment.module
Normal file
200
sites/all/modules/mb/mb_comment/mb_comment.module
Normal file
@@ -0,0 +1,200 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Provides a Cancel button for comments.
|
||||
*
|
||||
* Currently available buttons:
|
||||
* - Cancel
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_permission().
|
||||
*/
|
||||
function mb_comment_permission() {
|
||||
return array(
|
||||
'access mb comment' => array(
|
||||
'title' => t('Use More Comment Buttons'),
|
||||
'description' => t('Use the buttons defined by More Buttons Comment.')
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_menu().
|
||||
*/
|
||||
function mb_comment_menu() {
|
||||
$items = array();
|
||||
|
||||
$items['admin/config/mb/buttons/more-buttons-comment'] = array(
|
||||
'page callback' => 'drupal_get_form',
|
||||
'page arguments' => array('mb_comment_admin'),
|
||||
'title' => 'Comments',
|
||||
'access arguments' => array('administer site configuration'),
|
||||
'description' => 'An overview of what content type uses buttons/functions of the MB Comment module.',
|
||||
'file' => 'mb_comment.admin.inc',
|
||||
'type' => MENU_LOCAL_TASK,
|
||||
'weight' => 10
|
||||
);
|
||||
$items['admin/config/mb/buttons/more-buttons-comment/reset'] = array(
|
||||
'page callback' => 'drupal_get_form',
|
||||
'page arguments' => array('mb_comment_reset'),
|
||||
'access arguments' => array('administer site configuration'),
|
||||
'type' => MENU_CALLBACK,
|
||||
'file' => 'mb_comment.admin.inc'
|
||||
);
|
||||
|
||||
return $items;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_theme().
|
||||
*/
|
||||
function mb_comment_theme() {
|
||||
return array(
|
||||
'mb_comment_admin' => array(
|
||||
'variables' => array('form' => NULL),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_form_alter().
|
||||
*/
|
||||
function mb_comment_form_alter(&$form, &$form_state, $form_id) {
|
||||
$module = 'mb_comment';
|
||||
|
||||
if ($form['#id']) {
|
||||
if ($form['#id'] == 'comment-form') {
|
||||
$node = $form['#node'];
|
||||
|
||||
if (arg(0) == 'comment') {
|
||||
$default_values = mb_default_values();
|
||||
$mb_content_values = mb_get_values('mb');
|
||||
$destination = drupal_get_destination();
|
||||
|
||||
$settings = array();
|
||||
$settings['cancel'] = variable_get($module . '_cancel_' . $node->type, 0);
|
||||
|
||||
if (!preg_match('/comment\/reply/', url($_SERVER["HTTP_REFERER"]))) {
|
||||
$form['comment_referer'] = array(
|
||||
'#type' => 'value',
|
||||
'#value' => url($_SERVER["HTTP_REFERER"])
|
||||
);
|
||||
}
|
||||
|
||||
$form_state['cache'] = TRUE;
|
||||
|
||||
// Define the "Cancel" form element.
|
||||
if ($settings['cancel'] > 0) {
|
||||
if ($settings['cancel'] == 1) {
|
||||
$weight_cancel = $form['actions']['submit']['#weight'] - 1;
|
||||
}
|
||||
elseif ($settings['cancel'] == 2) {
|
||||
$weight_cancel = 16;
|
||||
}
|
||||
|
||||
$form['actions']['cancel'] = array(
|
||||
'#type' => 'submit',
|
||||
'#value' => isset($mb_comment_values['cancel']) ? t('@cancel-value', array('@cancel-value' => t($mb_comment_values['cancel']))) : t($default_values['cancel']),
|
||||
'#weight' => 30,
|
||||
'#validate' => array('mb_comment_cancel_validate')
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
switch ($form_id) {
|
||||
case 'node_type_delete_confirm':
|
||||
// Delete MB Comment content type system variables
|
||||
// if content types will be deleted.
|
||||
$form['#submit'][] = 'mb_comment_delete_confirm_submit';
|
||||
|
||||
break;
|
||||
|
||||
case 'node_type_form':
|
||||
// Provide the prepared additional MB Comment button settings.
|
||||
|
||||
// Check the specific case add content type form.
|
||||
if (empty($form['#node_type']->type)) {
|
||||
// Add content type.
|
||||
$type = 'mb_comment_type_dummy';
|
||||
}
|
||||
else {
|
||||
// Edit an content type.
|
||||
$type = $form['#node_type']->type;
|
||||
}
|
||||
|
||||
// It makes no sense to use the MB Comment module with the content type panel.
|
||||
if ($type == 'panel') {
|
||||
return;
|
||||
}
|
||||
|
||||
// The additional button settings.
|
||||
$form['comment_buttons'] = array(
|
||||
'#type' => 'fieldset',
|
||||
'#title' => t('Button settings - comments'),
|
||||
'#group' => 'additional_settings',
|
||||
'#collapsible' => TRUE,
|
||||
'#collapsed' => TRUE,
|
||||
'#weight' => 5,
|
||||
'#attached' => array(
|
||||
'js' => array(drupal_get_path('module', $module) . '/' . $module . '_node_form.js')
|
||||
)
|
||||
);
|
||||
|
||||
// Provide "Cancel" button settings.
|
||||
$form['comment_buttons'][$module . '_cancel'] = array(
|
||||
'#type' => 'select',
|
||||
'#title' => t('Cancel button'),
|
||||
'#description' => t('Please select using the button or its position.'),
|
||||
'#options' => mb_cancel_button_positions(),
|
||||
'#default_value' => variable_get($module . '_cancel_' . $type, 0)
|
||||
);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_validate().
|
||||
*
|
||||
* Handle the "Cancel" button validation.
|
||||
*/
|
||||
function mb_comment_cancel_validate(&$form, &$form_state) {
|
||||
// This is the cancel action. No validation required.
|
||||
mb_comment_cancel_action($form, $form_state);
|
||||
}
|
||||
|
||||
/**
|
||||
* The "Cancel" action.
|
||||
*
|
||||
* Handle different submit actions and make different redirects.
|
||||
*
|
||||
* @see mb_comment_cancel_validate()
|
||||
*/
|
||||
function mb_comment_cancel_action(&$form, &$form_state) {
|
||||
// Hide the error messages.
|
||||
drupal_get_messages('error');
|
||||
|
||||
$redirect = 'node/' . $form['nid']['#value'];
|
||||
|
||||
if (isset($form['comment_referer']['#value'])) {
|
||||
$redirect = $form['comment_referer']['#value'];
|
||||
}
|
||||
|
||||
drupal_goto($redirect);
|
||||
}
|
||||
|
||||
/**
|
||||
* Submit callback to delete MB Comment content type system variables
|
||||
* if content types will be deleted.
|
||||
*/
|
||||
function mb_comment_delete_confirm_submit($form, &$form_state) {
|
||||
$module = 'mb_comment';
|
||||
|
||||
foreach ($form_state['build_info']['args'] as $type) {
|
||||
variable_del($module . '_cancel_' . $type->type);
|
||||
}
|
||||
}
|
20
sites/all/modules/mb/mb_comment/mb_comment_node_form.js
Normal file
20
sites/all/modules/mb/mb_comment/mb_comment_node_form.js
Normal file
@@ -0,0 +1,20 @@
|
||||
|
||||
(function ($) {
|
||||
|
||||
Drupal.behaviors.mbCommentFieldsetSummaries = {
|
||||
attach: function (context) {
|
||||
// Provide the summary for the content type form.
|
||||
$('fieldset#edit-comment-buttons', context).drupalSetSummary(function(context) {
|
||||
var vals = [];
|
||||
|
||||
// Cancel button.
|
||||
var cancel = $("select[name='mb_comment_cancel'] option:selected", context).text();
|
||||
cancel = Drupal.t('Cancel button') + ": " + cancel;
|
||||
vals.push(cancel);
|
||||
|
||||
return Drupal.checkPlain(vals.join(', '));
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
})(jQuery);
|
Reference in New Issue
Block a user