You are here

function menu_block_export_form_submit in Menu Block 7.3

Same name and namespace in other branches
  1. 7.2 menu_block_export.admin.inc \menu_block_export_form_submit()

Submit callback for menu_block_export_form().

File

./menu_block_export.admin.inc, line 55
Provides infrequently used functions and hooks for menu_block_export.

Code

function menu_block_export_form_submit(&$form, &$form_state) {
  $output = '';
  $module = check_plain($form_state['values']['name']);
  foreach (variable_get('menu_block_ids', array()) as $delta) {
    $config = menu_block_get_config($delta);

    // Use the constant instead of the constant's value.
    if ($config['menu_name'] == MENU_TREE__CURRENT_PAGE_MENU) {
      $config['menu_name'] = 'MENU_TREE__CURRENT_PAGE_MENU';
    }
    else {

      // If it's not the constant, wrap value in quotes.
      $config['menu_name'] = "'" . $config['menu_name'] . "'";
    }
    $id = "{$module}-{$delta}";
    if (strlen($id) > 32) {
      $id = md5($id);
    }
    $output .= <<<END_OF_CONFIG

    '{<span class="php-variable">$id</span>}' => array(
      'parent'      => {<span class="php-variable">$config</span>[<span class="php-string">'parent'</span>]},
      'title_link'  => {<span class="php-variable">$config</span>[<span class="php-string">'title_link'</span>]},
      'admin_title' => '{<span class="php-variable">$config</span>[<span class="php-string">'admin_title'</span>]}',
      'level'       => {<span class="php-variable">$config</span>[<span class="php-string">'level'</span>]},
      'follow'      => '{<span class="php-variable">$config</span>[<span class="php-string">'follow'</span>]}',
      'depth'       => {<span class="php-variable">$config</span>[<span class="php-string">'depth'</span>]},
      'expanded'    => {<span class="php-variable">$config</span>[<span class="php-string">'expanded'</span>]},
      'sort'        => {<span class="php-variable">$config</span>[<span class="php-string">'sort'</span>]},
    ),
END_OF_CONFIG;
  }
  $output = <<<END_OF_CONFIG
/**
 * Implements hook_menu_block_blocks().
 */
function {<span class="php-variable">$module</span>}_menu_block_blocks() {
  // The array key is the block delta used by menu block.
  return array({<span class="php-variable">$output</span>}
  );
}

END_OF_CONFIG;
  $element = array(
    '#type' => 'textarea',
    '#title' => t('Use this in your !module.module file:', array(
      '!module' => $module,
    )),
    '#value' => $output,
    '#rows' => 20,
    // Since this isn't a real form, manually add additional required properties.
    '#id' => 'menu-block-export-textarea',
    '#name' => 'export',
    '#required' => FALSE,
    '#attributes' => array(
      'style' => 'font-family: monospace;',
    ),
    '#title_display' => 'before',
    '#parents' => array(
      'dummy',
    ),
  );
  $form_state['output'] = drupal_render($element);
}