You are here

webform_matrix_component.module in Webform Matrix Component 7

File

webform_matrix_component.module
View source
<?php

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

/**
 * 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' => TRUE,
      // 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, $formid) {
  if ($form['type']['#value'] == 'matrix') {
    $component = $form_state['build_info']['args'][1];
    $matrix_form = webform_matrix_get_column_form($form, $form_state, $component);
    $form = array_merge($form, $matrix_form);
  }
}

/**
 * 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,
  );
  $form['matrix_fieldset']['webform_matrix_component_textfield_validation'] = array(
    '#type' => 'textarea',
    '#title' => t('Textfield Validation'),
    '#description' => t('You can extend textfield validation.Seperate By new line.
          create new function webform_render_matrix_textfield_% in your module file. pass element & form_state as arguments. Otherwise you will get error call to undefines function.'),
    '#default_value' => variable_get('webform_matrix_component_textfield_validation', 'Numeric'),
  );
}

Functions

Namesort descending Description
webform_matrix_component_form_webform_admin_settings_alter Implements hook_form_formid_alter().
webform_matrix_component_form_webform_component_edit_form_alter Implements hook_form_formid_alter().
webform_matrix_component_webform_component_info Define components to Webform.