You are here

webform_bt_layout.module in Webform Bootstrap 3 Layout 7.3

File

webform_bt_layout.module
View source
<?php

/**
 * This module provides a layout container for webforms.
 */

/**
 * Implements hook_help().
 */
function webform_bt_layout_help($section = 'admin/help#webform_bt_layout', $arg = NULL) {
  switch ($section) {
    case 'admin/help#webform_bt_layout':

      // Return a line-break version of the module README.txt
      return nl2br(file_get_contents(drupal_get_path('module', 'webform_bt_layout') . '/README.txt'));
  }
  return '';
}

/**
 * Implements hook_webform_component_info().
 */
function webform_bt_layout_webform_component_info() {
  return array(
    'bt_layout_row' => array(
      'label' => t('Bootstrap layout row'),
      'description' => t('Create bootstrap row.'),
      'features' => array(
        'csv' => FALSE,
        'required' => FALSE,
        'conditional' => FALSE,
        'group' => TRUE,
        'title_display' => FALSE,
        'title_inline' => FALSE,
        'description' => FALSE,
        'wrapper_classes' => FALSE,
      ),
      'file' => 'bt_layout_row.inc',
    ),
    'bt_layout_cols' => array(
      'label' => t('Bootstrap layout cols'),
      'description' => t('Allows you to arrange fields into columns.'),
      'features' => array(
        'csv' => FALSE,
        'required' => FALSE,
        'conditional' => FALSE,
        'group' => TRUE,
        'title_display' => FALSE,
        'title_inline' => FALSE,
        'description' => FALSE,
        'wrapper_classes' => FALSE,
      ),
      'file' => 'bt_layout_cols.inc',
    ),
  );
}

/**
 * Implements hook_form_alter().
 * @param array $form
 * @param array $form_state
 * @param string $form_id
 */
function webform_bt_layout_form_alter(&$form, &$form_state, $form_id) {
  if ($form_id == 'webform_components_form') {
    $form['add']['add']['#submit'][] = 'webform_bt_layout_form_add_submit';
  }
}

/**
 * Implements hook_webform_component_presave().
 * @param array $component
 */
function webform_bt_layout_webform_component_presave(&$component) {
  if ($component['type'] === 'bt_layout_cols' || $component['type'] === 'bt_layout_row') {
    $component['name'] = $component['form_key'];
  }
}

/**
 * Immediately add a new layout cols to the webform instead of being redirected to the component form
 * @param array $form
 * @param array $form_state
 */
function webform_bt_layout_form_add_submit($form, &$form_state) {
  $component = $form_state['values']['add'];
  if ($component['type'] === 'bt_layout_cols' || $component['type'] === 'bt_layout_row') {
    $nid = $component['nid'] = $form_state['values']['nid'];
    $component['form_key'] = _webform_safe_name($component['name']);
    unset($component['required'], $component['cid'], $component['add']);
    webform_component_defaults($component);
    $cid = webform_component_insert($component);
    $form_state['redirect'] = array(
      "node/{$nid}/webform/components/{$cid}",
    );
  }
}

Functions

Namesort descending Description
webform_bt_layout_form_add_submit Immediately add a new layout cols to the webform instead of being redirected to the component form
webform_bt_layout_form_alter Implements hook_form_alter().
webform_bt_layout_help Implements hook_help().
webform_bt_layout_webform_component_info Implements hook_webform_component_info().
webform_bt_layout_webform_component_presave Implements hook_webform_component_presave().