You are here

nd.plugins.inc in Node displays 6

Administration functions for ND plugins.

File

includes/nd.plugins.inc
View source
<?php

/**
 * @file
 * Administration functions for ND plugins.
 */

/**
 * Menu callback. Registers all plugins for ND.
 */
function nd_plugins() {
  $form = array();
  $plugins = nd_plugins_retrieve();
  $plugin_settings = variable_get('nd_plugin_settings', array());
  if (is_array($plugins)) {
    $form['#plugins'] = $plugins;
    foreach ($plugins as $key => $plugin) {
      $form['plugin_' . $plugin['key']] = array(
        '#type' => 'checkbox',
        '#default_value' => $plugin_settings[$plugin['key']]['status'],
      );
    }
  }
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save'),
  );
  return $form;
}

/**
 * Save the plugin settings.
 */
function nd_plugins_submit($form, &$form_state) {
  $plugin_settings = array();
  foreach ($form['#plugins'] as $key => $plugin) {
    if ($form_state['values']['plugin_' . $plugin['key']] == '1') {
      $plugin_settings[$plugin['key']] = $plugin;
      $plugin_settings[$plugin['key']]['status'] = '1';
    }
  }
  variable_set('nd_plugin_settings', $plugin_settings);
}

/**
 * Theme the form.
 */
function theme_nd_plugins($form) {
  $output = '';
  $header = array(
    t('Status'),
    t('Info'),
  );
  $rows = array();
  foreach ($form['#plugins'] as $key => $plugin) {
    $row = array();
    $row[] = array(
      'data' => drupal_render($form['plugin_' . $plugin['key']]),
    );
    $row[] = array(
      'data' => '<strong>' . $plugin['title'] . '</strong>: ' . $plugin['description'],
    );
    $rows[] = $row;
  }
  $output .= theme('table', $header, $rows);
  $output .= drupal_render($form);
  return $output;
}

/**
 * Retrieve all available plugins.
 */
function nd_plugins_retrieve() {
  $plugins = module_invoke_all('nd_plugins');
  foreach ($plugins as $plugin => $data) {
    $data['key'] = $plugin;
    $data['form_callback'] = 'nd_' . $plugin . '_form';
    $data['submit_callback'] = 'nd_' . $plugin . '_submit';
    $data['process_callback'] = 'nd_' . $plugin . '_process';
    if (isset($data['file']) && isset($data['path'])) {
      $data['filename'] = $data['path'] . '/' . $data['file'];
    }
    $plugins[$plugin] = $data;
  }
  return $plugins;
}

Functions

Namesort descending Description
nd_plugins Menu callback. Registers all plugins for ND.
nd_plugins_retrieve Retrieve all available plugins.
nd_plugins_submit Save the plugin settings.
theme_nd_plugins Theme the form.