You are here

function fasttoggle_get_settings_form_items in Fasttoggle 7

Get settings form items.

Parameters

array $config: The array of configuration items.

Return value

array|mixed The setting form items.

2 calls to fasttoggle_get_settings_form_items()
fasttoggle_node_form_node_type_form_alter in module/fasttoggle_node/fasttoggle_node.module
Implements hook_form_FORM_ID_alter().
fasttoggle_settings_form in ./fasttoggle.admin.inc
Configures what fast toggling options are available (menu callback)

File

./fasttoggle.admin.inc, line 19

Code

function fasttoggle_get_settings_form_items(array $config = array()) {
  $form = array();
  $setting_key = NULL;
  if (empty($config)) {
    $object_type_filter = NULL;
    $object_subtype_filter = NULL;
    $dummy_obj = NULL;
    $desc_key = "global_settings_desc";
  }
  else {
    $object_type_filter = $config['type'];
    $object_subtype_filter = $config['subtype'];
    $dummy_obj = new stdClass();
    $dummy_obj->type = $object_subtype_filter;
    $desc_key = "nodetype_settings_desc";
  }
  $config_data = module_invoke_all('fasttoggle_available_links', $object_type_filter, $dummy_obj);
  foreach ($config_data as $object_type => $object_data) {
    if (isset($object_type_filter) && $object_type != $object_type_filter) {
      continue;
    }

    // Label settings.
    $defaults = fasttoggle_defaults_from_config_data($object_data);
    unset($setting_key);
    $form["fasttoggle_{$object_type}"] = array(
      '#type' => 'fieldset',
      '#title' => isset($config['#title']) ? $config['#title'] : t("%type", array(
        '%type' => ucfirst($object_type),
      )),
      '#description' => t("Select what options for fast toggling of this object's settings are available."),
    );
    $subform =& $form["fasttoggle_{$object_type}"];
    foreach ($object_data['fields'] as $group_name => $group_data) {

      // Start a new subgroup of settings?
      if (!isset($setting_key) || isset($group_data['#title'])) {

        // For nodes, the setter adds the node type so we need to do so too when
        // getting only.
        $setting_key = isset($config['setting']) ? "{$config['setting']}_{$object_type}_{$config['subtype']}" : "fasttoggle_{$object_type}_{$group_name}_settings";
        $current_values = array_filter(variable_get($setting_key, $defaults));

        // Some forms (node_type_admin...) do array_keys on the values saved.
        $temp = array_reverse(array_keys($current_values), TRUE);
        if (array_pop($temp) === 0) {
          $current_values = array_flip($current_values);
        }
        if (isset($config['write_key'])) {
          $setting_key = $config['write_key'];
        }
      }

      // Create the subgroup if it doesn't already exist.
      if (!isset($subform[$setting_key])) {
        $subform[$setting_key] = array(
          '#type' => 'checkboxes',
          '#title' => t("Togglable %type %group fields and settings.", array(
            '%type' => ucfirst($object_type),
            '%group' => ucfirst($group_name),
          )),
          '#description' => isset($object_data[$desc_key]) ? $object_data[$desc_key] : '',
          '#options' => array(),
          '#default_value' => array(),
        );
      }
      foreach ($group_data['instances'] as $field_name => $field_data) {
        $value_key = "{$group_name}_{$field_name}";
        $subform[$setting_key]['#options'][$value_key] = $field_data['description'];
        if (isset($current_values[$value_key])) {
          $subform[$setting_key]['#default_value'][] = $value_key;
        }
      }
    }

    // Extra settings.
    if (empty($config) && isset($object_data['extra_settings'])) {
      $subform['extra_settings'] = array(
        '#type' => 'item',
        '#title' => t("Additional %type settings.", array(
          '%type' => $object_type,
        )),
      );
      foreach ($object_data['extra_settings'] as $key => $data) {
        $subform['extra_settings'][$key] = $data;
      }
    }
  }
  if (!empty($config)) {
    $temp = $form;
    $form = array_pop($temp);
  }
  return $form;
}