You are here

flexiform_multistep.module in Flexiform 7

Module file for creating CTools multi-step forms with Flexiform.

File

flexiform_multistep/flexiform_multistep.module
View source
<?php

/**
 * @file
 * Module file for creating CTools multi-step forms with Flexiform.
 */

/**
 * Implements hook_form_alter() on behalf of inline entity form for multistep.
 *
 * In a ctools wizard the 'next' button is in a different location in the form
 * array and inline entity form does not cater for this.
 *
 * @see inline_entity_form_form_alter
 */
function flexiform_multistep_form_alter(&$form, &$form_state, $form_id) {
  if (!empty($form_state['flexiform_multistep']) && !empty($form_state['inline_entity_form'])) {
    $submit_element = NULL;
    if (!empty($form['buttons']['next'])) {
      $submit_element =& $form['buttons']['next'];
    }
    if ($submit_element) {
      $submit = array_merge(array(
        'inline_entity_form_trigger_submit',
      ), $form['#submit']);
      if (!empty($submit_element['#submit'])) {
        $submit = array_merge($submit, $submit_element['#submit']);

        // $form['#submit'] and $submit_element['#submit'] might have matching
        // callbacks, resulting in duplicates and double processing.
        $submit_element['#submit'] = array_unique($submit);
      }
      else {
        $submit_element['#submit'] = $submit;
      }
      $submit_element['#ief_submit_all'] = TRUE;
    }
  }
}

/**
 * Implements hook_form_FORM_ID_alter() for flexiform_manage_form_fields_form().
 */
function flexiform_multistep_form_flexiform_manage_form_fields_form_alter(&$form, &$form_state, $form_id) {
  form_load_include($form_state, 'inc', 'flexiform_multistep', 'flexiform_multistep.admin');
  _flexiform_multistep_form_flexiform_manage_form_fields_form_alter($form, $form_state, $form_id);
}

/**
 * Implements hook_field_group_format_settings().
 */
function flexiform_multistep_field_group_format_settings($group) {
  if ($group->entity_type == 'flexiform' && $group->format_type == 'flexiform_step') {
    module_load_include('inc', 'flexiform_multistep', 'flexiform_multistep.admin');
    return _flexiform_multistep_field_group_format_settings($group);
  }
}

/**
 *  Implements hook_field_group_formatter_info().
 */
function flexiform_multistep_field_group_formatter_info() {
  return array(
    'form' => array(
      'flexiform_step' => array(
        'label' => t('Flexiform Page'),
        'description' => t('A server side page in a Flexiform. Note: Only compatible with Flexiforms.'),
        'instance_settings' => array(
          'save_entities' => NULL,
          'save_entities_custom' => NULL,
        ),
      ),
    ),
  );
}

/**
 *  Implements hook_flexiform_wrapper_alter().
 */
function flexiform_multistep_flexiform_wrapper_alter(&$wrapper, FlexiformDisplayInterface $display, &$context) {
  $flexiform = $display
    ->getFlexiform();
  $settings = isset($flexiform->settings['flexiform_multistep']) ? $flexiform->settings['flexiform_multistep'] : array();
  $context += array(
    'args' => array(),
  );
  array_unshift($context['args'], !empty($context['js']));
  if (!empty($settings['enabled'])) {
    $wrapper = 'flexiform_multistep_wrapper';
    module_load_include('inc', 'flexiform_multistep', 'flexiform_multistep.pages');
  }
}

/**
 * Implements hook_flexiform_rules_arguments_alter().
 */
function flexiform_multistep_flexiform_rules_arguments_alter(&$args, $form_state, $event) {
  if (!empty($form_state['step'])) {
    $args['flexiform_step'] = $form_state['step'];
  }
}