You are here

function menu_block_admin_settings_form in Menu Block 6.2

Same name and namespace in other branches
  1. 7.3 menu_block.admin.inc \menu_block_admin_settings_form()
  2. 7.2 menu_block.admin.inc \menu_block_admin_settings_form()

Menu block admin settings form.

Return value

The settings form used by Menu block.

1 string reference to 'menu_block_admin_settings_form'
menu_block_menu in ./menu_block.module
Implements hook_menu().

File

./menu_block.admin.inc, line 372
Provides infrequently used functions for menu_block.

Code

function menu_block_admin_settings_form($form_state) {

  // Retrieve core's menus.
  $menus = menu_get_menus();

  // Retrieve all the menu names provided by hook_menu_block_get_sort_menus().
  $menus = array_merge($menus, module_invoke_all('menu_block_get_sort_menus'));
  asort($menus);

  // Load stored configuration.
  $menu_order = variable_get('menu_block_menu_order', array(
    'primary-links' => '',
    'secondary-links' => '',
  ));

  // Remove any menus no longer in the list of all menus.
  foreach (array_keys($menu_order) as $menu) {
    if (!isset($menus[$menu])) {
      unset($menu_order[$menu]);
    }
  }

  // Merge the saved configuration with any un-configured menus.
  $all_menus = $menu_order + $menus;
  $form['heading'] = array(
    '#value' => '<p>' . t('If a block is configured to use <em>"the menu selected by the page"</em>, the block will be generated from the first "available" menu that contains a link to the page.') . '</p>',
  );

  // Orderable list of menu selections.
  $form['menu_order'] = array(
    '#tree' => TRUE,
    '#theme' => 'menu_block_menu_order',
  );
  $order = 0;
  $total_menus = count($all_menus);
  foreach (array_keys($all_menus) as $menu_name) {
    $form['menu_order'][$menu_name] = array(
      'title' => array(
        '#value' => check_plain($menus[$menu_name]),
      ),
      'available' => array(
        '#type' => 'checkbox',
        '#attributes' => array(
          'title' => t('Select from the @menu_name menu', array(
            '@menu_name' => $menus[$menu_name],
          )),
        ),
        '#default_value' => isset($menu_order[$menu_name]),
      ),
      'weight' => array(
        '#type' => 'weight',
        '#default_value' => $order - $total_menus,
        '#delta' => $total_menus,
        '#id' => 'edit-menu-block-menus-' . $menu_name,
      ),
    );
    $order++;
  }
  $form['footer_note'] = array(
    '#value' => '<p>' . t('The above list will <em>not</em> affect menu blocks that are configured to use a specific menu.') . '</p>',
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save configuration'),
  );
  return $form;
}