You are here

function _linkit_build_plugin_form_fields in Linkit 7.2

Append plugin form element to the setttings form.

1 call to _linkit_build_plugin_form_fields()
linkit_profiles_export_ui_form in plugins/export_ui/linkit_profiles.inc
Generate a profile form.

File

plugins/export_ui/linkit_profiles.inc, line 177

Code

function _linkit_build_plugin_form_fields(&$form, $profile, $plugins) {
  $form['data']['plugins_fieldset'] = array(
    '#type' => 'fieldset',
    '#title' => t('Linkit plugins'),
    '#description' => t('Linkit is all about the plugins. They define what content Linkit will present in the autocomplete search field.'),
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
    '#tree' => FALSE,
    '#theme' => '_linkit_theme_profile_form_table',
  );
  $form['data']['plugins_fieldset']['plugins'] = array(
    '#markup' => '',
    '#tree' => TRUE,
    '#parents' => array(
      'data',
      'plugins',
    ),
  );

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

    // Get the plugin handler.
    $handler = linkit_get_plugin_handler($plugin, $profile);
    $tmp_plugins[$name]['name'] = array(
      '#markup' => $handler
        ->ui_title(),
    );
    $tmp_plugins[$name]['description'] = array(
      '#markup' => $handler
        ->ui_description(),
    );
    $tmp_plugins[$name]['weight'] = array(
      '#type' => 'weight',
      '#title' => t('Weight for @title', array(
        '@title' => $handler
          ->ui_title(),
      )),
      '#title_display' => 'invisible',
      '#default_value' => isset($profile->data['plugins'][$name]['weight']) ? $profile->data['plugins'][$name]['weight'] : LINKIT_DEFAULT_WEIGHT,
    );
    $tmp_plugins[$name]['enabled'] = array(
      '#type' => 'checkbox',
      '#title' => t('Enable @title', array(
        '@title' => $handler
          ->ui_title(),
      )),
      '#title_display' => 'invisible',
    );
    if (isset($profile->data['plugins'])) {
      $tmp_plugins[$name]['enabled']['#default_value'] = isset($profile->data['plugins'][$name]['enabled']) ? $profile->data['plugins'][$name]['enabled'] : FALSE;
    }
    elseif (in_array($name, array(
      'node',
      'external',
      'file',
    ))) {
      $tmp_plugins[$name]['enabled']['#default_value'] = TRUE;
    }
  }

  // Sort by #weight.
  uasort($tmp_plugins, '_linkit_sort_plugins_by_weight');
  foreach ($tmp_plugins as $name => $plugin) {
    $form['data']['plugins_fieldset']['plugins'][$name] = $plugin;
  }
}