You are here

webform_matrix_component.module in Webform Matrix Component 6

File

webform_matrix_component.module
View source
<?php

/**
 * @file
 * Provide matrix component for webform
 */
module_load_include('inc', 'webform_matrix_component', '/components/matrix');
module_load_include('inc', 'webform', '/includes/webform.components');

/**
 * 
 */
function webform_matrix_component_menu() {
  $items['webform_matrx_component/get-type-option'] = array(
    'page callback' => '_webform_matrix_component_get_type_option',
    'access callback' => TRUE,
    'file' => 'matrix.inc',
    'type' => MENU_CALLBACK,
    'file path' => drupal_get_path('module', 'webform_matrix_component') . '/components',
  );
  return $items;
}

/**
 * Define components to Webform.
 * @see webform.api.php
 * @see webform_components()
 */
function webform_matrix_component_webform_component_info() {
  $components = array();
  $components['matrix'] = array(
    'label' => t('Matrix'),
    'description' => t('Basic matrix type. Add One More Element in Row'),
    'features' => array(
      // This component supports defmatault values. Defaults to TRUE.
      'default_value' => FALSE,
      // This component supports a description field. Defaults to TRUE.
      'description' => TRUE,
      // This component supports a title attribute. Defaults to TRUE.
      'title' => TRUE,
      // This component has a title that can be toggled as displayed or not.
      'title_display' => TRUE,
      // This component has a title that can be displayed inline.
      'title_inline' => FALSE,
      // If this component can be used as a conditional SOURCE. All components
      // may always be displayed conditionally, regardless of this setting.
      // Defaults to TRUE.
      'conditional' => TRUE,
      // If this component allows other components to be grouped within it
      // (like a fieldset or tabs). Defaults to FALSE.
      'group' => FALSE,
      // Add content to CSV downloads. Defaults to TRUE.
      'csv' => TRUE,
    ),
    'file' => 'components/matrix.inc',
    'file path' => drupal_get_path('module', 'webform_matrix_component'),
  );
  return $components;
}

/**
 * Implements hook_form_formid_alter().
 */
function webform_matrix_component_form_webform_component_edit_form_alter(&$form, &$form_state) {
  if ($form['type']['#value'] == 'matrix') {
    $nid = arg(1);
    $node = node_load($nid);
    $component = $node->webform['components'][1];
    $matrix_form = _webform_matrix_component_get_column_form($form, $form_state, $component);
    $form = array_merge($form, $matrix_form);
    $form['actions']['submit']['#submit'][] = 'webform_component_edit_form_matrix_submit';
    $form['actions']['submit']['#validate'][] = 'webform_component_edit_form_matrix_validate';
    $form['#validate'][] = 'webform_component_edit_form_matrix_validate';
  }
}
function webform_component_edit_form_matrix_validate(&$form, &$form_state) {

  // If an AHAH submission, it's just the dependent dropdown working.
  if (!empty($form_state['ahah_submission'])) {
    $form['#validate'] = $form['actions']['submit']['#validate'] = array();
    return;
  }
}
function webform_component_edit_form_matrix_submit($form, &$form_state) {

  // If an AHAH submission, it's just the dependent dropdown working.
  if (!empty($form_state['ahah_submission'])) {
    return;
  }
}

/**
 * Implements hook_form_formid_alter().
 */
function webform_matrix_component_form_webform_admin_settings_alter(&$form, &$form_state, $formid) {

  // Admin settings for webform_matrix_component
  // Admin settings for webform_matrix_component
  // Can define rows/cols for matrix components
  // Default rows-10,cols-10.
  module_load_include('inc', 'webform', 'components/number');
  $form['matrix_fieldset'] = array(
    '#type' => 'fieldset',
    '#title' => t('Matrix Component Settings'),
    '#collapsible' => 1,
    '#collapsed' => 1,
  );
  $form['matrix_fieldset']['webform_matrix_component_webform_matrix_rows'] = array(
    '#type' => 'textfield',
    '#title' => t('Matrix Rows'),
    '#description' => t('Enter the max rows in matrix component'),
    '#default_value' => variable_get('webform_matrix_component_webform_matrix_rows', 10),
    '#element_validate' => array(
      '_webform_validate_number',
    ),
    '#integer' => TRUE,
    '#min' => 1,
    '#max' => 100,
    '#step' => 1,
  );
  $form['matrix_fieldset']['webform_matrix_component_webform_matrix_cols'] = array(
    '#type' => 'textfield',
    '#title' => t('Matrix Cols'),
    '#description' => t('Enter the max cols in matrix component'),
    '#default_value' => variable_get('webform_matrix_component_webform_matrix_cols', 10),
    '#element_validate' => array(
      '_webform_validate_number',
    ),
    '#integer' => TRUE,
    '#min' => 1,
    '#max' => 100,
    '#step' => 1,
  );
}