Skip to content
This repository was archived by the owner on May 9, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions cm_tools.info
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
name = "Computerminds tools"
core = "7.x"
description = "A collection of tools and helpers written by Computerminds."

files[] = "handlers/ajax_operations/CMToolsAjaxOperation.inc"
files[] = "handlers/ajax_operations/CMToolsAjaxOperationBroken.inc"
files[] = "handlers/ajax_operations/CMToolsAjaxOperationInterface.inc"
151 changes: 150 additions & 1 deletion cm_tools.module
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,115 @@

include_once 'cm_tools.element.inc';

/**
* Implements hook_menu().
*/
function cm_tools_menu() {
$items = array();

$items['ajax-operation/%cm_tools_ajax_operation'] = array(
'title' => 'AJAX Operation',
'page callback' => 'cm_tools_ajax_operation_callback',
'page arguments' => array(1),
'delivery callback' => 'ajax_deliver',
'access callback' => 'cm_tools_ajax_operation_access',
'access arguments' => array(1),
'theme callback' => 'ajax_base_page_theme',
'type' => MENU_CALLBACK,
'file' => 'includes/ajax_operations.inc',
);

return $items;
}

/**
* Menu loader for cm_tools ajax operations.
*
* @param $operation_name
*
* @return CMToolsAjaxOperationInterface|FALSE
*/
function cm_tools_ajax_operation_load($operation_name) {
ctools_include('plugins');
if (($plugin = ctools_get_plugins('cm_tools', 'ajax_operation', $operation_name)) && ($class = ctools_plugin_get_class($plugin, 'handler'))) {
$op = new $class();
$op->setPluginInfo($plugin);
return $op;
}
return FALSE;
}

/**
* Determine whether a user has access to the given
* ajax operation.
*
* @param CMToolsAjaxOperationInterface $op
* @param null $account
* (Optional) The user account to check access for.
* Defaults to the currently logged in user.
*
* @return boolean
*/
function cm_tools_ajax_operation_access(CMToolsAjaxOperationInterface $op, $account = NULL) {
if (!isset($account)) {
$account = $GLOBALS['user'];
}
return $op->access($account);
}

/**
* Implements hook_ctools_plugin_type().
*/
function cm_tools_ctools_plugin_type() {
return array(
'ajax_operation' => array(
'cache' => TRUE,
'use hooks' => TRUE,
'hook' => 'cm_tools_ajax_operations',
'classes' => array('handler'),
'alterable' => TRUE,
'defaults' => array(
'abstract' => FALSE,
'label' => 'Broken Ajax Operation',
'description' => '',
'parameters' => array(),
'handler' => array(
'class' => 'CMToolsAjaxOperationBroken',
'file' => 'CMToolsAjaxOperationBroken.inc',
'path' => drupal_get_path('module', 'cm_tools') . '/handlers/ajax_operations',
),
),
),
);
}

/**
* Implements hook_ctools_plugin_api().
*
* @param $owner
* @param $api
* @return mixed
*/
function cm_tools_ctools_plugin_api($owner, $api) {
if ($owner === 'cm_tools' && $api === 'ajax_operation') {
return 1;
}
}

/**
* Implements hook_hook_info().
*/
function cm_tools_hook_info() {
$hooks = array();
$hooks['cm_tools_ajax_operations'] = array(
'group' => 'ajax_operations',
);
$hooks['cm_tools_ajax_operations_alter'] = array(
'group' => 'ajax_operations',
);
return $hooks;
}

/**
* Include .inc files as necessary.
*
Expand Down Expand Up @@ -51,6 +160,46 @@ function cm_tools_form_include(&$form_state, $file, $module = 'cm_tools', $dir =
form_load_include($form_state, 'inc', $module, $dir . $file);
}

/**
* Include js files as necessary.
*
* This helper function is used by ctools but can also be used in other
* modules in the same way as explained in the comments of ctools_include.
*
* @param $file
* The base file name to be included.
* @param $module
* Optional module containing the include.
* @param $dir
* Optional subdirectory containing the include file.
*/
function cm_tools_add_js($file, $module = 'cm_tools', $dir = 'js') {
drupal_add_js(drupal_get_path('module', $module) . "/$dir/$file.js");
}

/**
* Format a javascript file name for use with $form['#attached']['js'].
*
* This helper function is used by ctools but can also be used in other
* modules in the same way as explained in the comments of ctools_include.
*
* @code
* $form['#attached']['js'] = array(ctools_attach_js('auto-submit'));
* @endcode
*
* @param $file
* The base file name to be included.
* @param $module
* Optional module containing the include.
* @param $dir
* Optional subdirectory containing the include file.
*
* @return string
*/
function cm_tools_attach_js($file, $module = 'cm_tools', $dir = 'js') {
return drupal_get_path('module', $module) . "/$dir/$file.js";
}

/**
* Inserts one or more suggestions into a theme_hook_suggestions array.
*
Expand Down Expand Up @@ -309,7 +458,7 @@ function cm_tools_array_remove_values(&$haystack, $values) {

foreach ($values as $value_to_remove) {
$key = array_search($value_to_remove, $haystack);
if ($key !== false) {
if ($key !== FALSE) {
unset($haystack[$key]);
}
}
Expand Down
Loading