Check my latest blog
Improving the Drupal CMS User Experience
Basically it's my notes from Drupal Camp London on the Seminar of the same name.
/** * @file Orders Taxonomy * * @param $tid - expecting a tid * @param $no_results - the number of results that you'd like to return * @param $order - which tid first - child or most senior parent ? * * @return returns a string . */ function rcn_taxonomy_order($tid, $no_results = 1, $order = 'first') { $wrapper = entity_metadata_wrapper('taxonomy_term', $tid); $all_parents = $wrapper->parents_all->value(); ($order == 'last') ? $all_parents = array_reverse($all_parents) : $all_parents; $stitch_term_array = ''; foreach ($all_parents as $key => $term) { ($key < $no_results) ? $stitch_term_array .= $term->name . ", " : ''; } return rtrim($stitch_term_array, ', '); }
// @todo temporary debugging code to look for an error // check to see if this is an arry if (!is_array($registry[$hook]['preprocess functions'])){ watchdog('!array preprocess func', $hook); } if (!isset($registry[$hook]['preprocess functions'])){ watchdog('!isset preprocess func', $hook); } // @todo end debugging
/** * @file * Custom forms. */ /** * Form builder. * * @param array $form * An associative array containing the structure of the form. * @param array $form_state * An array which stores information about the form. * * @return array * Completed form array.
$quiz_result = quiz_result_load($quiz_result_id); if (!$quiz_result) { return array('error' => array('#markup' => 'Could not find quiz result.')); } $form['quiz_result'] = array( '#type' => 'value', '#value' => $quiz_result, ); try { $w_quiz = entity_metadata_wrapper('node', $quiz); $quiz_title = $w_quiz->label(); } catch (EntityMetadataWrapperException $e) { watchdog_exception(‘my_custom', $e); $quiz_title = ''; } $message = t("Are you sure that you want to delete your answers for %quiz_title?", array("%quiz_title" => $quiz_title)); try { $w_quiz_result = entity_metadata_wrapper('quiz_result', $quiz_result); $redirect = "portfolio/portfolio/{$w_quiz_result->field_custom_field->raw()}"; }
$redirect = 'eportfolio'; } $form['submit_redirect'] = array( '#type' => 'value', '#value' => $redirect, ); $caption = t("This action cannot be undone."); return confirm_form($form, $message, $redirect, $caption, t('Delete')); } /** * Form submit handler. * * @param array $form * An associative array containing the structure of the form. * @param array $form_state * An array which stores information about the form. */ function my_custom_delete_form_submit($form, &$form_state) { quiz_delete_results(array($form_state['values']['quiz_result']->result_id)); $form_state['redirect'] = $form_state['values']['submit_redirect'];
/** * @file * Modal form wrappers for SAQs. */ /** * CTools modal form wrapper function. * * @param object $quiz * The quiz node the results belong to. * @param int $quiz_result_id * The rid of the quiz result we're deleting. * @param bool $js * Whether javascript is enabled. * @param bool $refresh * Whether to refresh the base page on form submission. */ function my_modal_custom_delete_form_modal_callback($quiz, $quiz_result_id, $js = FALSE, $refresh = TRUE) { if (!$js) { if ($quiz_result = quiz_result_load($quiz_result_id)) { $portfolio_id = rcni_modal_get_parent_portfolio_id($quiz_result); $options = $portfolio_id ? array('query' => array('destination' => "portfolio/portfolio/{$portfolio_id}")) : array(); drupal_goto("node/{$quiz->nid}/quiz-results/{$quiz_result_id}/delete", $options); } else { drupal_goto("eportfolio"); } } else { $form_state = array( 'ajax' => TRUE, 'build_info' => array( 'args' => array( $quiz->nid, $quiz_result_id, ), ), 'rcni_modal' => TRUE, );
form_load_include($form_state, 'inc', ‘my_custom', 'includes/form'); my_modal_custom_form_modal_callback($form_id, $form_state, $refresh); } }
/** * Implements hook_menu(). */ function my_modal_menu() { $items = array(); $items['node/%quiz_menu/quiz-results/%quiz_rid/delete'] = array( 'title' => 'Delete answers', 'page callback' => 'drupal_get_form', 'page arguments' => array('rcni_saqs_delete_form', 1, 3), 'access callback' => 'rcni_saqs_quiz_result_delete_access', 'access arguments' => array(3), 'file' => 'includes/form.inc', ); return $items; }
/** * Access callback for deleting a quiz. * * @return bool * True if user can delete quiz result. */ function rcni_saqs_quiz_result_delete_access($result_id) { if (user_access('delete any quiz results')) { return TRUE; } global $user; $quiz_result = quiz_result_load($result_id); if (!$quiz_result) { return FALSE; } return user_access('delete results for own quiz') && $user->uid == $quiz_result->uid; }