You are here

function ds_buildmodes_matrix_form in Display Suite 6.2

Same name and namespace in other branches
  1. 6.3 includes/ds.buildmodes.inc \ds_buildmodes_matrix_form()
  2. 6 includes/ds.buildmodes.inc \ds_buildmodes_matrix_form()

Build modes matrix form.

Parameters

string $module The name of the module.:

array $types A list of types.:

1 string reference to 'ds_buildmodes_matrix_form'
ds_build_modes_page in includes/ds.buildmodes.inc
Build modes overview.

File

includes/ds.buildmodes.inc, line 255
Manage build modes.

Code

function ds_buildmodes_matrix_form($form_state, $module, $types) {
  drupal_add_js(drupal_get_path('module', 'ds') . '/js/buildmodes.js');
  if (is_array($types) && !empty($types)) {

    // Exclude build mode matrix.
    $exclude_build_modes = variable_get($module . '_buildmodes_exclude', array());
    $all_build_modes = ds_get_build_modes($module);
    $build_modes = array(
      'ds_block_all' => array(
        'title' => t('All'),
      ),
    );
    if (count($all_build_modes) > 1) {
      $build_modes += $all_build_modes;
    }
    $form['#build_modes'] = $build_modes;
    $form['#types'] = $types;
    $form['#module'] = $module;
    foreach ($types as $tkey => $type) {
      $row_exluded = variable_get($module . '_type_' . $tkey, FALSE);
      foreach ($build_modes as $bkey => $mode) {

        // We create 2 form keys here. The first one is the checkbox,
        // the second is a hidden value to store the default value in.
        $form['exclude'][$tkey][$tkey . '-' . $bkey] = array(
          '#type' => 'checkbox',
          '#attributes' => array(
            'class' => 'checkbox-instance',
          ),
        );
        $form['exclude'][$tkey][$tkey . '-' . $bkey . '-disabled'] = array(
          '#type' => 'value',
          '#value' => isset($exclude_build_modes[$tkey][$bkey]) ? $exclude_build_modes[$tkey][$bkey] : NULL,
        );
        if ($bkey == 'ds_block_all') {
          $form['exclude'][$tkey][$tkey . '-' . $bkey]['#attributes']['class'] .= ' block-all';
          $form['exclude'][$tkey][$tkey . '-' . $bkey]['#default_value'] = $row_exluded;
        }
        else {
          $form['exclude'][$tkey][$tkey . '-' . $bkey]['#default_value'] = isset($exclude_build_modes[$tkey][$bkey]) ? $exclude_build_modes[$tkey][$bkey] : NULL;
          if ($row_exluded) {
            $form['exclude'][$tkey][$tkey . '-' . $bkey]['#disabled'] = 'disabled';
          }
        }
      }
    }
    $form['exclude']['submit'] = array(
      '#type' => 'submit',
      '#value' => t('Save settings'),
      '#submit' => array(
        'ds_build_modes_matrix_submit',
      ),
    );
  }
  return $form;
}