You are here

function quicktabs_field_collection_get_quicktabs_options in QuickTabs Field Collection 7

Helper function to add QuickTab settings fields to the field settings form.

Taken from the QuickTab module and tweaked slightly to work within the field config form. If/when QuickTabs offers an API to pull in renderes and styles this function can be removed and the changes moved back into the normal settings form.

Parameters

array $element: The settings form array.

array $settings: The current settings for the field.

1 call to quicktabs_field_collection_get_quicktabs_options()
quicktabs_field_collection_field_formatter_settings_form in ./quicktabs_field_collection.module
Implements hook_field_formatter_settings_form().

File

./quicktabs_field_collection.module, line 162
Renders a field collection as QuickTabs.

Code

function quicktabs_field_collection_get_quicktabs_options(&$element, $settings) {
  $element['quicktabs'] = array(
    '#type' => 'fieldset',
    '#title' => t('QuickTab settings'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
    '#tree' => TRUE,
  );
  $element['quicktabs']['hide_empty_tabs'] = array(
    '#type' => 'checkbox',
    '#title' => t('Hide empty tabs'),
    '#description' => t('Hide tabs where there is no content available.'),
    '#default_value' => $settings['quicktabs']['hide_empty_tabs'],
  );
  ctools_include('plugins');
  $renderers = ctools_get_plugins('quicktabs', 'renderers');
  $renderer_options = array();
  foreach ($renderers as $name => $info) {
    if ($class = ctools_plugin_load_class('quicktabs', 'renderers', $name, 'handler')) {

      // Add the renderer to the dropdown list of renderers
      $renderer_options[$name] = $name;

      // Get the renderer's options form elements
      // PHP 5.2 doesn't support $class::staticMethod() syntax, so we have to
      // use call_user_func_array() until PHP 5.3 is required.
      $renderer_form_options[$name] = call_user_func_array(array(
        $class,
        'optionsForm',
      ), array(
        $qt,
      ));
    }
  }
  ksort($renderer_options);
  $element['quicktabs']['renderer'] = array(
    '#type' => 'select',
    '#title' => t('Renderer'),
    '#description' => t('Choose how to render the content.'),
    '#options' => $renderer_options,
    '#default_value' => $settings['quicktabs']['renderer'],
    '#attributes' => array(
      'class' => array(
        'qtfc-renderer-select',
      ),
    ),
  );

  // Add the renderer options form elements to the form, to be shown only if the
  // renderer in question is selected.
  $element['quicktabs']['options'] = array(
    '#tree' => TRUE,
  );
  foreach ($renderer_form_options as $renderer => $options) {
    $defaults = !empty($settings['quicktabs']['options'][$renderer]) ? $settings['quicktabs']['options'][$renderer] : array();
    foreach ($options as $key => &$option) {
      $renderer_settings = isset($defaults[$key]) ? $defaults[$key] : NULL;
      if (!empty($renderer_settings)) {

        // Settings needs special handling in the case of nested form items.
        $option = _quicktabs_field_collection_recurse_set_defaults($option, $renderer_settings);
      }
      $option['#states'] = array(
        'visible' => array(
          'select.qtfc-renderer-select' => array(
            'value' => $renderer,
          ),
        ),
      );
    }
    $element['quicktabs']['options'][$renderer] = $options;
  }
  if (module_exists('quicktabs_tabstyles')) {
    $styles = module_invoke_all('quicktabs_tabstyles');
    $style_options = array();

    // The keys used for options must be valid html IDs.
    foreach ($styles as $style) {
      $style_options[$style] = $style;
    }
    ksort($style_options);
    $element['quicktabs']['style'] = array(
      '#type' => 'select',
      '#title' => t('Style'),
      '#description' => t('Choose the quicktab style.'),
      '#options' => array(
        'default' => t('Default style'),
      ) + array(
        'nostyle' => t('No style'),
      ) + $style_options,
      '#default_value' => $settings['quicktabs']['style'],
      '#states' => array(
        'visible' => array(
          'select.qtfc-renderer-select' => array(
            'value' => 'quicktabs',
          ),
        ),
      ),
    );
  }
}