Commit a1555d71 authored by TravisCarden's avatar TravisCarden
Browse files

Switched to #attribute style array keys on checklist definitions.

parent 3ebd8bc7
......@@ -31,11 +31,11 @@
*/
function hook_checklistapi_checklist_info_alter(&$checklists) {
// Add an item.
$checklists['example']['groups']['example_group']['items']['sample_item'] = array(
$checklists['example']['example_group']['sample_item'] = array(
'title' => t('Sample item'),
);
// Remove an item.
unset($checklists['example']['groups']['example_group']['items']['example_item']);
unset($checklists['example']['example_group']['example_item']);
}
/**
......@@ -48,39 +48,40 @@ function hook_checklistapi_checklist_info_alter(&$checklists) {
* An array of checklists. Each checklist is keyed by an arbitrary unique
* identifier. The corresponding multidimensional array describing the
* checklist may contain the following key-value pairs:
* - title: Required. The title of the checklist.
* - description: A brief description of the checklist for its corresponding
* - #title: Required. The title of the checklist.
* - #description: A brief description of the checklist for its corresponding
* menu item.
* - path: Required. The Drupal path where the checklist will be accessed.
* - menu_name: Set this to a custom menu if you don't want your item to be
* - #path: Required. The Drupal path where the checklist will be accessed.
* - #menu_name: Set this to a custom menu if you don't want your item to be
* placed in Navigation.
* - weight: An integer used to sort the list of checklists before being
* - #weight: An integer used to sort the list of checklists before being
* output; lower numbers appear before higher numbers.
* - groups: An array of containers for grouping items, presented as vertical
* - Any number of arrays representing groups of items, presented as vertical
* tabs. Each group is keyed by an arbitrary unique identifier. The
* corresponding multimensional array describing the group may contain the
* following key-value pairs:
* - title: Required. The title of the group used as the vertical tab label.
* - description: A description of the group.
* - weight: An integer used to sort the list of groups before being output;
* lower numbers appear before higher numbers.
* - items: An array of checklist items. Each item is keyed by an arbitrary
* unique identifier. The corresponding multimensional array describing
* the item may contain the following key-value pairs:
* - title: Required. The title of the item.
* - description: A description of the item.
* - default_value: The default checked state of the item--TRUE for
* - #title: Required. The title of the group used as the vertical tab
* label.
* - #description: A description of the group.
* - #weight: An integer used to sort the list of groups before being
* output; lower numbers appear before higher numbers.
* - Any number of arrays representing checklist items. Each item is keyed
* by an arbitrary unique identifier. The corresponding multimensional
* array describing the item may contain the following key-value pairs:
* - #title: Required. The title of the item.
* - #description: A description of the item.
* - #default_value: The default checked state of the item--TRUE for
* checked or FALSE for unchecked. Defaults to FALSE. This is useful for
* automatically checking off tasks that can be programmatically tested
* (e.g. a module is installed or a setting set).
* - weight: An integer used to sort the list of items before being
* - #weight: An integer used to sort the list of items before being
* output; lower numbers appear before higher numbers.
* - links: An array of links. Each link is keyed by an arbitrary unique
* identifier. The corresponding multimensional array describing the
* link may contain the following key-value pairs:
* - text: The link text.
* - path: The link path.
* - context: The context in which the link may appear. May be one of
* - Any number of arrays representing links. Each link is keyed by an
* arbitrary unique identifier. The corresponding multimensional array
* describing the link may contain the following key-value pairs:
* - #text: The link text.
* - #path: The link path.
* - #context: The context in which the link may appear. May be one of
* the following:
* - CHECKLISTAPI_LINK_CONTEXT_ANY: Default. The link will always
* appear.
......@@ -88,8 +89,8 @@ function hook_checklistapi_checklist_info_alter(&$checklists) {
* the item it belongs to has been checked off.
* - CHECKLISTAPI_LINK_CONTEXT_ITEM_UNCHECKED: The link will appear if
* the item it belongs to has not checked off.
* - options: An associative array of additional options used by the l()
* function.
* - #options: An associative array of additional options used by the
* l() function.
*
* For a detailed usage example, see checklistapi_example.module.
*
......@@ -100,24 +101,18 @@ function hook_checklistapi_checklist_info() {
$checklists = array();
$checklists['example'] = array(
'title' => t('Example checklist'),
'description' => t('An example checklist.'),
'path' => 'example-checklist',
'help' => t('<p>This is an example checklist.</p>'),
'groups' => array(
'example_group' => array(
'title' => t('Example group'),
'description' => t('<p>Here are some example items.</p>'),
'items' => array(
'example_item' => array(
'title' => t('Example item'),
'links' => array(
'example_link' => array(
'text' => t('Example.com'),
'path' => 'http://www.example.com/',
),
),
),
'#title' => t('Example checklist'),
'#description' => t('An example checklist.'),
'#path' => 'example-checklist',
'#help' => t('<p>This is an example checklist.</p>'),
'example_group' => array(
'#title' => t('Example group'),
'#description' => t('<p>Here are some example items.</p>'),
'example_item' => array(
'#title' => t('Example item'),
'example_link' => array(
'text' => t('Example.com'),
'path' => 'http://www.example.com/',
),
),
),
......
......@@ -57,8 +57,8 @@ function checklistapi_get_checklist_info() {
function checklistapi_help($path, $arg) {
$checklists = checklistapi_get_checklist_info();
foreach ($checklists as $checklist) {
if ($checklist['path'] == $path && !empty($checklist['help'])) {
return $checklist['help'];
if ($checklist['#path'] == $path && !empty($checklist['#help'])) {
return $checklist['#help'];
}
}
}
......@@ -69,21 +69,21 @@ function checklistapi_help($path, $arg) {
function checklistapi_menu() {
$items = array();
foreach (checklistapi_get_checklist_info() as $checklist_id => $checklist) {
if (!empty($checklist['path']) && !empty($checklist['title'])) {
$path = $checklist['path'];
if (!empty($checklist['#path']) && !empty($checklist['#title'])) {
$path = $checklist['#path'];
$items[$path] = array(
'title' => $checklist['title'],
'title' => $checklist['#title'],
'page callback' => 'drupal_get_form',
'page arguments' => array('checklistapi_form', $checklist_id),
'access callback' => 'checklistapi_checklist_access',
'access arguments' => array($checklist_id),
'file' => 'checklistapi.pages.inc',
);
if (!empty($checklist['description'])) {
$items[$path]['description'] = $checklist['description'];
if (!empty($checklist['#description'])) {
$items[$path]['#description'] = $checklist['#description'];
}
if (!empty($checklist['menu_name'])) {
$items[$path]['menu_name'] = $checklist['menu_name'];
if (!empty($checklist['#menu_name'])) {
$items[$path]['#menu_name'] = $checklist['#menu_name'];
}
}
}
......@@ -102,7 +102,7 @@ function checklistapi_permission() {
if (!empty($key)) {
$permission = 'edit ' . $key . ' checklistapi checklist';
// Only link to the checklist if the active user has access to it.
$checklist_name_replacement = user_access($permission) ? l($checklist['title'], $checklist['path']) : drupal_placeholder($checklist['title']);
$checklist_name_replacement = user_access($permission) ? l($checklist['#title'], $checklist['#path']) : drupal_placeholder($checklist['#title']);
$perms[$permission] = array(
'title' => t('Edit the !checklist checklist', array('!checklist' => $checklist_name_replacement)),
);
......@@ -123,22 +123,22 @@ function checklistapi_permission() {
function checklistapi_prepare_checklists(&$checklists) {
if (!empty($checklists)) {
// Sort checklists by weight.
uasort($checklists, 'drupal_sort_weight');
uasort($checklists, 'element_sort');
// Loop through checklists.
foreach ($checklists as $checklist_id => $checklist) {
if (!empty($checklist['groups']) && is_array($checklist['groups'])) {
// Sort groups by weight.
uasort($checklists[$checklist_id]['groups'], 'drupal_sort_weight');
uasort($checklists[$checklist_id]['groups'], 'element_sort');
// Loop through groups.
foreach ($checklist['groups'] as $group_id => $group) {
if (!empty($group['items']) && is_array($group['items'])) {
// Sort checklist items by weight.
uasort($checklists[$checklist_id]['groups'][$group_id]['items'], 'drupal_sort_weight');
uasort($checklists[$checklist_id]['groups'][$group_id]['items'], 'element_sort');
// Loop through checklist items.
foreach ($group['items'] as $item_id => $item) {
if (!empty($item['links']) && is_array($item['links'])) {
// Sort links by weight.
uasort($checklists[$checklist_id]['groups'][$group_id]['items'][$item_id]['links'], 'drupal_sort_weight');
uasort($checklists[$checklist_id]['groups'][$group_id]['items'][$item_id]['links'], 'element_sort');
}
}
}
......
......@@ -35,16 +35,20 @@ function checklistapi_form($form, &$form_state, $checklist_id) {
),
);
// Loop through groups.
foreach ($checklist['groups'] as $group_key => $group) {
$group_keys = element_children($checklist);
foreach ($group_keys as $group_key) {
$group = &$checklist[$group_key];
$form['checklistapi'][$group_key] = array(
'#type' => 'fieldset',
'#title' => filter_xss($group['title']),
'#title' => filter_xss($group['#title']),
);
if (isset($group['description'])) {
$form['checklistapi'][$group_key]['#description'] = filter_xss_admin($group['description']);
if (!empty($group['#description'])) {
$form['checklistapi'][$group_key]['#description'] = filter_xss_admin($group['#description']);
}
// Loop through items.
foreach ($group['items'] as $item_key => $item) {
$item_keys = element_children($group);
foreach ($item_keys as $item_key) {
$item = &$group[$item_key];
// Get saved state.
$saved_item = !empty($saved_values[$group_key][$item_key]) ? $saved_values[$group_key][$item_key] : 0;
// Set default value.
......@@ -59,41 +63,41 @@ function checklistapi_form($form, &$form_state, $checklist_id) {
$description = (isset($item['description'])) ? '<p>' . $item['description'] . '</p>' : '';
// Build links.
$links = array();
$link_keys = element_children($item);
foreach ($link_keys as $link_key) {
$link = &$item[$link_key];
$context = (!empty($link['#context'])) ? $link['#context'] : CHECKLISTAPI_LINK_CONTEXT_ANY;
$show_link = FALSE;
if ($context == CHECKLISTAPI_LINK_CONTEXT_ANY) {
$show_link = TRUE;
}
elseif ($saved_item && $context == CHECKLISTAPI_LINK_CONTEXT_ITEM_CHECKED) {
$show_link = TRUE;
}
elseif (!$saved_item && $context == CHECKLISTAPI_LINK_CONTEXT_ITEM_UNCHECKED) {
$show_link = TRUE;
}
if ($show_link) {
$options = (!empty($link['#options']) && is_array($link['#options'])) ? $link['#options'] : array();
$links[] = l($link['#text'], $link['#path'], $options);
}
}
if ($saved_item) {
// Prepend completion details.
$user = user_load($saved_item['uid']);
$links[] = t(
array_unshift($links, t(
'Completed @time by !user',
array(
'@time' => format_date($saved_item['completed'], 'short'),
'!user' => theme('username', array('account' => $user)),
)
);
}
if (!empty($item['links']) && is_array($item['links'])) {
foreach ($item['links'] as $link_key => $link) {
$context = (!empty($link['context'])) ? $link['context'] : CHECKLISTAPI_LINK_CONTEXT_ANY;
$show_link = FALSE;
if ($context == CHECKLISTAPI_LINK_CONTEXT_ANY) {
$show_link = TRUE;
}
elseif ($saved_item && $context == CHECKLISTAPI_LINK_CONTEXT_ITEM_CHECKED) {
$show_link = TRUE;
}
elseif (!$saved_item && $context == CHECKLISTAPI_LINK_CONTEXT_ITEM_UNCHECKED) {
$show_link = TRUE;
}
if ($show_link) {
$options = (!empty($link['options']) && is_array($link['options'])) ? $link['options'] : array();
$links[] = l($link['text'], $link['path'], $options);
}
}
));
}
$description .= '<div class="links">' . implode(' | ', $links) . '</div>';
// Build the list item.
$form['checklistapi'][$group_key][$item_key] = array(
'#type' => 'checkbox',
'#title' => filter_xss($item['title']),
'#title' => filter_xss($item['#title']),
'#description' => filter_xss_admin($description),
'#default_value' => $default_value,
);
......@@ -106,7 +110,7 @@ function checklistapi_form($form, &$form_state, $checklist_id) {
);
// Stash the checklist title for use in the submission handler.
$form['#checklist_title'] = check_plain($checklist['title']);
$form['#checklist_title'] = check_plain($checklist['#title']);
return $form;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment