You are here

function _linkit_build_search_plugin_form_fields in Linkit 7.3

Append search plugin form element to the profile form.

Parameters

LinkitProfile $profile: A profile object contains all settings for the profile.

See also

linkit_profiles_form()

1 call to _linkit_build_search_plugin_form_fields()
linkit_profiles_form in plugins/export_ui/linkit_profiles.inc
Linkit profile settings form.

File

plugins/export_ui/linkit_profiles.inc, line 203

Code

function _linkit_build_search_plugin_form_fields(&$form, LinkitProfile $profile) {

  // Load all search plugins.
  $search_plugins = linkit_search_plugin_load_all();
  $form['data']['search_plugins_fieldset'] = array(
    '#type' => 'fieldset',
    '#title' => t('Search plugins'),
    '#description' => t('Linkit is all about the search plugins. They define what content Linkit will present in the autocomplete search field.'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
    '#tree' => FALSE,
  );
  $form['data']['search_plugins_fieldset']['search_plugins'] = array(
    '#markup' => '',
    '#tree' => TRUE,
    '#parents' => array(
      'data',
      'search_plugins',
    ),
    '#theme' => 'linkit_plugin_form_table',
  );
  $form['data']['search_plugins_fieldset']['search_plugins_settings'] = array(
    '#markup' => '',
    '#tree' => TRUE,
    '#parents' => array(
      'data',
    ),
  );

  // Used to store plugin form elements temporary so we can use this to sort by
  // weight later.
  $tmp = array();
  foreach ($search_plugins as $name => $plugin_definition) {

    // Get a plugin instance.
    $plugin = LinkitSearchPlugin::factory($plugin_definition, $profile);
    $tmp[$name]['name'] = array(
      '#markup' => $plugin
        ->ui_title(),
    );
    $tmp[$name]['description'] = array(
      '#markup' => $plugin
        ->ui_description(),
    );
    $tmp[$name]['enabled'] = array(
      '#type' => 'checkbox',
      '#title' => t('Enable @title', array(
        '@title' => $plugin
          ->ui_title(),
      )),
      '#title_display' => 'invisible',
      '#default_value' => isset($profile->data['search_plugins'][$name]['enabled']) ? $profile->data['search_plugins'][$name]['enabled'] : FALSE,
    );
    $tmp[$name]['weight'] = array(
      '#type' => 'weight',
      '#title' => t('Weight for @title', array(
        '@title' => $plugin
          ->ui_title(),
      )),
      '#title_display' => 'invisible',
      '#default_value' => isset($profile->data['search_plugins'][$name]['weight']) ? $profile->data['search_plugins'][$name]['weight'] : '',
    );

    // Append the search plugin specific settings.
    $plugin_specific_settings = $plugin
      ->buildSettingsForm();
    if ($plugin_specific_settings) {

      // Add the handler settings form to the generic.
      $form['data']['search_plugins_fieldset']['search_plugins_settings'] += $plugin_specific_settings;
    }
  }

  // Sort by weight.
  uasort($tmp, '_linkit_sort_plugins_by_weight_default_value');
  foreach ($tmp as $name => $element) {
    $form['data']['search_plugins_fieldset']['search_plugins'][$name] = $element;
  }
}