diff --git a/commerce_registration.tokens.inc b/commerce_registration.tokens.inc index 446de30..fc9fc6c 100644 --- a/commerce_registration.tokens.inc +++ b/commerce_registration.tokens.inc @@ -1,15 +1,31 @@ t('Commerce Registration'), + 'description' => t('Tokens related to commerce registrations.'), + ); + + $info['tokens']['commerce-registration']['registration-index'] = array( + 'name' => t('Registration Index'), + 'description' => t('The numerical index of the registration for a product.'), + ); + + return $info; +} + +/** * Implements hook_token_info_alter(). - * - * @param $data */ function commerce_registration_token_info_alter(&$data) { + // Add token for Commerce Order to Registrations. $data['tokens']['registration']['commerce_order'] = array( 'name' => t('Commerce Order ID'), 'description' => t('The Commerce order number that the registration belongs to.'), @@ -18,27 +34,33 @@ function commerce_registration_token_info_alter(&$data) { /** * Implements hook_tokens(). - * - * @param $type - * @param $tokens - * @param array $data - * @param array $options - * @return array */ function commerce_registration_tokens($type, $tokens, array $data = array(), array $options = array()) { - $items = array(); - if (!isset($data['registration'])) { - return array(); - } - $reg = $data['registration']; - if ($type == 'registration') { - foreach ($tokens as $key => $token) { - switch ($key) { + $replacements = array(); + + if ($type == 'registration' && !empty($data['registration'])) { + $reg = $data['registration']; + + foreach ($tokens as $name => $original) { + switch ($name) { case "commerce_order": - $items[$token] = $reg->order_id; + $replacements[$original] = $reg->order_id; break; } } } - return $items; + + if ($type == 'commerce-registration' && !empty($data['commerce-registration'])) { + $commerce_registration = $data['commerce-registration']; + + foreach ($tokens as $name => $original) { + switch ($name) { + case 'registration-index': + $replacements[$original] = $commerce_registration['index']; + break; + } + } + } + + return $replacements; } diff --git a/includes/commerce_registration.checkout_pane.inc b/includes/commerce_registration.checkout_pane.inc index 266ad0b..f17e9ce 100755 --- a/includes/commerce_registration.checkout_pane.inc +++ b/includes/commerce_registration.checkout_pane.inc @@ -36,21 +36,39 @@ function commerce_registration_information_checkout_form($form, &$form_state, $c // We add a single registration for the quantity of the product being // purchased/registered for. $label = $i + 1; + $tokens_data = array('index' => $label); $title_vars = array( '@product' => $product->title->value(), '@count' => $label, ); $title = t('@product - Registrant #@count', $title_vars); + // Replace tokens in the title and help text. if (!empty($override_title)) { + // Support for legacy tokens: '[title]' and '[index]'. $title = str_replace('[title]', $product->title->value(), $override_title); $title = str_replace('[index]', $label, $title); + if (module_exists('token')) { + $title = token_replace($title, array( + 'commerce-line-item' => $line_item_wrapper->value(), + 'commerce-order' => $order_wrapper->value(), + 'commerce-registration' => $tokens_data, + )); + } + } + $help_text = variable_get('commerce_registration_registrant_help', NULL); + if (!empty($help_text) && module_exists('token')) { + $help_text = token_replace($help_text, array( + 'commerce-line-item' => $line_item_wrapper->value(), + 'commerce-order' => $order_wrapper->value(), + 'commerce-registration' => $tokens_data, + )); } $pane_form[$prodkey][$prodkey . '-reg-' . $i] = array( '#type' => 'fieldset', '#title' => $title, '#collapsible' => TRUE, '#tree' => TRUE, - '#description' => variable_get('commerce_registration_registrant_help', ''), + '#description' => $help_text, ); $entity = NULL; $bundle = registration_get_entity_registration_type('commerce_product', @@ -381,18 +399,29 @@ function commerce_registration_information_settings_form($checkout_pane) { $form['commerce_registration_product_title'] = array( '#type' => 'textfield', '#title' => t('Product Registration Title'), - '#description' => t('The text to populate the fieldset label for a registrant\'s information.') . '
' - . t('Available tokens are [title] for the product title, and [index] for a countable index value.'), + '#description' => t('The text to populate the fieldset label for a registrant\'s information. Tokens are supported if the module is enabled.'), '#default_value' => variable_get('commerce_registration_product_title', ''), + '#maxlength' => 1024, ); $form['commerce_registration_registrant_help'] = array( '#type' => 'textarea', '#title' => t('Product Registration Fieldset Help Text'), - '#description' => t('The help text to display to the user entering registration information.'), + '#description' => t('The help text to display to the user entering registration information. Tokens are supported if the module is enabled.'), '#default_value' => variable_get('commerce_registration_registrant_help', ''), ); + if (module_exists('token')) { + $form['commerce_registration_token_tree'] = array( + '#theme' => 'token_tree', + '#token_types' => array( + 'commerce-line-item', + 'commerce-order', + 'commerce-registration', + ), + ); + } + $form['commerce_registration_hide_email_logged_in'] = array( '#type' => 'checkbox', '#title' => t('Hide the Email field for logged in users'),