Commit d2b3e00f authored by Sven Lauer's avatar Sven Lauer
Browse files

Comment and indentation fixes.

parent 8efe8ca0
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -75,4 +75,3 @@ function commerce_bpc_pattern_settings_form($form, &$form_state, $type = NULL) {

  return commerce_bpc_settings_form($form, 'default', $type);
}
+42 −42
Original line number Diff line number Diff line
@@ -15,9 +15,10 @@
 * a product type is fit for bulk product creation (it needs to have
 * at least one combination-creating instance).
 *
 * @param $instance
 * @param array $instance
 *   Array holding instance information.
 * @return
 *
 * @return bool
 *   TRUE if the implementing module manages combination creation
 *   through the instance.
 */
@@ -58,15 +59,14 @@ function hook_commerce_bpc_is_combination_field($instance) {
 * calls). Thus in recording which fields have been altered in form_state, the
 * implementation should make sure it does not record things twice.
 *
 * @param $form
 * @param array $form
 *   Nested array of form elements that comprise the bulk creation form.
 * @param $form_state
 * @param array $form_state
 *   A keyed array containing the current state of the form.
 * @param $path
 * @param array $path
 *   An array of keys specifying where in the form the current element
 *   is to be found. This should be reset if the element is moved.
 *
 *
 * @see hook_commerce_bpc_MODULE_NAME_form_element_alter()
 * @see hook_commerce_bpc_FIELD_TYPE_form_element_alter()
 */
@@ -79,10 +79,10 @@ function hook_commerce_bpc_form_element_alter(&$form, &$form_state, &$path) {
  if (commerce_bpc_commerce_bpc_is_combination_field($instance)) {
    $element[$lang]['#type'] = 'checkboxes';

    // Get rid of 'none' option---user can just not pick any
    // Get rid of 'none' option---user can just not pick any.
    unset($element[$lang]['#options']['_none']);

    // Move to comibinations-fieldset
    // Move to comibinations-fieldset.
    $form['combinations'][$field_name] = $element;
    drupal_array_set_nested_value($form, $path, NULL);

@@ -92,7 +92,7 @@ function hook_commerce_bpc_form_element_alter(&$form, &$form_state, &$path) {

    if (empty($form_state['commerce_bpc']['list']['combination_fields'])
    || !in_array($field_name, $form_state['commerce_bpc']['list']['combination_fields'])) {
    // record what we have done. As this hook may be run multiple times
      // Record what we have done. As this hook may be run multiple times
      // due to form rebuilds, we need to make sure that we record each field
      // only once.
      $form_state['commerce_bpc']['list']['combination_fields'][] = $field_name;
@@ -110,15 +110,14 @@ function hook_commerce_bpc_form_element_alter(&$form, &$form_state, &$path) {
 * using long switch statements to alter form elements of multiple field
 * types.
 *
 * @param $form
 * @param array $form
 *   Nested array of form elements that comprise the bulk creation form.
 * @param $form_state
 * @param array $form_state
 *   A keyed array containing the current state of the form.
 * @param $path
 * @param array $path
 *   An array of keys specifying where in the form the current element
 *   is to be found. This should be reset if the element is moved.
 *
 *
 * @see hook_commerce_bpc_form_element_alter()
 * @see hook_commerce_bpc_MODULE_NAME_form_element_alter()
 */
@@ -134,20 +133,20 @@ function hook_commerce_bpc_FIELD_TYPE_form_element_alter(&$form, &$form_state, &
  if (commerce_bpc_commerce_bpc_is_combination_field($instance)) {
    $element[$lang]['#type'] = 'checkboxes';

    // Get rid of 'none' option---user can just not pick any
    // Get rid of 'none' option---user can just not pick any.
    unset($element[$lang]['#options']['_none']);

    // Move to comibinations-fieldset
    $form['combinations'][$field_name] = $element;
    drupal_array_set_nested_value($form, $path, NULL);

    // change path to allow subsequent hooks operate on the form element.
    // Change path to allow subsequent hooks operate on the form element.
    $path = array('combinations', $field_name);


    if (empty($form_state['commerce_bpc']['list']['combination_fields'])
    || !in_array($field_name, $form_state['commerce_bpc']['list']['combination_fields'])) {
    // record what we have done. As this hook may be run multiple times
      // Record what we have done. As this hook may be run multiple times
      // due to form rebuilds, we need to make sure that we record each field
      // only once.
      $form_state['commerce_bpc']['list']['combination_fields'][] = $field_name;
@@ -156,7 +155,7 @@ function hook_commerce_bpc_FIELD_TYPE_form_element_alter(&$form, &$form_state, &
}

/**
 * Perform alterations on the field form element of field types defined by a particular module.
 * Perform alterations on the field form elements provide by a field module.
 *
 * Modules can implement hook_commerce_bpc_MODULE_NAME_form_element_alter()
 * to act only on the form elements provided by field types defined by a
@@ -171,18 +170,18 @@ function hook_commerce_bpc_FIELD_TYPE_form_element_alter(&$form, &$form_state, &
 * which would require multiple identical implementations of
 * hook_commerce_bpc_FIELD_TYPE_form_element_alter().
 *
 * @param $form
 * @param array $form
 *   Nested array of form elements that comprise the bulk creation form.
 * @param $form_state
 * @param array $form_state
 *   A keyed array containing the current state of the form.
 * @param $path
 * @param array $path
 *   An array of keys specifying where in the form the current element
 *   is to be found. This should be reset if the element is moved.
 *
 * @see hook_commerce_bpc_form_element_alter()
 * @see hook_commerce_bpc_FIELD_TYPE_form_element_alter()
 */
function hook_commerce_bpc_MODULE_NAME_form_element_alter(&$form, &$form_state, $key) {
function hook_commerce_bpc_MODULE_NAME_form_element_alter(&$form, &$form_state, $path) {
  // Modification for form elements related to field types defined by a
  // specific module go here. For example, MODULE_NAME is "list" this code will
  // run only on fields of type "list_text", "list_integer", "list_float" and
@@ -195,10 +194,10 @@ function hook_commerce_bpc_MODULE_NAME_form_element_alter(&$form, &$form_state,
  if (commerce_bpc_commerce_bpc_is_combination_field($instance)) {
    $element[$lang]['#type'] = 'checkboxes';

    // Get rid of 'none' option---user can just not pick any
    // Get rid of 'none' option---user can just not pick any.
    unset($element[$lang]['#options']['_none']);

    // Move to comibinations-fieldset
    // Move to comibinations-fieldset.
    $form['combinations'][$field_name] = $element;
    drupal_array_set_nested_value($form, $path, NULL);

@@ -208,7 +207,7 @@ function hook_commerce_bpc_MODULE_NAME_form_element_alter(&$form, &$form_state,

    if (empty($form_state['commerce_bpc']['list']['combination_fields'])
    || !in_array($field_name, $form_state['commerce_bpc']['list']['combination_fields'])) {
    // record what we have done. As this hook may be run multiple times
      // Record what we have done. As this hook may be run multiple times
      // due to form rebuilds, we need to make sure that we record each field
      // only once.
      $form_state['commerce_bpc']['list']['combination_fields'][] = $field_name;
@@ -227,12 +226,12 @@ function hook_commerce_bpc_MODULE_NAME_form_element_alter(&$form, &$form_state,
 * This hook is invoked on form validation and submission to figure
 * out for which combinations of values products should be created.
 *
 * @param $form
 * @param array $form
 *   The Form API representation of the form.
 * @param $form_state
 * @param array $form_state
 *   An array holding the current state of the form, in particular the
 *   submitted values.
 * @param $combinations
 * @param array $combinations
 *   An array holding the combinations that have been created so far. Each
 *   combination is an array keyed by field names with full field api value
 *   arrays as values (i.e. a nested array that accomodates languages and
@@ -264,7 +263,7 @@ function hook_commerce_bpc_get_combinations($form, &$form_state, &$combinations)
        }
        else {
          $new_combinations[] = $combination;
          // if the values for a field are empty, we make sure that
          // If the values for a field are empty, we make sure that
          // we (re)-add the original combination only once.
          break;
        }
@@ -287,16 +286,16 @@ function hook_commerce_bpc_get_combinations($form, &$form_state, &$combinations)
 * for inclusion in SKUs, while the -label token should be a human readable
 * value.
 *
 * @param $product_type
 * @param array $product_type
 *   The product type to provide tokens for.
 * @param $combination
 * @param array $combination
 *   An array with field names as keys and their respective
 *   values as values.
 * @param $options
 * @param array $options
 *   Options array passed unmodified from hook_tokens(). Make sure
 *   you honor the 'sanitize' property.
 *
 * @return
 * @return array
 *   An array with two keys 'values' and 'labels', each of which should
 *   have an array keyed by field names with replacements as values.
 *
@@ -332,10 +331,11 @@ function hook_commerce_bpc_tokens($product_type, $combination, $options) {
 * These example values are used, for example, to provide live previews
 * the SKU and title of the products to be generated.
 *
 * @param $instance
 * @param array $instance
 *   An array holding the instance info for which example values should be
 *   returned.
 * @return
 *
 * @return array
 *   An array with two keys 'label' and 'value', holding an example value
 *   for each.
 *
+7 −11
Original line number Diff line number Diff line
@@ -18,11 +18,11 @@ function commerce_bpc_create_bulk_form($form, &$form_state, $product_type) {

  $form['#parents'] = array();

  // Create a temporary product object attach fields
  // Create a temporary product object attach fields.
  $new_product = commerce_product_new($product_type);
  $language = !empty($new_product->language) ? $new_product->language : LANGUAGE_NONE;

  // Store the product type for later use
  // Store the product type for later use.
  $form['product_type'] = array(
    '#type' => 'value',
    '#value' => $product_type,
@@ -56,7 +56,6 @@ function commerce_bpc_create_bulk_form($form, &$form_state, $product_type) {
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
    '#tree' => TRUE,
    // needed for
    '#parents' => array('static_values'),
  );

@@ -78,7 +77,6 @@ function commerce_bpc_create_bulk_form($form, &$form_state, $product_type) {
    '#description' => t("The part of the product title that is common to all products to be generated. The SKU of each individual product will be composed of this value together with values of the selected options."),
    '#size' => 60,
    '#maxlength' => 255,
//    '#weight' => 10,
    '#process' => array('commerce_bpc_process_fragment_field'),
  );

@@ -115,7 +113,8 @@ function commerce_bpc_create_bulk_form($form, &$form_state, $product_type) {
 * @see commerce_bpc_create_bulk_form_submit()
 */
function commerce_bpc_create_bulk_form_validate($form, &$form_state) {
  // Check to make sure all of the SKUs to be generated are unique and not taken yet
  // Check to make sure all of the SKUs to be generated are unique and not taken
  // yet.
  $skus = array();
  $data = array();
  $product_type = $form_state['values']['product_type'];
@@ -195,15 +194,12 @@ function commerce_bpc_create_bulk_form_submit($form, &$form_state) {
    $function($product_ids, $form_state);
  }


  $destinations = module_invoke_all('commerce_bpc_destinations', $form_state, $product_ids);
  drupal_alter('commerce_bpc_destinations', $destinations, $form_state, $product_ids);
  $_REQUEST['destinations'] = $destinations;
  $form_state['redirect'] = commerce_bpc_next_destination();
}



/**
 * Process the fields attached to the bulk creation form.
 *
@@ -221,7 +217,7 @@ function commerce_bpc_process_field_form_elements(&$form, &$form_state) {
    $field_name = $element[$element['#language']]['#field_name'];
    $info = field_info_field($field_name);
    $instance_info = field_info_instance('commerce_product', $field_name, $product_type);
    // Filter out fields that are set to be hidden
    // Filter out fields that are set to be hidden.
    if (!_commerce_bpc_get_value($instance_info, array('commerce_bpc', 'show_field'), TRUE)) {
      unset($form['static_values'][$field_key]);
    }
+9 −9
Original line number Diff line number Diff line
@@ -31,11 +31,11 @@ function commerce_bpc_commerce_bpc_list_form_element_alter(&$form, &$form_state,
        $element[$lang]['#type'] = 'checkboxes';
        break;
      case 'options_buttons':
        // Make sure checkboxes are being used
        // Make sure checkboxes are being used.
        $element[$lang]['#type'] = 'checkboxes';
    }
    $element[$lang]['#multiple'] = TRUE;
    // Unset -none- option if present
    // Unset -none- option if present.
    unset($element[$lang]['#options']['_none']);
    // No pre-seleciton.
    $element[$lang]['#default_value'] = array();
@@ -44,12 +44,12 @@ function commerce_bpc_commerce_bpc_list_form_element_alter(&$form, &$form_state,
    $form['combinations'][$field_name] = $element;
    drupal_array_set_nested_value($form, $path, NULL);

    // change path to allow subsequent hooks operate on the form element.
    // Change path to allow subsequent hooks operate on the form element.
    $path = array('combinations', $field_name);

    if (empty($form_state['commerce_bpc']['list']['combination_fields'])
    || !in_array($field_name, $form_state['commerce_bpc']['list']['combination_fields'])) {
    // record what we have done. As this hook may be run multiple times
      // Record what we have done. As this hook may be run multiple times
      // due to form rebuilds, we need to make sure that we record each field
      // only once.
      $form_state['commerce_bpc']['list']['combination_fields'][] = $field_name;
@@ -78,7 +78,7 @@ function commerce_bpc_commerce_bpc_get_combinations($form, &$form_state, &$combi
          }
          else {
            $new_combinations[] = $combination;
            // if the values for a field are empty, we make sure that
            // If the values for a field are empty, we make sure that
            // we (re)-add the original combination only once.
            break;
          }
@@ -101,7 +101,7 @@ function commerce_bpc_commerce_bpc_tokens($product_type, $combination, $options)
    $field = field_info_field($field_name);
    $instance = field_info_instance('commerce_product', $field_name, $product_type);
    if ($field['module'] == 'list' &&  !_commerce_bpc_get_value($instance, array('commerce_bpc', 'is_static'), FALSE)) {
      // TODO: Treat languages properly
      // TODO: Treat languages properly.
      $items = reset($values);
      // We only allow a single value per combination, so we can treat
      // this like a single value field.
+2 −2
Original line number Diff line number Diff line
@@ -8,7 +8,7 @@
 * Implements hook_uninstall().
 */
function commerce_bpc_uninstall() {
  // Clean up variables
  // Clean up variables.
  module_load_include('inc', 'commerce_bpc', 'commerce_bpc.settings');
  $settings = commerce_bpc_setting_defaults();
  $product_types = array_keys(commerce_product_types());
Loading