You are here

function custom_breadcrumbs_features_form_alter in Custom Breadcrumbs Features 7.2

Implements hook_form_alter().

File

./custom_breadcrumbs_features.module, line 82
Module file for custom_breadcrumbs_features.

Code

function custom_breadcrumbs_features_form_alter(&$form, &$form_state, $form_id) {
  $cb_types = _custom_breadcrumbs_features_get_types();
  foreach ($cb_types as $table => $cb_type) {
    if ($form_id == $cb_type['form']) {

      // If this is a breadcrumb form, tweak field 'name'.
      $form['name']['#required'] = TRUE;
      $form['name']['#attached']['js'] = array(
        drupal_get_path('module', 'custom_breadcrumbs_features') . '/js/custom_breadcrumbs_features.js',
      );

      // If this is a breadcrumb form, add field 'machine_name' .
      if (empty($form['bid']['#value'])) {
        $default_value = '';
      }
      else {
        $breadcrumb = custom_breadcrumbs_load_breadcrumbs($cb_type['module'], $table, array(
          'bid' => $form['bid']['#value'],
        ));
        $default_value = array_pop($breadcrumb)->machine_name;
      }
      $form['machine_name'] = array(
        '#type' => 'machine_name',
        '#default_value' => $default_value,
        '#maxlength' => 32,
        '#disabled' => !empty($form['bid']['#value']),
        '#machine_name' => array(
          'exists' => "{$table}_features_load",
        ),
        '#description' => t('A unique machine-readable name for this breadcrumb. It must only contain lowercase letters, numbers, and underscores. This name will be used when featurizing breadcrumbs.'),
        '#weight' => -49,
      );

      // No need to loop over all breadcrumb types.
      break;
    }
  }
}