You are here

function cck_select_other_post_render in CCK Select Other 7

Same name and namespace in other branches
  1. 6 cck_select_other.module \cck_select_other_post_render()

Post-render callback to add javascript functionality

Parameters

$content:

$element:

Return value

$form

1 string reference to 'cck_select_other_post_render'
cck_select_other_element_info in ./cck_select_other.module
Implementation of hook_element_info().

File

./cck_select_other.module, line 420
Implements a select list widget that lets a user provide an alternate option.

Code

function cck_select_other_post_render($content, $element) {
  static $js;
  if ($element['#type'] != 'cck_select_other') {
    return $content;
  }

  // No matches = not our field.
  $n = preg_match_all("/[A-Za-z0-9\\-\\_]+/", $element['#name'], $matches);
  if ($n == 0) {
    return $element;
  }

  // By any chance if we don't have any array keys, get out of here.
  $keys = isset($matches[0]) ? $matches[0] : NULL;
  if (!isset($keys)) {
    return $element;
  }
  foreach ($keys as $key => $val) {
    $keys[$key] = preg_replace("/_/", '-', $val);
  }
  $field_id = implode('-', $keys);
  if (!$js) {
    drupal_add_js(drupal_get_path('module', 'cck_select_other') . '/cck_select_other.js');
    $js = TRUE;
  }
  drupal_add_js(array(
    'CCKSelectOther' => array(
      array(
        'field_id' => $field_id,
      ),
    ),
  ), array(
    'type' => 'setting',
  ));
  return $content;
}