Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * @file
- * Custom functionality for NCAC site.
- */
- /**
- * Implementation of hook_init().
- */
- function ncac_init() {
- // Add dialog specific js. Used for 'Book now' dialog.
- dialog_add_js();
- }
- /**
- * Implementation of hook_menu().
- *
- * @return array of menu items
- */
- function ncac_menu() {
- $items = array();
- $items['book/%node/%ctools_js'] = array(
- 'title' => 'Book this activity',
- 'page callback' => 'ncac_dialog_node_view',
- 'page arguments' => array(1, 2),
- 'access arguments' => array('access content'),
- 'type' => MENU_CALLBACK,
- );
- return $items;
- }
- /**
- * Implementation of hook_nodeapi().
- */
- function ncac_nodeapi(&$node, $op) {
- // Remove add_to_cart and display_price portions of the node display when in dialog mode
- if (($op == 'view') && (isset($node->build_mode)) && ($node->build_mode === 'dialog')) {
- unset($node->content['add_to_cart']);
- unset($node->content['display_price']);
- }
- }
- /**
- * Implementation of hook_content_build_modes().
- *
- * @return
- * An array describing the build modes used by the module.
- * They are grouped by secondary tabs on CCK's 'Display fields' screens.
- */
- function ncac_content_build_modes() {
- $modes = array();
- $modes['dialog'] = array(
- 'title' => t('Dialog'),
- 'build modes' => array(
- 'dialog' => array(
- 'title' => t('Dialog'),
- 'views style' => FALSE,
- ),
- ),
- );
- return $modes;
- }
- /**
- * Implementation of hook_form_alter().
- */
- function ncac_form_alter(&$form, $form_state, $form_id) {
- // Only do this for node forms
- if (isset($form['#id']) && ($form['#id'] == 'node-form') && arg(0) == 'node') {
- $node = $form['#node'];
- // If a path has already been set for this node, don't automatically tick
- // the 'Automatic alias' box. Keeps existing aliases from being changed.
- if (drupal_strlen($node->path) > 0) {
- $node->pathauto_perform_alias = FALSE;
- }
- }
- // Add item's date validation to add to cart and buy it now forms
- $forms = array('uc_product_add_to_cart_form', 'uc_catalog_buy_it_now_form');
- foreach ($forms as $id) {
- if (drupal_substr($form_id, 0, drupal_strlen($id)) == $id) {
- $form['#validate'][] = 'ncac_validate_form_addtocart';
- }
- }
- // Add validation to cart view
- if ($form_id == 'uc_cart_view_form') {
- $form['#validate'][] = 'ncac_validate_form_cart';
- }
- // Add validation to checkout and checkout review forms
- if ($form_id == 'uc_cart_checkout_form' || $form_id == 'uc_cart_checkout_review_form') {
- $form['#validate'][] = 'ncac_validate_form_checkout';
- // Collapse and slim down the uc_discounts field. It's HUGE by default!
- $form['panes']['uc_discounts']['#collapsed'] = TRUE;
- $form['panes']['uc_discounts']['uc-discounts-codes']['#rows'] = 1;
- $form['panes']['uc_discounts']['uc-discounts-codes']['#cols'] = 20;
- }
- // Rename submit button on request node add form
- if ($form_id == 'request_node_form') {
- $form['buttons']['submit']['#value'] = 'Submit request';
- }
- }
- /**
- * AJAX aware view of activity registration node. Uses ctools and dialog
- *
- * @param $node
- * Node to be rendered
- * @param $ajax
- * Is this an AJAX request?
- */
- function ncac_dialog_node_view($node, $ajax = FALSE) {
- // Is this an AJAX request? If not just render the standard page view
- if (!$ajax) {
- return node_page_view($node);
- }
- // Set the build_mode so we know to get rid of the default uc_product
- // add_to_cart form using hook_nodeapi()
- $node->build_mode = 'dialog';
- ctools_include('ajax');
- // Start building the form that will work in the dialog
- $form_state = array(
- 'ajax' => TRUE,
- 'title' => $node->title,
- 'args' => array($node),
- );
- $form_id = 'uc_product_add_to_cart_form_' . $node->nid;
- ctools_include('form');
- // This won't override settings already in.
- $form_state += array(
- 're_render' => FALSE,
- 'no_redirect' => !empty($form_state['ajax']),
- );
- $output = ctools_build_form($form_id, $form_state);
- if (!empty($form_state['ajax']) && empty($form_state['executed'])) {
- $title = empty($form_state['title']) ? '' : $form_state['title'];
- // If there are messages for the form, render them. Includes min qty/date
- // errors.
- if ($messages = theme('status_messages')) {
- $output = $messages . $output;
- }
- // Render the node view and add it to the output
- $node_view = node_view($node, FALSE, TRUE);
- $output = $output . $node_view;
- $commands = array();
- if (isset($form_state['js settings'])) {
- $commands[] = ctools_ajax_command_settings($form_state['js settings']);
- }
- // Add dialog display of the node to the ctools ajax renderer stack
- $commands[] = dialog_command_display($title, $output);
- $output = $commands;
- }
- if (empty($output)) {
- // On form submission display a message in the dialog, then redirect to the cart
- $output[] = dialog_command_display(t('Book this activity'), t('Activity added to your cart...'));
- $output[] = ctools_ajax_command_redirect('cart');
- }
- // Use ctools to make the ajax magic happen
- ctools_ajax_render($output);
- }
Add Comment
Please, Sign In to add comment