You are here

function custom_breadcrumbs_common_form_elements in Custom Breadcrumbs 7.2

Same name and namespace in other branches
  1. 6.2 custom_breadcrumbs.admin.inc \custom_breadcrumbs_common_form_elements()

Provides form elements commonly used by custom breadcrumbs submodules.

Parameters

string $bid: The breadcrumb id.

object $breadcrumb: The breadcrumb object.

Return value

form A form array with common custom breadcrumb elements.

7 calls to custom_breadcrumbs_common_form_elements()
custom_breadcrumbsapi_form in custom_breadcrumbsapi/custom_breadcrumbsapi.module
Form builder; Displays an edit form for a module page breadcrumb.
custom_breadcrumbs_form in ./custom_breadcrumbs.admin.inc
Form builder to edit a custom breadcrumb record.
custom_breadcrumbs_panels_form in custom_breadcrumbs_panels/custom_breadcrumbs_panels.module
Form builder; Displays an edit form for a panels breadcrumb.
custom_breadcrumbs_paths_form in custom_breadcrumbs_paths/custom_breadcrumbs_paths.module
Form builder; Provide an edit form for a custom breadcrumb paths breadcrumb.
custom_breadcrumbs_taxonomy_term_form in custom_breadcrumbs_taxonomy/custom_breadcrumbs_taxonomy.admin.inc
Term Form.

... See full list

File

./custom_breadcrumbs.admin.inc, line 292
Admin page callback file for the custom_breadcrumbs module.

Code

function custom_breadcrumbs_common_form_elements($bid, $breadcrumb) {

  // TODO: consider removing the $bid parameter since its part of the breadcrumb
  // object.
  // TODO: or should $breadcrumb default to NULL?
  $form = array();
  $form['bid'] = array(
    '#type' => 'hidden',
    '#value' => $bid,
  );
  $form['name'] = array(
    '#type' => 'textfield',
    '#title' => t('Breadcrumb Name'),
    '#default_value' => isset($breadcrumb->name) ? $breadcrumb->name : '',
    '#description' => t('This name will only appear when listing custom breadcrumbs. If left blank, a name for this breadcrumb will be generated for you.'),
    '#weight' => -50,
  );
  if (isset($breadcrumb)) {
    $cbid = custom_breadcrumbs_unique_breadcrumb_id($breadcrumb->breadcrumb_type, $breadcrumb->bid);
  }
  if (isset($cbid)) {
    $form['classid'] = array(
      '#markup' => '<strong>' . t('The CSS class name for this breadcrumb is !name', array(
        '!name' => $cbid,
      )) . '</strong>',
    );
  }
  $multilingual = _custom_breadcrumbs_multilingual();
  if ($multilingual) {
    $form['language'] = array(
      '#type' => 'select',
      '#title' => t('Language'),
      '#options' => array(
        '' => t('All languages'),
      ) + locale_language_list('name'),
      '#default_value' => isset($breadcrumb->language) ? $breadcrumb->language : NULL,
      '#description' => t('A breadcrumb set for a specific language will always be used when displaying a node in that language, and takes precedence over breadcrumbs set for <em>All languages</em>.'),
    );
  }
  else {
    $form['language'] = array(
      '#type' => 'value',
      '#value' => '',
    );
  }
  $form['visibility_php'] = array(
    '#type' => 'textarea',
    '#title' => t('Breadcrumb visibility'),
    '#access' => user_access('use php in custom breadcrumbs'),
    '#description' => t('Determine whether this breadcrumb should be displayed by using a PHP snippet to return TRUE or FALSE. Note that this code has access to the $node variable, and can check its type or any other property. Do not use opening and closing php tags.'),
    '#default_value' => isset($breadcrumb->visibility_php) ? $breadcrumb->visibility_php : '',
  );
  $description = t('A list of titles for the breadcrumb links, one on each line. For each crumb title you can also specify a title attribute to add to the link. Separate the crumb title and the title attribute with a pipe (|) symbol.');
  if (variable_get('custom_breadcrumbs_use_php_in_titles', FALSE) && user_access('use php in custom breadcrumbs')) {
    $description .= ' ' . t("Or, you can enter a small PHP code snippet (less than 250 characters) returning either an array of text strings for the breadcrumb titles, with one title per array element, or an associative array with elements 'titles' and 'paths' each containing an array of text strings for the breadcrumb titles and paths, respectively. Include the snippet between %php. Use with caution since incorrect PHP code can break your Drupal site. Token replacement will occur after any PHP is evaluated.", array(
      '%php' => '<?php ?>',
    ));
  }
  $form['titles'] = array(
    '#type' => 'textarea',
    '#title' => t('Titles'),
    '#required' => TRUE,
    '#description' => $description,
    '#default_value' => isset($breadcrumb->titles) ? $breadcrumb->titles : NULL,
  );
  $description = t('A list of Drupal paths for the breadcrumb links, one on each line.');
  if (variable_get('custom_breadcrumbs_use_php_in_titles', FALSE) && user_access('use php in custom breadcrumbs')) {
    $description .= ' ' . t("You can also enter a small PHP code snippet (less than 250 characters) returning an array of drupal paths for the breadcrumb links, with one path per array element. Include the snippet between %php. Use with caution since incorrect PHP code can break your Drupal site. Token replacement will occur after any PHP is evaluated.", array(
      '%php' => '<?php ?>',
    ));
  }
  $form['paths'] = array(
    '#type' => 'textarea',
    '#title' => t('Paths'),
    '#required' => FALSE,
    '#description' => $description,
    '#default_value' => isset($breadcrumb->paths) ? $breadcrumb->paths : NULL,
  );
  $form['help'] = array(
    '#type' => 'fieldset',
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
    '#title' => t('Placeholder tokens'),
    '#description' => t("The following placeholder tokens can be used in both paths and titles. When used in a path or title, they will be replaced with the appropriate values."),
  );
  if (module_exists('token')) {
    $form['help']['tokens'] = array(
      '#theme' => 'token_tree_link',
      '#token_types' => array(
        'node',
      ),
    );
  }
  else {
    $form['help']['#description'] = t("Core tokens can be used as dynamic placeholder tokens in your breadcrumb trails. To view a list of available tokens here, download and install the <a href='@token'>Token module</a> from Drupal.org.", array(
      '@token' => 'http://www.drupal.org/project/token',
    ));
    $form['help']['#collapsible'] = FALSE;
    $form['help']['#collapsed'] = FALSE;
  }
  $form['help2'] = array(
    '#type' => 'fieldset',
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
    '#title' => t('Special identifiers'),
    '#description' => t("The following identifiers can be used to achieve a special behavior. Identifiers should be added to the paths area in the following format: identifier|path.<br />For example: %pathauto_id|[ogname-raw]", array(
      '%pathauto_id' => '<pathauto>',
    )),
  );
  $form['help2']['tokens'] = array(
    '#markup' => theme('custom_breadcrumbs_help_identifiers'),
  );
  $form['actions'] = array(
    '#type' => 'actions',
  );
  $form['actions']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save'),
  );
  if (isset($bid)) {
    $form['actions']['delete'] = array(
      '#type' => 'submit',
      '#value' => t('Delete'),
      '#submit' => array(
        'custom_breadcrumbs_form_delete',
      ),
    );
  }
  $form['actions']['cancel'] = array(
    '#type' => 'submit',
    '#value' => t('Cancel'),
    '#submit' => array(
      'custom_breadcrumbs_form_cancel',
    ),
  );
  return $form;
}