You are here

function mongodb_block_ui_admin_configure in MongoDB 7

Menu callback; displays the mongodb_block_ui configuration form.

1 string reference to 'mongodb_block_ui_admin_configure'
mongodb_block_ui_menu in mongodb_block_ui/mongodb_block_ui.module
Implements hook_menu().

File

mongodb_block_ui/mongodb_block_ui.admin.inc, line 209
Admin page callbacks for the mongodb_block_ui module.

Code

function mongodb_block_ui_admin_configure($form, &$form_state, $theme, $module, $delta) {
  if (!($block = mongodb_collection('block', $theme)
    ->findOne(array(
    '_id' => array(
      'module' => $module,
      'delta' => $delta,
    ),
  )))) {
    $block = array();
  }
  if ($module == 'mongodb_block_ui' && ($custom_block = mongodb_block_ui_load($delta))) {
    $block += $custom_block;
    $form = mongodb_block_ui_custom_block_form($block);
  }
  $block = (object) $block;
  $form['title'] = array(
    '#type' => 'textfield',
    '#title' => t('Block title'),
    '#maxlength' => 64,
    '#description' => t('The title of the block as shown to the user.'),
    '#default_value' => isset($block->title) ? $block->title : '',
    '#weight' => -20,
  );
  $form['module'] = array(
    '#type' => 'value',
    '#value' => $module,
  );
  $form['delta'] = array(
    '#type' => 'value',
    '#value' => $delta,
  );

  // Get the block subject for the page title.
  $info = module_invoke($module, 'block_info');
  if (isset($info[$delta])) {
    drupal_set_title(t("'%name' block", array(
      '%name' => $info[$delta]['info'],
    )), PASS_THROUGH);
  }

  // Module-specific block configuration.
  if ($settings = module_invoke($module, 'block_configure', $delta)) {
    foreach ($settings as $k => $v) {
      $form['settings'][$k] = $v;
    }
  }
  $description = t("Specify pages by using their paths. Enter one path per line.\n    The '%' character is a wildcard. Example paths are %blog for the blog page\n    and %blog-wildcard for every personal blog. %front is the front page.", [
    '%blog' => 'blog',
    '%blog-wildcard' => 'blog/%',
    '%front' => '<front>',
  ]);

  // Visibility settings.
  $form['visibility_title'] = array(
    '#type' => 'item',
    '#title' => t('Visibility settings'),
  );
  $form['visibility'] = array(
    '#type' => 'vertical_tabs',
    '#attached' => array(
      'js' => array(
        drupal_get_path('module', 'mongodb_block_ui') . '/mongodb_block_ui.js',
      ),
    ),
  );

  // Per-path visibility.
  $form['visibility']['path_include'] = array(
    '#type' => 'fieldset',
    '#title' => t('Pages'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
    '#group' => 'visibility',
    '#weight' => 0,
  );
  $form['visibility']['path_exclude'] = array(
    '#type' => 'fieldset',
    '#title' => t('Pages exclude'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
    '#group' => 'visibility',
    '#weight' => 0,
  );
  $access = user_access('use PHP for settings');
  if (isset($block->visibility) && $block->visibility == 2 && !$access) {
    $form['visibility']['path']['visibility'] = array(
      '#type' => 'value',
      '#value' => 2,
    );
    $form['visibility']['path']['pages'] = array(
      '#type' => 'value',
      '#value' => isset($block->pages) ? $block->pages : '',
    );
  }
  else {
    if (module_exists('php') && $access) {
      $description .= ' ' . t('If the PHP option is chosen, enter PHP code between %php. Note that executing incorrect PHP code can break your Drupal site.', array(
        '%php' => '<?php ?>',
      ));
    }
    $form['visibility']['path_include']['pages'] = array(
      '#type' => 'textarea',
      '#title' => t('Show on these pages'),
      '#default_value' => isset($block->pages) ? implode("\n", $block->pages) : '',
      '#description' => $description,
    );
    $form['visibility']['path_exclude']['pages_exclude'] = array(
      '#type' => 'textarea',
      '#title' => t('Do not show on these pages'),
      '#default_value' => isset($block->pages_exclude) ? implode("\n", $block->pages_exclude) : '',
      '#description' => $description,
    );
  }
  $form['visibility']['node_type'] = array(
    '#type' => 'fieldset',
    '#title' => t('Content types'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
    '#group' => 'visibility',
    '#weight' => 5,
  );
  $form['visibility']['node_type']['types'] = array(
    '#type' => 'checkboxes',
    '#title' => t('Show block for specific content types'),
    '#default_value' => isset($block->node_type) ? $block->node_type : array(),
    '#options' => node_type_get_names(),
    '#description' => t('Show this block only on pages that display content of the given type(s). If you select no types, there will be no type-specific limitation.'),
  );
  $form['actions'] = array(
    '#type' => 'container',
    '#attributes' => array(
      'class' => array(
        'form-actions',
      ),
    ),
  );
  $form['actions']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save block'),
  );
  $form['#theme_key'] = $theme;
  return $form;
}