You are here

function custom_breadcrumbsapi_form in Custom Breadcrumbs 7.2

Same name and namespace in other branches
  1. 6.2 custom_breadcrumbsapi/custom_breadcrumbsapi.module \custom_breadcrumbsapi_form()

Form builder; Displays an edit form for a module page breadcrumb.

See also

custom_breadcrumbs_form_validate()

custom_breadcrumbs_form_submit()

1 string reference to 'custom_breadcrumbsapi_form'
custom_breadcrumbsapi_menu in custom_breadcrumbsapi/custom_breadcrumbsapi.module
Implements hook_menu().

File

custom_breadcrumbsapi/custom_breadcrumbsapi.module, line 125

Code

function custom_breadcrumbsapi_form($form, &$form_state, $type) {
  $form = array();
  $breadcrumb = NULL;
  $bid = arg(5);
  if (isset($bid)) {
    drupal_set_title(t('Edit Custom Breadcrumb for Module Page'));
    $breadcrumbs = custom_breadcrumbs_load_breadcrumbs('custom_breadcrumbsapi', NULL, array(
      'bid' => $bid,
    ));
    $breadcrumb = array_pop($breadcrumbs);
  }
  else {
    drupal_set_title(t('Add Custom Breadcrumb for Module Page'));
  }
  $options = array();

  // Include any templates in the theme registry.
  drupal_theme_initialize();
  $hooks = theme_get_registry();
  if (is_array($hooks)) {
    foreach ($hooks as $name => $hook) {
      if (isset($hook['template'])) {
        $options[$name] = $hook['template'];
      }
    }
  }

  // Include all module functions specified in hook_custom_breadcrumbsapi.
  $modules = module_implements('custom_breadcrumbsapi');
  foreach ($modules as $module) {
    $func = $module . '_custom_breadcrumbsapi';
    $names = $func();
    foreach ($names as $name) {
      $options[$name] = $name;
    }
  }
  if (empty($options)) {
    $form['notice'] = array(
      '#markup' => t('No module pages using theme templates or currently implementing the custom breadcrumbs api. Read the <a href="@help">documentation</a> to learn how to do this.', array(
        '@help' => url('admin/help/custom_breadcrumbsapi'),
      )),
    );
  }
  else {
    $form['module_page'] = array(
      '#type' => 'select',
      '#title' => t('Module Page'),
      '#required' => TRUE,
      '#options' => $options,
      '#description' => t('The module page that this custom breadcrumb trail will apply to.'),
      '#default_value' => isset($breadcrumb->module_page) ? $breadcrumb->module_page : NULL,
      '#weight' => -10,
    );

    // Store information needed to save this breadcrumb.
    $form['#module'] = 'custom_breadcrumbsapi';
    $form['#infokey'] = 'module';
    $form += custom_breadcrumbs_common_form_elements($bid, $breadcrumb);
    $form['visibility_php']['#description'] = t('Determine whether this breadcrumb should be displayed by using a PHP snippet to return TRUE or FALSE. For module pages in the theme registry, you will have access to the %var array. Consult the individual template files for variable names that are used as the arguments of this array. Do not use opening and closing php tags.', array(
      '%var' => '$variables',
    ));
    $form['#submit'][] = 'custom_breadcrumbs_form_submit';
    $form['#validate'][] = 'custom_breadcrumbs_form_validate';
  }
  return $form;
}