| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
function drupal_get_form($form_id) {
|
| 70 |
$form_state = array();
|
| 71 |
|
| 72 |
$args = func_get_args();
|
| 73 |
|
| 74 |
array_shift($args);
|
| 75 |
$form_state['args'] = $args;
|
| 76 |
|
| 77 |
return drupal_build_form($form_id, $form_state);
|
| 78 |
}
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
function drupal_build_form($form_id, &$form_state) {
|
| 124 |
|
| 125 |
$form_state += form_state_defaults();
|
| 126 |
|
| 127 |
if (!isset($form_state['input'])) {
|
| 128 |
$form_state['input'] = $form_state['method'] == 'get' ? $_GET : $_POST;
|
| 129 |
}
|
| 130 |
|
| 131 |
$cacheable = FALSE;
|
| 132 |
|
| 133 |
if (isset($_SESSION['batch_form_state'])) {
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
$form_state = $_SESSION['batch_form_state'];
|
| 138 |
unset($_SESSION['batch_form_state']);
|
| 139 |
}
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
if (isset($form_state['input']['form_id']) && $form_state['input']['form_id'] == $form_id && !empty($form_state['input']['form_build_id'])) {
|
| 147 |
$form = form_get_cache($form_state['input']['form_build_id'], $form_state);
|
| 148 |
}
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
if (!isset($form)) {
|
| 154 |
$form = drupal_retrieve_form($form_id, $form_state);
|
| 155 |
$form_build_id = 'form-' . md5(uniqid(mt_rand(), TRUE));
|
| 156 |
$form['#build_id'] = $form_build_id;
|
| 157 |
|
| 158 |
|
| 159 |
if ($form_state['method'] == 'get' && !isset($form['#method'])) {
|
| 160 |
$form['#method'] = 'get';
|
| 161 |
}
|
| 162 |
|
| 163 |
drupal_prepare_form($form_id, $form, $form_state);
|
| 164 |
|
| 165 |
|
| 166 |
$original_form = $form;
|
| 167 |
$cacheable = TRUE;
|
| 168 |
}
|
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
drupal_process_form($form_id, $form, $form_state);
|
| 176 |
|
| 177 |
if ($cacheable && !empty($form_state['cache']) && empty($form['#no_cache'])) {
|
| 178 |
|
| 179 |
|
| 180 |
form_set_cache($form_build_id, $original_form, $form_state);
|
| 181 |
}
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
if ((!empty($form_state['storage']) || $form_state['rebuild']) && $form_state['submitted'] && !form_get_errors()) {
|
| 199 |
$form = drupal_rebuild_form($form_id, $form_state);
|
| 200 |
}
|
| 201 |
|
| 202 |
|
| 203 |
if (!isset($form['#theme'])) {
|
| 204 |
drupal_theme_initialize();
|
| 205 |
$registry = theme_get_registry();
|
| 206 |
if (isset($registry[$form_id])) {
|
| 207 |
$form['#theme'] = $form_id;
|
| 208 |
}
|
| 209 |
}
|
| 210 |
|
| 211 |
return $form;
|
| 212 |
}
|
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
function form_state_defaults() {
|
| 218 |
|
| 219 |
'rebuild' => FALSE,
|
| 220 |
'redirect' => NULL,
|
| 221 |
'storage' => NULL,
|
| 222 |
'submitted' => FALSE,
|
| 223 |
'programmed' => FALSE,
|
| 224 |
'cache'=> FALSE,
|
| 225 |
'method' => 'post',
|
| 226 |
'groups' => array(),
|
| 227 |
);
|
| 228 |
}
|
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
|
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
|
| 250 |
|
| 251 |
|
| 252 |
|
| 253 |
|
| 254 |
|
| 255 |
|
| 256 |
|
| 257 |
|
| 258 |
|
| 259 |
|
| 260 |
|
| 261 |
|
| 262 |
|
| 263 |
|
| 264 |
function drupal_rebuild_form($form_id, &$form_state, $form_build_id = NULL) {
|
| 265 |
$form = drupal_retrieve_form($form_id, $form_state);
|
| 266 |
|
| 267 |
if (!isset($form_build_id)) {
|
| 268 |
|
| 269 |
$form_build_id = 'form-' . md5(mt_rand());
|
| 270 |
}
|
| 271 |
$form['#build_id'] = $form_build_id;
|
| 272 |
drupal_prepare_form($form_id, $form, $form_state);
|
| 273 |
|
| 274 |
if (empty($form['#no_cache'])) {
|
| 275 |
|
| 276 |
|
| 277 |
|
| 278 |
form_set_cache($form_build_id, $form, $form_state);
|
| 279 |
}
|
| 280 |
|
| 281 |
|
| 282 |
|
| 283 |
|
| 284 |
$form_state['input'] = array();
|
| 285 |
|
| 286 |
|
| 287 |
|
| 288 |
$form_state['groups'] = array();
|
| 289 |
|
| 290 |
|
| 291 |
|
| 292 |
$form = form_builder($form_id, $form, $form_state);
|
| 293 |
return $form;
|
| 294 |
}
|
| 295 |
|
| 296 |
|
| 297 |
|
| 298 |
|
| 299 |
function form_get_cache($form_build_id, &$form_state) {
|
| 300 |
if ($cached = cache_get('form_' . $form_build_id, 'cache_form')) {
|
| 301 |
$form = $cached->data;
|
| 302 |
global $user;
|
| 303 |
if ((isset($form['#cache_token']) && drupal_valid_token($form['#cache_token'])) || (!isset($form['#cache_token']) && !$user->uid)) {
|
| 304 |
if ($cached = cache_get('storage_' . $form_build_id, 'cache_form')) {
|
| 305 |
$form_state['storage'] = $cached->data;
|
| 306 |
}
|
| 307 |
return $form;
|
| 308 |
}
|
| 309 |
}
|
| 310 |
}
|
| 311 |
|
| 312 |
|
| 313 |
|
| 314 |
|
| 315 |
function form_set_cache($form_build_id, $form, $form_state) {
|
| 316 |
|
| 317 |
$expire = 21600;
|
| 318 |
global $user;
|
| 319 |
if ($user->uid) {
|
| 320 |
$form['#cache_token'] = drupal_get_token();
|
| 321 |
}
|
| 322 |
cache_set('form_' . $form_build_id, $form, 'cache_form', REQUEST_TIME + $expire);
|
| 323 |
if (!empty($form_state['storage'])) {
|
| 324 |
cache_set('storage_' . $form_build_id, $form_state['storage'], 'cache_form', REQUEST_TIME + $expire);
|
| 325 |
}
|
| 326 |
}
|
| 327 |
|
| 328 |
|
| 329 |
|
| 330 |
|
| 331 |
|
| 332 |
|
| 333 |
|
| 334 |
|
| 335 |
|
| 336 |
|
| 337 |
|
| 338 |
|
| 339 |
|
| 340 |
|
| 341 |
|
| 342 |
|
| 343 |
|
| 344 |
|
| 345 |
|
| 346 |
|
| 347 |
|
| 348 |
|
| 349 |
|
| 350 |
|
| 351 |
|
| 352 |
|
| 353 |
|
| 354 |
|
| 355 |
|
| 356 |
|
| 357 |
|
| 358 |
|
| 359 |
|
| 360 |
|
| 361 |
|
| 362 |
|
| 363 |
|
| 364 |
|
| 365 |
|
| 366 |
|
| 367 |
|
| 368 |
|
| 369 |
|
| 370 |
|
| 371 |
|
| 372 |
function drupal_form_submit($form_id, &$form_state) {
|
| 373 |
if (!isset($form_state['args'])) {
|
| 374 |
$args = func_get_args();
|
| 375 |
array_shift($args);
|
| 376 |
array_shift($args);
|
| 377 |
$form_state['args'] = $args;
|
| 378 |
}
|
| 379 |
|
| 380 |
$form = drupal_retrieve_form($form_id, $form_state);
|
| 381 |
$form_state['input'] = $form_state['values'];
|
| 382 |
$form_state['programmed'] = TRUE;
|
| 383 |
|
| 384 |
$form_state['submitted'] = TRUE;
|
| 385 |
|
| 386 |
$form_state += form_state_defaults();
|
| 387 |
|
| 388 |
drupal_prepare_form($form_id, $form, $form_state);
|
| 389 |
drupal_process_form($form_id, $form, $form_state);
|
| 390 |
}
|
| 391 |
|
| 392 |
|
| 393 |
|
| 394 |
|
| 395 |
|
| 396 |
|
| 397 |
|
| 398 |
|
| 399 |
|
| 400 |
|
| 401 |
|
| 402 |
|
| 403 |
|
| 404 |
|
| 405 |
|
| 406 |
|
| 407 |
|
| 408 |
|
| 409 |
|
| 410 |
|
| 411 |
function drupal_retrieve_form($form_id, &$form_state) {
|
| 412 |
$forms = &drupal_static(__FUNCTION__);
|
| 413 |
|
| 414 |
|
| 415 |
|
| 416 |
|
| 417 |
$args = $form_state['args'];
|
| 418 |
|
| 419 |
|
| 420 |
|
| 421 |
if (!drupal_function_exists($form_id)) {
|
| 422 |
|
| 423 |
|
| 424 |
|
| 425 |
|
| 426 |
|
| 427 |
|
| 428 |
|
| 429 |
|
| 430 |
|
| 431 |
|
| 432 |
|
| 433 |
if (!isset($forms) || !isset($forms[$form_id])) {
|
| 434 |
$forms = module_invoke_all('forms', $form_id, $args);
|
| 435 |
}
|
| 436 |
$form_definition = $forms[$form_id];
|
| 437 |
if (isset($form_definition['callback arguments'])) {
|
| 438 |
$args = array_merge($form_definition['callback arguments'], $args);
|
| 439 |
}
|
| 440 |
if (isset($form_definition['callback'])) {
|
| 441 |
$callback = $form_definition['callback'];
|
| 442 |
drupal_function_exists($callback);
|
| 443 |
}
|
| 444 |
}
|
| 445 |
|
| 446 |
$args = array_merge(array(&$form_state), $args);
|
| 447 |
|
| 448 |
|
| 449 |
|
| 450 |
$form = call_user_func_array(isset($callback) ? $callback : $form_id, $args);
|
| 451 |
$form['#form_id'] = $form_id;
|
| 452 |
$form['#args'] = $form_state['args'];
|
| 453 |
return $form;
|
| 454 |
}
|
| 455 |
|
| 456 |
|
| 457 |
|
| 458 |
|
| 459 |
|
| 460 |
|
| 461 |
|
| 462 |
|
| 463 |
|
| 464 |
|
| 465 |
|
| 466 |
|
| 467 |
|
| 468 |
|
| 469 |
|
| 470 |
|
| 471 |
function drupal_process_form($form_id, &$form, &$form_state) {
|
| 472 |
$form_state['values'] = array();
|
| 473 |
|
| 474 |
|
| 475 |
if ($form_state['method'] == 'get' && !empty($form_state['always_process'])) {
|
| 476 |
if (!isset($form_state['input']['form_build_id'])) {
|
| 477 |
$form_state['input']['form_build_id'] = $form['#build_id'];
|
| 478 |
}
|
| 479 |
if (!isset($form_state['input']['form_id'])) {
|
| 480 |
$form_state['input']['form_id'] = $form_id;
|
| 481 |
}
|
| 482 |
if (!isset($form_state['input']['form_token']) && isset($form['#token'])) {
|
| 483 |
$form_state['input']['form_token'] = drupal_get_token($form['#token']);
|
| 484 |
}
|
| 485 |
}
|
| 486 |
|
| 487 |
|
| 488 |
$form = form_builder($form_id, $form, $form_state);
|
| 489 |
|
| 490 |
|
| 491 |
if ($form_state['process_input']) {
|
| 492 |
drupal_validate_form($form_id, $form, $form_state);
|
| 493 |
|
| 494 |
|
| 495 |
|
| 496 |
|
| 497 |
|
| 498 |
|
| 499 |
drupal_static_reset('form_clean_id');
|
| 500 |
|
| 501 |
if ($form_state['submitted'] && !form_get_errors() && !$form_state['rebuild']) {
|
| 502 |
|
| 503 |
form_execute_handlers('submit', $form, $form_state);
|
| 504 |
|
| 505 |
|
| 506 |
|
| 507 |
|
| 508 |
if (variable_get('cache', CACHE_DISABLED) == CACHE_DISABLED && !empty($form_state['values']['form_build_id'])) {
|
| 509 |
cache_clear_all('form_' . $form_state['values']['form_build_id'], 'cache_form');
|
| 510 |
cache_clear_all('storage_' . $form_state['values']['form_build_id'], 'cache_form');
|
| 511 |
}
|
| 512 |
|
| 513 |
|
| 514 |
|
| 515 |
|
| 516 |
|
| 517 |
if ($batch =& batch_get() && !isset($batch['current_set'])) {
|
| 518 |
|
| 519 |
|
| 520 |
$batch['form'] = $form;
|
| 521 |
$batch['form_state'] = $form_state;
|
| 522 |
$batch['progressive'] = !$form_state['programmed'];
|
| 523 |
batch_process();
|
| 524 |
|
| 525 |
|
| 526 |
|
| 527 |
|
| 528 |
}
|
| 529 |
|
| 530 |
|
| 531 |
$form_state['executed'] = TRUE;
|
| 532 |
|
| 533 |
|
| 534 |
|
| 535 |
|
| 536 |
|
| 537 |
|
| 538 |
|
| 539 |
|
| 540 |
|
| 541 |
|
| 542 |
|
| 543 |
|
| 544 |
if (!$form_state['programmed'] && empty($form_state['rebuild']) && empty($form_state['storage']) && empty($form_state['no_redirect'])) {
|
| 545 |
drupal_redirect_form($form, $form_state['redirect']);
|
| 546 |
}
|
| 547 |
}
|
| 548 |
}
|
| 549 |
}
|
| 550 |
|
| 551 |
|
| 552 |
|
| 553 |
|
| 554 |
|
| 555 |
|
| 556 |
|
| 557 |
|
| 558 |
|
| 559 |
|
| 560 |
|
| 561 |
|
| 562 |
|
| 563 |
|
| 564 |
|
| 565 |
function drupal_prepare_form($form_id, &$form, &$form_state) {
|
| 566 |
global $user;
|
| 567 |
|
| 568 |
$form['#type'] = 'form';
|
| 569 |
$form_state['programmed'] = isset($form_state['programmed']) ? $form_state['programmed'] : FALSE;
|
| 570 |
|
| 571 |
if (isset($form['#build_id'])) {
|
| 572 |
$form['form_build_id'] = array(
|
| 573 |
'#type' => 'hidden',
|
| 574 |
'#value' => $form['#build_id'],
|
| 575 |
'#id' => $form['#build_id'],
|
| 576 |
'#name' => 'form_build_id',
|
| 577 |
|
| 578 |
}
|
| 579 |
|
| 580 |
|
| 581 |
|
| 582 |
|
| 583 |
|
| 584 |
if (isset($form['#token'])) {
|
| 585 |
if ($form['#token'] === FALSE || $user->uid == 0 || $form_state['programmed']) {
|
| 586 |
unset($form['#token']);
|
| 587 |
}
|
| 588 |
|
| 589 |
$form['form_token'] = array('#type' => 'token', '#default_value' => drupal_get_token($form['#token']));
|
| 590 |
|
| 591 |
}
|
| 592 |
elseif (isset($user->uid) && $user->uid && !$form_state['programmed']) {
|
| 593 |
$form['#token'] = $form_id;
|
| 594 |
$form['form_token'] = array(
|
| 595 |
'#id' => form_clean_id('edit-' . $form_id . '-form-token'),
|
| 596 |
'#type' => 'token',
|
| 597 |
'#default_value' => drupal_get_token($form['#token']),
|
| 598 |
|
| 599 |
}
|
| 600 |
|
| 601 |
if (isset($form_id)) {
|
| 602 |
$form['form_id'] = array(
|
| 603 |
'#type' => 'hidden',
|
| 604 |
'#value' => $form_id,
|
| 605 |
'#id' => form_clean_id("edit-$form_id"),
|
| 606 |
|
| 607 |
}
|
| 608 |
if (!isset($form['#id'])) {
|
| 609 |
$form['#id'] = form_clean_id($form_id);
|
| 610 |
}
|
| 611 |
|
| 612 |
$form += element_info('form');
|
| 613 |
$form += array('#tree' => FALSE, '#parents' => array());
|
| 614 |
|
| 615 |
if (!isset($form['#validate'])) {
|
| 616 |
if (drupal_function_exists($form_id . '_validate')) {
|
| 617 |
$form['#validate'] = array($form_id . '_validate');
|
| 618 |
}
|
| 619 |
}
|
| 620 |
|
| 621 |
if (!isset($form['#submit'])) {
|
| 622 |
if (drupal_function_exists($form_id . '_submit')) {
|
| 623 |
|
| 624 |
$form['#submit'] = array($form_id . '_submit');
|
| 625 |
}
|
| 626 |
}
|
| 627 |
|
| 628 |
|
| 629 |
|
| 630 |
|
| 631 |
|
| 632 |
|
| 633 |
|
| 634 |
$data = &$form;
|
| 635 |
$data['__drupal_alter_by_ref'] = array(&$form_state);
|
| 636 |
drupal_alter('form_' . $form_id, $data);
|
| 637 |
|
| 638 |
|
| 639 |
|
| 640 |
$data['__drupal_alter_by_ref'] = array(&$form_state);
|
| 641 |
drupal_alter('form', $data, $form_id);
|
| 642 |
}
|
| 643 |
|
| 644 |
|
| 645 |
|
| 646 |
|
| 647 |
|
| 648 |
|
| 649 |
|
| 650 |
|
| 651 |
|
| 652 |
|
| 653 |
|
| 654 |
|
| 655 |
|
| 656 |
|
| 657 |
|
| 658 |
|
| 659 |
|
| 660 |
|
| 661 |
|
| 662 |
|
| 663 |
|
| 664 |
|
| 665 |
function drupal_validate_form($form_id, $form, &$form_state) {
|
| 666 |
$validated_forms = &drupal_static(__FUNCTION__, array());
|
| 667 |
|
| 668 |
if (isset($validated_forms[$form_id]) && empty($form_state['must_validate'])) {
|
| 669 |
return;
|
| 670 |
}
|
| 671 |
|
| 672 |
|
| 673 |
|
| 674 |
if (isset($form['#token'])) {
|
| 675 |
if (!drupal_valid_token($form_state['values']['form_token'], $form['#token'])) {
|
| 676 |
|
| 677 |
form_set_error('form_token', t('Validation error, please try again. If this error persists, please contact the site administrator.'));
|
| 678 |
}
|
| 679 |
}
|
| 680 |
|
| 681 |
_form_validate($form, $form_state, $form_id);
|
| 682 |
$validated_forms[$form_id] = TRUE;
|
| 683 |
}
|
| 684 |
|
| 685 |
|
| 686 |
|
| 687 |
|
| 688 |
|
| 689 |
|
| 690 |
|
| 691 |
|
| 692 |
|
| 693 |
|
| 694 |
function drupal_redirect_form($form, $redirect = NULL) {
|
| 695 |
$goto = NULL;
|
| 696 |
if (isset($redirect)) {
|
| 697 |
$goto = $redirect;
|
| 698 |
}
|
| 699 |
if ($goto !== FALSE && isset($form['#redirect'])) {
|
| 700 |
$goto = $form['#redirect'];
|
| 701 |
}
|
| 702 |
if (!isset($goto) || ($goto !== FALSE)) {
|
| 703 |
if (isset($goto)) {
|
| 704 |
if (is_array($goto)) {
|
| 705 |
call_user_func_array('drupal_goto', $goto);
|
| 706 |
}
|
| 707 |
|
| 708 |
|
| 709 |
|
| 710 |
|
| 711 |
$function = drupal_installation_attempted() ? 'install_goto' : 'drupal_goto';
|
| 712 |
$function($goto);
|
| 713 |
|
| 714 |
}
|
| 715 |
drupal_goto($_GET['q']);
|
| 716 |
}
|
| 717 |
}
|
| 718 |
|
| 719 |
|
| 720 |
|
| 721 |
|
| 722 |
|
| 723 |
|
| 724 |
|
| 725 |
|
| 726 |
|
| 727 |
|
| 728 |
|
| 729 |
|
| 730 |
|
| 731 |
|
| 732 |
|
| 733 |
|
| 734 |
|
| 735 |
|
| 736 |
|
| 737 |
|
| 738 |
|
| 739 |
|
| 740 |
function _form_validate($elements, &$form_state, $form_id = NULL) {
|
| 741 |
|
| 742 |
$t = get_t();
|
| 743 |
|
| 744 |
|
| 745 |
foreach (element_children($elements) as $key) {
|
| 746 |
if (isset($elements[$key]) && $elements[$key]) {
|
| 747 |
_form_validate($elements[$key], $form_state);
|
| 748 |
}
|
| 749 |
}
|
| 750 |
|
| 751 |
if (!isset($elements['#validated']) || !$elements['#validated']) {
|
| 752 |
if (isset($elements['#needs_validation'])) {
|
| 753 |
|
| 754 |
|
| 755 |
|
| 756 |
|
| 757 |
if ($elements['#required'] && (!count($elements['#value']) || (is_string($elements['#value']) && strlen(trim($elements['#value'])) == 0))) {
|
| 758 |
form_error($elements, $t('!name field is required.', array('!name' => $elements['#title'])));
|
| 759 |
}
|
| 760 |
|
| 761 |
|
| 762 |
if (isset($elements['#maxlength']) && drupal_strlen($elements['#value']) > $elements['#maxlength']) {
|
| 763 |
form_error($elements, $t('!name cannot be longer than %max characters but is currently %length characters long.', array('!name' => empty($elements['#title']) ? $elements['#parents'][0] : $elements['#title'], '%max' => $elements['#maxlength'], '%length' => drupal_strlen($elements['#value']))));
|
| 764 |
}
|
| 765 |
|
| 766 |
if (isset($elements['#options']) && isset($elements['#value'])) {
|
| 767 |
if ($elements['#type'] == 'select') {
|
| 768 |
$options = form_options_flatten($elements['#options']);
|
| 769 |
}
|
| 770 |
|
| 771 |
$options = $elements['#options'];
|
| 772 |
|
| 773 |
if (is_array($elements['#value'])) {
|
| 774 |
$value = $elements['#type'] == 'checkboxes' ? array_keys(array_filter($elements['#value'])) : $elements['#value'];
|
| 775 |
foreach ($value as $v) {
|
| 776 |
if (!isset($options[$v])) {
|
| 777 |
form_error($elements, $t('An illegal choice has been detected. Please contact the site administrator.'));
|
| 778 |
watchdog('form', 'Illegal choice %choice in !name element.', array('%choice' => $v, '!name' => empty($elements['#title']) ? $elements['#parents'][0] : $elements['#title']), WATCHDOG_ERROR);
|
| 779 |
}
|
| 780 |
}
|
| 781 |
}
|
| 782 |
elseif (!isset($options[$elements['#value']])) {
|
| 783 |
form_error($elements, $t('An illegal choice has been detected. Please contact the site administrator.'));
|
| 784 |
watchdog('form', 'Illegal choice %choice in %name element.', array('%choice' => $elements['#value'], '%name' => empty($elements['#title']) ? $elements['#parents'][0] : $elements['#title']), WATCHDOG_ERROR);
|
| 785 |
}
|
| 786 |
}
|
| 787 |
}
|
| 788 |
|
| 789 |
|
| 790 |
if (isset($form_id)) {
|
| 791 |
form_execute_handlers('validate', $elements, $form_state);
|
| 792 |
}
|
| 793 |
|
| 794 |
|
| 795 |
elseif (isset($elements['#element_validate'])) {
|
| 796 |
foreach ($elements['#element_validate'] as $function) {
|
| 797 |
if (drupal_function_exists($function)) {
|
| 798 |
$function($elements, $form_state, $form_state['complete form']);
|
| 799 |
}
|
| 800 |
}
|
| 801 |
}
|
| 802 |
$elements['#validated'] = TRUE;
|
| 803 |
}
|
| 804 |
}
|
| 805 |
|
| 806 |
|
| 807 |
|
| 808 |
|
| 809 |
|
| 810 |
|
| 811 |
|
| 812 |
|
| 813 |
|
| 814 |
|
| 815 |
|
| 816 |
|
| 817 |
|
| 818 |
|
| 819 |
|
| 820 |
|
| 821 |
function form_execute_handlers($type, &$form, &$form_state) {
|
| 822 |
$return = FALSE;
|
| 823 |
if (isset($form_state[$type . '_handlers'])) {
|
| 824 |
$handlers = $form_state[$type . '_handlers'];
|
| 825 |
}
|
| 826 |
elseif (isset($form['#' . $type])) {
|
| 827 |
$handlers = $form['#' . $type];
|
| 828 |
}
|
| 829 |
|
| 830 |
$handlers = array();
|
| 831 |
|
| 832 |
|
| 833 |
foreach ($handlers as $function) {
|
| 834 |
if (drupal_function_exists($function)) {
|
| 835 |
|
| 836 |
|
| 837 |
|
| 838 |
if ($type == 'submit' && ($batch =& batch_get()) && !isset($batch['current_set'])) {
|
| 839 |
|
| 840 |
|
| 841 |
|
| 842 |
$batch['sets'][] = array('form_submit' => $function);
|
| 843 |
}
|
| 844 |
|
| 845 |
$function($form, $form_state);
|
| 846 |
|
| 847 |
$return = TRUE;
|
| 848 |
}
|
| 849 |
}
|
| 850 |
return $return;
|
| 851 |
}
|
| 852 |
|
| 853 |
|
| 854 |
|
| 855 |
|
| 856 |
|
| 857 |
|
| 858 |
|
| 859 |
|
| 860 |
|
| 861 |
|
| 862 |
|
| 863 |
|
| 864 |
|
| 865 |
|
| 866 |
|
| 867 |
|
| 868 |
|
| 869 |
function form_set_error($name = NULL, $message = '') {
|
| 870 |
$form = &drupal_static(__FUNCTION__, array());
|
| 871 |
if (isset($name) && !isset($form[$name])) {
|
| 872 |
$form[$name] = $message;
|
| 873 |
if ($message) {
|
| 874 |
drupal_set_message($message, 'error');
|
| 875 |
}
|
| 876 |
}
|
| 877 |
return $form;
|
| 878 |
}
|
| 879 |
|
| 880 |
|
| 881 |
|
| 882 |
|
| 883 |
function form_clear_error() {
|
| 884 |
drupal_static_reset('form_set_error');
|
| 885 |
}
|
| 886 |
|
| 887 |
|
| 888 |
|
| 889 |
|
| 890 |
function form_get_errors() {
|
| 891 |
$form = form_set_error();
|
| 892 |
if (!empty($form)) {
|
| 893 |
return $form;
|
| 894 |
}
|
| 895 |
}
|
| 896 |
|
| 897 |
|
| 898 |
|
| 899 |
|
| 900 |
function form_get_error($element) {
|
| 901 |
$form = form_set_error();
|
| 902 |
$key = $element['#parents'][0];
|
| 903 |
if (isset($form[$key])) {
|
| 904 |
return $form[$key];
|
| 905 |
}
|
| 906 |
$key = implode('][', $element['#parents']);
|
| 907 |
if (isset($form[$key])) {
|
| 908 |
return $form[$key];
|
| 909 |
}
|
| 910 |
}
|
| 911 |
|
| 912 |
|
| 913 |
|
| 914 |
|
| 915 |
function form_error(&$element, $message = '') {
|
| 916 |
form_set_error(implode('][', $element['#parents']), $message);
|
| 917 |
}
|
| 918 |
|
| 919 |
|
| 920 |
|
| 921 |
|
| 922 |
|
| 923 |
|
| 924 |
|
| 925 |
|
| 926 |
|
| 927 |
|
| 928 |
|
| 929 |
|
| 930 |
|
| 931 |
|
| 932 |
|
| 933 |
|
| 934 |
|
| 935 |
|
| 936 |
function form_builder($form_id, $element, &$form_state) {
|
| 937 |
|
| 938 |
$element['#processed'] = FALSE;
|
| 939 |
|
| 940 |
|
| 941 |
if ((!empty($element['#type'])) && ($info = element_info($element['#type']))) {
|
| 942 |
|
| 943 |
$element += $info;
|
| 944 |
$element['#defaults_loaded'] = TRUE;
|
| 945 |
}
|
| 946 |
|
| 947 |
|
| 948 |
if (isset($element['#type']) && $element['#type'] == 'form') {
|
| 949 |
|
| 950 |
$form_state['complete form'] = $element;
|
| 951 |
|
| 952 |
|
| 953 |
|
| 954 |
if ($form_state['programmed'] || (!empty($form_state['input']) && (isset($form_state['input']['form_id']) && ($form_state['input']['form_id'] == $form_id)))) {
|
| 955 |
$form_state['process_input'] = TRUE;
|
| 956 |
}
|
| 957 |
|
| 958 |
$form_state['process_input'] = FALSE;
|
| 959 |
|
| 960 |
}
|
| 961 |
|
| 962 |
if (!isset($element['#id'])) {
|
| 963 |
$element['#id'] = form_clean_id('edit-' . implode('-', $element['#parents']));
|
| 964 |
}
|
| 965 |
|
| 966 |
if (!empty($element['#input'])) {
|
| 967 |
_form_builder_handle_input_element($form_id, $element, $form_state);
|
| 968 |
}
|
| 969 |
|
| 970 |
|
| 971 |
if (isset($element['#process']) && !$element['#processed']) {
|
| 972 |
foreach ($element['#process'] as $process) {
|
| 973 |
if (drupal_function_exists($process)) {
|
| 974 |
$element = $process($element, $form_state, $form_state['complete form']);
|
| 975 |
}
|
| 976 |
}
|
| 977 |
$element['#processed'] = TRUE;
|
| 978 |
}
|
| 979 |
|
| 980 |
|
| 981 |
$element['#sorted'] = TRUE;
|
| 982 |
|
| 983 |
|
| 984 |
$count = 0;
|
| 985 |
foreach (element_children($element) as $key) {
|
| 986 |
|
| 987 |
if (!isset($element[$key]['#tree'])) {
|
| 988 |
$element[$key]['#tree'] = $element['#tree'];
|
| 989 |
}
|
| 990 |
|
| 991 |
|
| 992 |
if (isset($element['#access']) && !$element['#access']) {
|
| 993 |
$element[$key]['#access'] = FALSE;
|
| 994 |
}
|
| 995 |
|
| 996 |
|
| 997 |
if (!isset($element[$key]['#parents'])) {
|
| 998 |
|
| 999 |
|
| 1000 |
$element[$key]['#parents'] = $element[$key]['#tree'] && $element['#tree'] ? array_merge($element['#parents'], array($key)) : array($key);
|
| 1001 |
$array_parents = isset($element['#array_parents']) ? $element['#array_parents'] : array();
|
| 1002 |
$array_parents[] = $key;
|
| 1003 |
$element[$key]['#array_parents'] = $array_parents;
|
| 1004 |
}
|
| 1005 |
|
| 1006 |
|
| 1007 |
if (!isset($element[$key]['#weight'])) {
|
| 1008 |
$element[$key]['#weight'] = $count/1000;
|
| 1009 |
}
|
| 1010 |
|
| 1011 |
|
| 1012 |
|
| 1013 |
unset($element['#sorted']);
|
| 1014 |
|
| 1015 |
$element[$key] = form_builder($form_id, $element[$key], $form_state);
|
| 1016 |
$count++;
|
| 1017 |
}
|
| 1018 |
|
| 1019 |
|
| 1020 |
|
| 1021 |
if (isset($element['#after_build']) && !isset($element['#after_build_done'])) {
|
| 1022 |
foreach ($element['#after_build'] as $function) {
|
| 1023 |
$element = $function($element, $form_state);
|
| 1024 |
$element['#after_build_done'] = TRUE;
|
| 1025 |
}
|
| 1026 |
}
|
| 1027 |
|
| 1028 |
|
| 1029 |
|
| 1030 |
_form_builder_ie_cleanup($element, $form_state);
|
| 1031 |
|
| 1032 |
|
| 1033 |
|
| 1034 |
|
| 1035 |
|
| 1036 |
if (!empty($form_state['submitted'])) {
|
| 1037 |
unset($form_state['buttons']);
|
| 1038 |
}
|
| 1039 |
|
| 1040 |
|
| 1041 |
|
| 1042 |
if (!empty($element['#cache'])) {
|
| 1043 |
$form_state['cache'] = $element['#cache'];
|
| 1044 |
}
|
| 1045 |
|
| 1046 |
|
| 1047 |
|
| 1048 |
if (isset($element['#type']) && $element['#type'] == 'file') {
|
| 1049 |
$form_state['has_file_element'] = TRUE;
|
| 1050 |
}
|
| 1051 |
|
| 1052 |
if (isset($element['#type']) && $element['#type'] == 'form') {
|
| 1053 |
|
| 1054 |
|
| 1055 |
if (isset($form_state['has_file_element'])) {
|
| 1056 |
$element['#attributes']['enctype'] = 'multipart/form-data';
|
| 1057 |
}
|
| 1058 |
|
| 1059 |
$form_state['complete form'] = $element;
|
| 1060 |
}
|
| 1061 |
return $element;
|
| 1062 |
}
|
| 1063 |
|
| 1064 |
|
| 1065 |
|
| 1066 |
|
| 1067 |
|
| 1068 |
function _form_builder_handle_input_element($form_id, &$element, &$form_state) {
|
| 1069 |
if (!isset($element['#name'])) {
|
| 1070 |
$name = array_shift($element['#parents']);
|
| 1071 |
$element['#name'] = $name;
|
| 1072 |
if ($element['#type'] == 'file') {
|
| 1073 |
|
| 1074 |
|
| 1075 |
|
| 1076 |
$element['#name'] = 'files[' . $element['#name'] . ']';
|
| 1077 |
}
|
| 1078 |
elseif (count($element['#parents'])) {
|
| 1079 |
$element['#name'] .= '[' . implode('][', $element['#parents']) . ']';
|
| 1080 |
}
|
| 1081 |
array_unshift($element['#parents'], $name);
|
| 1082 |
}
|
| 1083 |
|
| 1084 |
if (!empty($element['#disabled'])) {
|
| 1085 |
$element['#attributes']['disabled'] = 'disabled';
|
| 1086 |
}
|
| 1087 |
|
| 1088 |
|
| 1089 |
if (!isset($element['#value']) && !array_key_exists('#value', $element)) {
|
| 1090 |
$value_callback = !empty($element['#value_callback']) ? $element['#value_callback'] : 'form_type_' . $element['#type'] . '_value';
|
| 1091 |
|
| 1092 |
if ($form_state['programmed'] || ($form_state['process_input'] && (!isset($element['#access']) || $element['#access']))) {
|
| 1093 |
$input = $form_state['input'];
|
| 1094 |
foreach ($element['#parents'] as $parent) {
|
| 1095 |
$input = isset($input[$parent]) ? $input[$parent] : NULL;
|
| 1096 |
}
|
| 1097 |
|
| 1098 |
if (!$form_state['programmed'] || isset($input)) {
|
| 1099 |
|
| 1100 |
if (drupal_function_exists($value_callback)) {
|
| 1101 |
$element['#value'] = $value_callback($element, $input, $form_state);
|
| 1102 |
}
|
| 1103 |
if (!isset($element['#value']) && isset($input)) {
|
| 1104 |
$element['#value'] = $input;
|
| 1105 |
}
|
| 1106 |
}
|
| 1107 |
|
| 1108 |
if (isset($element['#value']) || (!empty($element['#required']))) {
|
| 1109 |
$element['#needs_validation'] = TRUE;
|
| 1110 |
}
|
| 1111 |
}
|
| 1112 |
|
| 1113 |
if (!isset($element['#value'])) {
|
| 1114 |
|
| 1115 |
if (drupal_function_exists($value_callback)) {
|
| 1116 |
$element['#value'] = $value_callback($element, FALSE, $form_state);
|
| 1117 |
}
|
| 1118 |
|
| 1119 |
|
| 1120 |
|
| 1121 |
if (!isset($element['#value']) && empty($element['#has_garbage_value'])) {
|
| 1122 |
$element['#value'] = isset($element['#default_value']) ? $element['#default_value'] : '';
|
| 1123 |
}
|
| 1124 |
}
|
| 1125 |
}
|
| 1126 |
|
| 1127 |
|
| 1128 |
|
| 1129 |
|
| 1130 |
|
| 1131 |
if (!empty($form_state['input']) && isset($element['#executes_submit_callback'])) {
|
| 1132 |
|
| 1133 |
|
| 1134 |
$button_type = $element['#executes_submit_callback'] ? 'submit' : 'button';
|
| 1135 |
$form_state['buttons'][$button_type][] = $element;
|
| 1136 |
|
| 1137 |
if (_form_button_was_clicked($element, $form_state)) {
|
| 1138 |
$form_state['submitted'] = $form_state['submitted'] || $element['#executes_submit_callback'];
|
| 1139 |
|
| 1140 |
|
| 1141 |
|
| 1142 |
|
| 1143 |
$form_state['values'][$element['#name']] = $element['#value'];
|
| 1144 |
$form_state['clicked_button'] = $element;
|
| 1145 |
|
| 1146 |
if (isset($element['#validate'])) {
|
| 1147 |
$form_state['validate_handlers'] = $element['#validate'];
|
| 1148 |
}
|
| 1149 |
if (isset($element['#submit'])) {
|
| 1150 |
$form_state['submit_handlers'] = $element['#submit'];
|
| 1151 |
}
|
| 1152 |
}
|
| 1153 |
}
|
| 1154 |
form_set_value($element, $element['#value'], $form_state);
|
| 1155 |
}
|
| 1156 |
|
| 1157 |
|
| 1158 |
|
| 1159 |
|
| 1160 |
|
| 1161 |
|
| 1162 |
|
| 1163 |
|
| 1164 |
|
| 1165 |
|
| 1166 |
function _form_button_was_clicked($form, &$form_state) {
|
| 1167 |
|
| 1168 |
|
| 1169 |
|
| 1170 |
|
| 1171 |
|
| 1172 |
if (isset($form_state['input'][$form['#name']]) && $form_state['input'][$form['#name']] == $form['#value']) {
|
| 1173 |
return TRUE;
|
| 1174 |
}
|
| 1175 |
|
| 1176 |
|
| 1177 |
|
| 1178 |
|
| 1179 |
|
| 1180 |
elseif (!empty($form['#has_garbage_value']) && isset($form['#value']) && $form['#value'] !== '') {
|
| 1181 |
return TRUE;
|
| 1182 |
}
|
| 1183 |
return FALSE;
|
| 1184 |
}
|
| 1185 |
|
| 1186 |
|
| 1187 |
|
| 1188 |
|
| 1189 |
|
| 1190 |
|
| 1191 |
|
| 1192 |
|
| 1193 |
|
| 1194 |
function _form_builder_ie_cleanup($form, &$form_state) {
|
| 1195 |
|
| 1196 |
|
| 1197 |
if (!empty($form['#type']) && $form['#type'] == 'form') {
|
| 1198 |
|
| 1199 |
|
| 1200 |
|
| 1201 |
if (empty($form_state['submitted']) && !empty($form_state['buttons']['submit']) && empty($form_state['buttons']['button'])) {
|
| 1202 |
$button = $form_state['buttons']['submit'][0];
|
| 1203 |
|
| 1204 |
|
| 1205 |
|
| 1206 |
$form_state['submitted'] = TRUE;
|
| 1207 |
$form_state['submit_handlers'] = empty($button['#submit']) ? NULL : $button['#submit'];
|
| 1208 |
$form_state['validate_handlers'] = empty($button['#validate']) ? NULL : $button['#validate'];
|
| 1209 |
$form_state['values'][$button['#name']] = $button['#value'];
|
| 1210 |
$form_state['clicked_button'] = $button;
|
| 1211 |
}
|
| 1212 |
}
|
| 1213 |
}
|
| 1214 |
|
| 1215 |
|
| 1216 |
|
| 1217 |
|
| 1218 |
|
| 1219 |
|
| 1220 |
|
| 1221 |
|
| 1222 |
|
| 1223 |
|
| 1224 |
|
| 1225 |
|
| 1226 |
|
| 1227 |
|
| 1228 |
|
| 1229 |
function form_type_image_button_value($form, $input, $form_state) {
|
| 1230 |
if ($input !== FALSE) {
|
| 1231 |
if (!empty($input)) {
|
| 1232 |
|
| 1233 |
|
| 1234 |
return $form['#return_value'];
|
| 1235 |
}
|
| 1236 |
|
| 1237 |
|
| 1238 |
|
| 1239 |
|
| 1240 |
|
| 1241 |
|
| 1242 |
$input = $form_state['input'];
|
| 1243 |
foreach (explode('[', $form['#name']) as $element_name) {
|
| 1244 |
|
| 1245 |
if (substr($element_name, -1) == ']') {
|
| 1246 |
$element_name = substr($element_name, 0, -1);
|
| 1247 |
}
|
| 1248 |
|
| 1249 |
if (!isset($input[$element_name])) {
|
| 1250 |
if (isset($input[$element_name . '_x'])) {
|
| 1251 |
return $form['#return_value'];
|
| 1252 |
}
|
| 1253 |
return NULL;
|
| 1254 |
}
|
| 1255 |
$input = $input[$element_name];
|
| 1256 |
}
|
| 1257 |
return $form['#return_value'];
|
| 1258 |
|
| 1259 |
}
|
| 1260 |
}
|
| 1261 |
|
| 1262 |
|
| 1263 |
|
| 1264 |
|
| 1265 |
|
| 1266 |
|
| 1267 |
|
| 1268 |
|
| 1269 |
|
| 1270 |
|
| 1271 |
|
| 1272 |
|
| 1273 |
|
| 1274 |
function form_type_checkbox_value($element, $input = FALSE) {
|
| 1275 |
if ($input !== FALSE) {
|
| 1276 |
if (empty($element['#disabled'])) {
|
| 1277 |
return !empty($input) ? $element['#return_value'] : 0;
|
| 1278 |
}
|
| 1279 |
|
| 1280 |
return $element['#default_value'];
|
| 1281 |
|
| 1282 |
}
|
| 1283 |
}
|
| 1284 |
|
| 1285 |
|
| 1286 |
|
| 1287 |
|
| 1288 |
|
| 1289 |
|
| 1290 |
|
| 1291 |
|
| 1292 |
|
| 1293 |
|
| 1294 |
|
| 1295 |
|
| 1296 |
|
| 1297 |
function form_type_checkboxes_value($element, $input = FALSE) {
|
| 1298 |
if ($input === FALSE) {
|
| 1299 |
$value = array();
|
| 1300 |
$element += array('#default_value' => array());
|
| 1301 |
foreach ($element['#default_value'] as $key) {
|
| 1302 |
$value[$key] = 1;
|
| 1303 |
}
|
| 1304 |
return $value;
|
| 1305 |
}
|
| 1306 |
elseif (!isset($input)) {
|
| 1307 |
return array();
|
| 1308 |
}
|
| 1309 |
}
|
| 1310 |
|
| 1311 |
|
| 1312 |
|
| 1313 |
|
| 1314 |
|
| 1315 |
|
| 1316 |
|
| 1317 |
|
| 1318 |
|
| 1319 |
|
| 1320 |
|
| 1321 |
|
| 1322 |
|
| 1323 |
|
| 1324 |
function form_type_password_confirm_value($element, $input = FALSE) {
|
| 1325 |
if ($input === FALSE) {
|
| 1326 |
$element += array('#default_value' => array());
|
| 1327 |
return $element['#default_value'] + array('pass1' => '', 'pass2' => '');
|
| 1328 |
}
|
| 1329 |
}
|
| 1330 |
|
| 1331 |
|
| 1332 |
|
| 1333 |
|
| 1334 |
|
| 1335 |
|
| 1336 |
|
| 1337 |
|
| 1338 |
|
| 1339 |
|
| 1340 |
|
| 1341 |
|
| 1342 |
|
| 1343 |
function form_type_select_value($element, $input = FALSE) {
|
| 1344 |
if ($input !== FALSE) {
|
| 1345 |
if (isset($element['#multiple']) && $element['#multiple']) {
|
| 1346 |
return (is_array($input)) ? drupal_map_assoc($input) : array();
|
| 1347 |
}
|
| 1348 |
|
| 1349 |
return $input;
|
| 1350 |
|
| 1351 |
}
|
| 1352 |
}
|
| 1353 |
|
| 1354 |
|
| 1355 |
|
| 1356 |
|
| 1357 |
|
| 1358 |
|
| 1359 |
|
| 1360 |
|
| 1361 |
|
| 1362 |
|
| 1363 |
|
| 1364 |
|
| 1365 |
|
| 1366 |
function form_type_textfield_value($element, $input = FALSE) {
|
| 1367 |
if ($input !== FALSE) {
|
| 1368 |
|
| 1369 |
|
| 1370 |
return str_replace(array("\r", "\n"), '', $input);
|
| 1371 |
}
|
| 1372 |
}
|
| 1373 |
|
| 1374 |
|
| 1375 |
|
| 1376 |
|
| 1377 |
|
| 1378 |
|
| 1379 |
|
| 1380 |
|
| 1381 |
|
| 1382 |
|
| 1383 |
|
| 1384 |
|
| 1385 |
|
| 1386 |
function form_type_token_value($element, $input = FALSE) {
|
| 1387 |
if ($input !== FALSE) {
|
| 1388 |
return (string)$input;
|
| 1389 |
}
|
| 1390 |
}
|
| 1391 |
|
| 1392 |
|
| 1393 |
|
| 1394 |
|
| 1395 |
|
| 1396 |
|
| 1397 |
|
| 1398 |
|
| 1399 |
|
| 1400 |
|
| 1401 |
|
| 1402 |
|
| 1403 |
|
| 1404 |
|
| 1405 |
|
| 1406 |
|
| 1407 |
|
| 1408 |
|
| 1409 |
|
| 1410 |
|
| 1411 |
|
| 1412 |
|
| 1413 |
|
| 1414 |
|
| 1415 |
function form_set_value($element, $value, &$form_state) {
|
| 1416 |
_form_set_value($form_state['values'], $element, $element['#parents'], $value);
|
| 1417 |
}
|
| 1418 |
|
| 1419 |
|
| 1420 |
|
| 1421 |
|
| 1422 |
|
| 1423 |
|
| 1424 |
|
| 1425 |
|
| 1426 |
function _form_set_value(&$form_values, $element, $parents, $value) {
|
| 1427 |
$parent = array_shift($parents);
|
| 1428 |
if (empty($parents)) {
|
| 1429 |
$form_values[$parent] = $value;
|
| 1430 |
}
|
| 1431 |
|
| 1432 |
if (!isset($form_values[$parent])) {
|
| 1433 |
$form_values[$parent] = array();
|
| 1434 |
}
|
| 1435 |
_form_set_value($form_values[$parent], $element, $parents, $value);
|
| 1436 |
|
| 1437 |
}
|
| 1438 |
|
| 1439 |
function form_options_flatten($array, $reset = TRUE) {
|
| 1440 |
|
| 1441 |
|
| 1442 |
static $return;
|
| 1443 |
|
| 1444 |
if ($reset) {
|
| 1445 |
$return = array();
|
| 1446 |
}
|
| 1447 |
|
| 1448 |
foreach ($array as $key => $value) {
|
| 1449 |
if (is_object($value)) {
|
| 1450 |
form_options_flatten($value->option, FALSE);
|
| 1451 |
}
|
| 1452 |
elseif (is_array($value)) {
|
| 1453 |
form_options_flatten($value, FALSE);
|
| 1454 |
}
|
| 1455 |
|
| 1456 |
$return[$key] = 1;
|
| 1457 |
|
| 1458 |
}
|
| 1459 |
|
| 1460 |
return $return;
|
| 1461 |
}
|
| 1462 |
|
| 1463 |
|
| 1464 |
|
| 1465 |
|
| 1466 |
|
| 1467 |
|
| 1468 |
|
| 1469 |
|
| 1470 |
|
| 1471 |
|
| 1472 |
|
| 1473 |
|
| 1474 |
|
| 1475 |
|
| 1476 |
|
| 1477 |
|
| 1478 |
function theme_select($element) {
|
| 1479 |
$select = '';
|
| 1480 |
$size = $element['#size'] ? ' size="' . $element['#size'] . '"' : '';
|
| 1481 |
_form_set_class($element, array('form-select'));
|
| 1482 |
$multiple = $element['#multiple'];
|
| 1483 |
return '<select name="' . $element['#name'] . '' . ($multiple ? '[]' : '') . '"' . ($multiple ? ' multiple="multiple" ' : '') . drupal_attributes($element['#attributes']) . ' id="' . $element['#id'] . '" ' . $size . '>' . form_select_options($element) . '</select>';
|
| 1484 |
}
|
| 1485 |
|
| 1486 |
function form_select_options($element, $choices = NULL) {
|
| 1487 |
if (!isset($choices)) {
|
| 1488 |
$choices = $element['#options'];
|
| 1489 |
}
|
| 1490 |
|
| 1491 |
|
| 1492 |
$value_valid = isset($element['#value']) || array_key_exists('#value', $element);
|
| 1493 |
$value_is_array = is_array($element['#value']);
|
| 1494 |
$options = '';
|
| 1495 |
foreach ($choices as $key => $choice) {
|
| 1496 |
if (is_array($choice)) {
|
| 1497 |
$options .= '<optgroup label="' . $key . '">';
|
| 1498 |
$options .= form_select_options($element, $choice);
|
| 1499 |
$options .= '</optgroup>';
|
| 1500 |
}
|
| 1501 |
elseif (is_object($choice)) {
|
| 1502 |
$options .= form_select_options($element, $choice->option);
|
| 1503 |
}
|
| 1504 |
|
| 1505 |
$key = (string)$key;
|
| 1506 |
if ($value_valid && (!$value_is_array && (string)$element['#value'] === $key || ($value_is_array && in_array($key, $element['#value'])))) {
|
| 1507 |
$selected = ' selected="selected"';
|
| 1508 |
}
|
| 1509 |
|
| 1510 |
$selected = '';
|
| 1511 |
|
| 1512 |
$options .= '<option value="' . check_plain($key) . '"' . $selected . '>' . check_plain($choice) . '</option>';
|
| 1513 |
|
| 1514 |
}
|
| 1515 |
return $options;
|
| 1516 |
}
|
| 1517 |
|
| 1518 |
|
| 1519 |
|
| 1520 |
|
| 1521 |
|
| 1522 |
|
| 1523 |
|
| 1524 |
|
| 1525 |
|
| 1526 |
|
| 1527 |
|
| 1528 |
|
| 1529 |
|
| 1530 |
|
| 1531 |
|
| 1532 |
|
| 1533 |
|
| 1534 |
|
| 1535 |
|
| 1536 |
|
| 1537 |
|
| 1538 |
|
| 1539 |
|
| 1540 |
|
| 1541 |
|
| 1542 |
|
| 1543 |
|
| 1544 |
|
| 1545 |
|
| 1546 |
|
| 1547 |
|
| 1548 |
|
| 1549 |
|
| 1550 |
function form_get_options($element, $key) {
|
| 1551 |
$keys = array();
|
| 1552 |
foreach ($element['#options'] as $index => $choice) {
|
| 1553 |
if (is_array($choice)) {
|
| 1554 |
return FALSE;
|
| 1555 |
}
|
| 1556 |
elseif (is_object($choice)) {
|
| 1557 |
if (isset($choice->option[$key])) {
|
| 1558 |
$keys[] = $index;
|
| 1559 |
}
|
| 1560 |
}
|
| 1561 |
elseif ($index == $key) {
|
| 1562 |
$keys[] = $index;
|
| 1563 |
}
|
| 1564 |
}
|
| 1565 |
return $keys;
|
| 1566 |
}
|
| 1567 |
|
| 1568 |
|
| 1569 |
|
| 1570 |
|
| 1571 |
|
| 1572 |
|
| 1573 |
|
| 1574 |
|
| 1575 |
|
| 1576 |
|
| 1577 |
|
| 1578 |
|
| 1579 |
|
| 1580 |
function theme_fieldset($element) {
|
| 1581 |
if (!empty($element['#collapsible'])) {
|
| 1582 |
drupal_add_js('misc/collapse.js');
|
| 1583 |
|
| 1584 |
if (!isset($element['#attributes']['class'])) {
|
| 1585 |
$element['#attributes']['class'] = '';
|
| 1586 |
}
|
| 1587 |
|
| 1588 |
$element['#attributes']['class'] .= ' collapsible';
|
| 1589 |
if (!empty($element['#collapsed'])) {
|
| 1590 |
$element['#attributes']['class'] .= ' collapsed';
|
| 1591 |
}
|
| 1592 |
}
|
| 1593 |
$element['#attributes']['id'] = $element['#id'];
|
| 1594 |
|
| 1595 |
return '<fieldset' . drupal_attributes($element['#attributes']) . '>' . ($element['#title'] ? '<legend>' . $element['#title'] . '</legend>' : '') . (isset($element['#description']) && $element['#description'] ? '<div class="fieldset-description">' . $element['#description'] . '</div>' : '') . (!empty($element['#children']) ? $element['#children'] : '') . (isset($element['#value']) ? $element['#value'] : '') . "</fieldset>\n";
|
| 1596 |
}
|
| 1597 |
|
| 1598 |
|
| 1599 |
|
| 1600 |
|
| 1601 |
|
| 1602 |
|
| 1603 |
|
| 1604 |
|
| 1605 |
|
| 1606 |
|
| 1607 |
|
| 1608 |
|
| 1609 |
function theme_radio($element) {
|
| 1610 |
_form_set_class($element, array('form-radio'));
|
| 1611 |
$output = '<input type="radio" ';
|
| 1612 |
$output .= 'id="' . $element['#id'] . '" ';
|
| 1613 |
$output .= 'name="' . $element['#name'] . '" ';
|
| 1614 |
$output .= 'value="' . $element['#return_value'] . '" ';
|
| 1615 |
$output .= (check_plain($element['#value']) == $element['#return_value']) ? ' checked="checked" ' : ' ';
|
| 1616 |
$output .= drupal_attributes($element['#attributes']) . ' />';
|
| 1617 |
if (!is_null($element['#title'])) {
|
| 1618 |
$output = '<label class="option" for="' . $element['#id'] . '">' . $output . ' ' . $element['#title'] . '</label>';
|
| 1619 |
}
|
| 1620 |
|
| 1621 |
return $output;
|
| 1622 |
}
|
| 1623 |
|
| 1624 |
|
| 1625 |
|
| 1626 |
|
| 1627 |
|
| 1628 |
|
| 1629 |
|
| 1630 |
|
| 1631 |
|
| 1632 |
|
| 1633 |
|
| 1634 |
|
| 1635 |
function theme_radios($element) {
|
| 1636 |
$class = 'form-radios';
|
| 1637 |
if (isset($element['#attributes']['class'])) {
|
| 1638 |
$class .= ' ' . $element['#attributes']['class'];
|
| 1639 |
}
|
| 1640 |
$element['#children'] = '<div class="' . $class . '">' . (!empty($element['#children']) ? $element['#children'] : '') . '</div>';
|
| 1641 |
|
| 1642 |
return $element['#children'];
|
| 1643 |
}
|
| 1644 |
|
| 1645 |
|
| 1646 |
|
| 1647 |
|
| 1648 |
function form_process_password_confirm($element) {
|
| 1649 |
$element['pass1'] = array(
|
| 1650 |
'#type' => 'password',
|
| 1651 |
'#title' => t('Password'),
|
| 1652 |
'#value' => empty($element['#value']) ? NULL : $element['#value']['pass1'],
|
| 1653 |
'#required' => $element['#required'],
|
| 1654 |
'#attributes' => array('class' => 'password-field'),
|
| 1655 |
|
| 1656 |
$element['pass2'] = array(
|
| 1657 |
'#type' => 'password',
|
| 1658 |
'#title' => t('Confirm password'),
|
| 1659 |
'#value' => empty($element['#value']) ? NULL : $element['#value']['pass2'],
|
| 1660 |
'#required' => $element['#required'],
|
| 1661 |
'#attributes' => array('class' => 'password-confirm'),
|
| 1662 |
|
| 1663 |
$element['#element_validate'] = array('password_confirm_validate');
|
| 1664 |
$element['#tree'] = TRUE;
|
| 1665 |
|
| 1666 |
if (isset($element['#size'])) {
|
| 1667 |
$element['pass1']['#size'] = $element['pass2']['#size'] = $element['#size'];
|
| 1668 |
}
|
| 1669 |
|
| 1670 |
return $element;
|
| 1671 |
}
|
| 1672 |
|
| 1673 |
|
| 1674 |
|
| 1675 |
|
| 1676 |
function password_confirm_validate($element, &$element_state) {
|
| 1677 |
$pass1 = trim($element['pass1']['#value']);
|
| 1678 |
if (!empty($pass1)) {
|
| 1679 |
$pass2 = trim($element['pass2']['#value']);
|
| 1680 |
if (strcmp($pass1, $pass2)) {
|
| 1681 |
form_error($element, t('The specified passwords do not match.'));
|
| 1682 |
}
|
| 1683 |
}
|
| 1684 |
elseif ($element['#required'] && !empty($element_state['input'])) {
|
| 1685 |
form_error($element, t('Password field is required.'));
|
| 1686 |
}
|
| 1687 |
|
| 1688 |
|
| 1689 |
|
| 1690 |
form_set_value($element['pass1'], NULL, $element_state);
|
| 1691 |
form_set_value($element['pass2'], NULL, $element_state);
|
| 1692 |
form_set_value($element, $pass1, $element_state);
|
| 1693 |
|
| 1694 |
return $element;
|
| 1695 |
|
| 1696 |
}
|
| 1697 |
|
| 1698 |
|
| 1699 |
|
| 1700 |
|
| 1701 |
|
| 1702 |
|
| 1703 |
|
| 1704 |
|
| 1705 |
|
| 1706 |
|
| 1707 |
|
| 1708 |
|
| 1709 |
function theme_date($element) {
|
| 1710 |
return '<div class="container-inline">' . drupal_render_children($element) . '</div>';
|
| 1711 |
}
|
| 1712 |
|
| 1713 |
|
| 1714 |
|
| 1715 |
|
| 1716 |
function form_process_date($element) {
|
| 1717 |
|
| 1718 |
if (empty($element['#value'])) {
|
| 1719 |
$element['#value'] = array('day' => format_date(REQUEST_TIME, 'custom', 'j'),
|
| 1720 |
'month' => format_date(REQUEST_TIME, 'custom', 'n'),
|
| 1721 |
'year' => format_date(REQUEST_TIME, 'custom', 'Y'));
|
| 1722 |
}
|
| 1723 |
|
| 1724 |
$element['#tree'] = TRUE;
|
| 1725 |
|
| 1726 |
|
| 1727 |
$format = variable_get('date_format_short', 'm/d/Y - H:i');
|
| 1728 |
$sort = array();
|
| 1729 |
$sort['day'] = max(strpos($format, 'd'), strpos($format, 'j'));
|
| 1730 |
$sort['month'] = max(strpos($format, 'm'), strpos($format, 'M'));
|
| 1731 |
$sort['year'] = strpos($format, 'Y');
|
| 1732 |
asort($sort);
|
| 1733 |
$order = array_keys($sort);
|
| 1734 |
|
| 1735 |
|
| 1736 |
foreach ($order as $type) {
|
| 1737 |
|
| 1738 |
case 'day':
|
| 1739 |
$options = drupal_map_assoc(range(1, 31));
|
| 1740 |
break;
|
| 1741 |
case 'month':
|
| 1742 |
$options = drupal_map_assoc(range(1, 12), 'map_month');
|
| 1743 |
break;
|
| 1744 |
case 'year':
|
| 1745 |
$options = drupal_map_assoc(range(1900, 2050));
|
| 1746 |
break;
|
| 1747 |
}
|
| 1748 |
$parents = $element['#parents'];
|
| 1749 |
$parents[] = $type;
|
| 1750 |
$element[$type] = array(
|
| 1751 |
'#type' => 'select',
|
| 1752 |
'#value' => $element['#value'][$type],
|
| 1753 |
'#attributes' => $element['#attributes'],
|
| 1754 |
'#options' => $options,
|
| 1755 |
|
| 1756 |
}
|
| 1757 |
|
| 1758 |
return $element;
|
| 1759 |
}
|
| 1760 |
|
| 1761 |
|
| 1762 |
|
| 1763 |
|
| 1764 |
function date_validate($form) {
|
| 1765 |
if (!checkdate($form['#value']['month'], $form['#value']['day'], $form['#value']['year'])) {
|
| 1766 |
form_error($form, t('The specified date is invalid.'));
|
| 1767 |
}
|
| 1768 |
}
|
| 1769 |
|
| 1770 |
|
| 1771 |
|
| 1772 |
|
| 1773 |
function map_month($month) {
|
| 1774 |
$months = &drupal_static(__FUNCTION__, array(
|
| 1775 |
1 => 'Jan',
|
| 1776 |
2 => 'Feb',
|
| 1777 |
3 => 'Mar',
|
| 1778 |
4 => 'Apr',
|
| 1779 |
5 => 'May',
|
| 1780 |
6 => 'Jun',
|
| 1781 |
7 => 'Jul',
|
| 1782 |
8 => 'Aug',
|
| 1783 |
9 => 'Sep',
|
| 1784 |
10 => 'Oct',
|
| 1785 |
11 => 'Nov',
|
| 1786 |
12 => 'Dec',
|
| 1787 |
));
|
| 1788 |
return t($months[$month]);
|
| 1789 |
}
|
| 1790 |
|
| 1791 |
|
| 1792 |
|
| 1793 |
|
| 1794 |
function weight_value(&$form) {
|
| 1795 |
if (isset($form['#default_value'])) {
|
| 1796 |
$form['#value'] = $form['#default_value'];
|
| 1797 |
}
|
| 1798 |
|
| 1799 |
$form['#value'] = 0;
|
| 1800 |
|
| 1801 |
}
|
| 1802 |
|
| 1803 |
|
| 1804 |
|
| 1805 |
|
| 1806 |
function form_ahah_callback() {
|
| 1807 |
$form_state = form_state_defaults();
|
| 1808 |
|
| 1809 |
$form_build_id = $_POST['form_build_id'];
|
| 1810 |
|
| 1811 |
|
| 1812 |
$form = form_get_cache($form_build_id, $form_state);
|
| 1813 |
if (!$form) {
|
| 1814 |
|
| 1815 |
|
| 1816 |
|
| 1817 |
|
| 1818 |
|
| 1819 |
exit;
|
| 1820 |
}
|
| 1821 |
|
| 1822 |
|
| 1823 |
$form['#redirect'] = FALSE;
|
| 1824 |
|
| 1825 |
|
| 1826 |
|
| 1827 |
$form_state['input'] = $_POST;
|
| 1828 |
$form_state['args'] = $form['#args'];
|
| 1829 |
$form_id = $form['#form_id'];
|
| 1830 |
|
| 1831 |
|
| 1832 |
drupal_process_form($form_id, $form, $form_state);
|
| 1833 |
|
| 1834 |
|
| 1835 |
|
| 1836 |
$form = drupal_rebuild_form($form_id, $form_state, $form_build_id);
|
| 1837 |
|
| 1838 |
|
| 1839 |
$callback = $form_state['clicked_button']['#ahah']['callback'];
|
| 1840 |
if (drupal_function_exists($callback)) {
|
| 1841 |
$callback($form, $form_state);
|
| 1842 |
}
|
| 1843 |
}
|
| 1844 |
|
| 1845 |
|
| 1846 |
|
| 1847 |
|
| 1848 |
|
| 1849 |
function form_process_radios($element) {
|
| 1850 |
if (count($element['#options']) > 0) {
|
| 1851 |
foreach ($element['#options'] as $key => $choice) {
|
| 1852 |
if (!isset($element[$key])) {
|
| 1853 |
|
| 1854 |
|
| 1855 |
$parents_for_id = array_merge($element['#parents'], array($key));
|
| 1856 |
$element[$key] = array(
|
| 1857 |
'#type' => 'radio',
|
| 1858 |
'#title' => $choice,
|
| 1859 |
'#return_value' => check_plain($key),
|
| 1860 |
'#default_value' => isset($element['#default_value']) ? $element['#default_value'] : NULL,
|
| 1861 |
'#attributes' => $element['#attributes'],
|
| 1862 |
'#parents' => $element['#parents'],
|
| 1863 |
'#id' => form_clean_id('edit-' . implode('-', $parents_for_id)),
|
| 1864 |
'#ahah' => isset($element['#ahah']) ? $element['#ahah'] : NULL,
|
| 1865 |
|
| 1866 |
}
|
| 1867 |
}
|
| 1868 |
}
|
| 1869 |
return $element;
|
| 1870 |
}
|
| 1871 |
|
| 1872 |
|
| 1873 |
|
| 1874 |
|
| 1875 |
|
| 1876 |
|
| 1877 |
|
| 1878 |
|
| 1879 |
|
| 1880 |
|
| 1881 |
|
| 1882 |
|
| 1883 |
|
| 1884 |
|
| 1885 |
|
| 1886 |
|
| 1887 |
|
| 1888 |
|
| 1889 |
|
| 1890 |
|
| 1891 |
|
| 1892 |
|
| 1893 |
|
| 1894 |
|
| 1895 |
|
| 1896 |
|
| 1897 |
|
| 1898 |
|
| 1899 |
|
| 1900 |
|
| 1901 |
|
| 1902 |
|
| 1903 |
|
| 1904 |
|
| 1905 |
|
| 1906 |
|
| 1907 |
|
| 1908 |
|
| 1909 |
|
| 1910 |
|
| 1911 |
|
| 1912 |
|
| 1913 |
|
| 1914 |
|
| 1915 |
|
| 1916 |
|
| 1917 |
|
| 1918 |
|
| 1919 |
|
| 1920 |
|
| 1921 |
|
| 1922 |
|
| 1923 |
function form_process_text_format($element) {
|
| 1924 |
if (isset($element['#text_format'])) {
|
| 1925 |
|
| 1926 |
|
| 1927 |
|
| 1928 |
$element_parents = $element['#parents'];
|
| 1929 |
$element_name = array_pop($element_parents);
|
| 1930 |
$element_parents[] = $element_name . '_format';
|
| 1931 |
|
| 1932 |
|
| 1933 |
$element['value'] = (array)$element;
|
| 1934 |
$element['value']['#weight'] = 0;
|
| 1935 |
unset($element['value']['#description']);
|
| 1936 |
$element['#type'] = 'markup';
|
| 1937 |
$element['#theme'] = NULL;
|
| 1938 |
$element['#theme_wrappers'] = array('text_format_wrapper');
|
| 1939 |
$element['format'] = filter_form($element['#text_format'], 1, $element_parents);
|
| 1940 |
|
| 1941 |
|
| 1942 |
|
| 1943 |
unset($element['value']['#text_format']);
|
| 1944 |
}
|
| 1945 |
return $element;
|
| 1946 |
}
|
| 1947 |
|
| 1948 |
|
| 1949 |
|
| 1950 |
|
| 1951 |
|
| 1952 |
|
| 1953 |
|
| 1954 |
|
| 1955 |
|
| 1956 |
|
| 1957 |
|
| 1958 |
|
| 1959 |
function theme_text_format_wrapper($element) {
|
| 1960 |
$output = '<div class="text-format-wrapper">' . "\n";
|
| 1961 |
|
| 1962 |
$output .= $element['#children'] . "\n";
|
| 1963 |
|
| 1964 |
if (!empty($element['#description'])) {
|
| 1965 |
$output .= '<div class="description">' . $element['#description'] . "</div>\n";
|
| 1966 |
}
|
| 1967 |
|
| 1968 |
$output .= "</div>\n";
|
| 1969 |
|
| 1970 |
return $output;
|
| 1971 |
}
|
| 1972 |
|
| 1973 |
|
| 1974 |
|
| 1975 |
|
| 1976 |
|
| 1977 |
|
| 1978 |
|
| 1979 |
|
| 1980 |
|
| 1981 |
|
| 1982 |
|
| 1983 |
|
| 1984 |
|
| 1985 |
|
| 1986 |
|
| 1987 |
function form_process_ahah($element) {
|
| 1988 |
$js_added = &drupal_static(__FUNCTION__, array());
|
| 1989 |
|
| 1990 |
if (isset($element['#ahah']) && !isset($element['#ahah']['event'])) {
|
| 1991 |
switch ($element['#type']) {
|
| 1992 |
case 'submit':
|
| 1993 |
case 'button':
|
| 1994 |
case 'image_button':
|
| 1995 |
|
| 1996 |
|
| 1997 |
|
| 1998 |
$element['#ahah']['event'] = 'mousedown';
|
| 1999 |
|
| 2000 |
|
| 2001 |
$element['#ahah']['keypress'] = TRUE;
|
| 2002 |
break;
|
| 2003 |
case 'password':
|
| 2004 |
case 'textfield':
|
| 2005 |
case 'textarea':
|
| 2006 |
$element['#ahah']['event'] = 'blur';
|
| 2007 |
break;
|
| 2008 |
case 'radio':
|
| 2009 |
case 'checkbox':
|
| 2010 |
case 'select':
|
| 2011 |
$element['#ahah']['event'] = 'change';
|
| 2012 |
break;
|
| 2013 |
default:
|
| 2014 |
return $element;
|
| 2015 |
}
|
| 2016 |
}
|
| 2017 |
|
| 2018 |
|
| 2019 |
|
| 2020 |
if ((isset($element['#ahah']['callback']) || isset($element['#ahah']['path'])) && isset($element['#ahah']['event']) && !isset($js_added[$element['#id']])) {
|
| 2021 |
drupal_add_library('system', 'form');
|
| 2022 |
drupal_add_js('misc/ahah.js');
|
| 2023 |
|
| 2024 |
|
| 2025 |
'url' => isset($element['#ahah']['callback']) ? url('system/ahah') : url($element['#ahah']['path']),
|
| 2026 |
'event' => $element['#ahah']['event'],
|
| 2027 |
'keypress' => empty($element['#ahah']['keypress']) ? NULL : $element['#ahah']['keypress'],
|
| 2028 |
'wrapper' => empty($element['#ahah']['wrapper']) ? NULL : $element['#ahah']['wrapper'],
|
| 2029 |
'selector' => empty($element['#ahah']['selector']) ? '#' . $element['#id'] : $element['#ahah']['selector'],
|
| 2030 |
'effect' => empty($element['#ahah']['effect']) ? 'none' : $element['#ahah']['effect'],
|
| 2031 |
'method' => empty($element['#ahah']['method']) ? 'replace' : $element['#ahah']['method'],
|
| 2032 |
'progress' => empty($element['#ahah']['progress']) ? array('type' => 'throbber') : $element['#ahah']['progress'],
|
| 2033 |
'button' => isset($element['#executes_submit_callback']) ? array($element['#name'] => $element['#value']) : FALSE,
|
| 2034 |
);
|
| 2035 |
|
| 2036 |
|
| 2037 |
if (is_string($ahah_binding['progress'])) {
|
| 2038 |
$ahah_binding['progress'] = array('type' => $ahah_binding['progress']);
|
| 2039 |
}
|
| 2040 |
|
| 2041 |
if (isset($ahah_binding['progress']['path'])) {
|
| 2042 |
$ahah_binding['progress']['url'] = url($ahah_binding['progress']['path']);
|
| 2043 |
}
|
| 2044 |
|
| 2045 |
|
| 2046 |
if ($ahah_binding['progress']['type'] == 'bar') {
|
| 2047 |
drupal_add_js('misc/progress.js', array('cache' => FALSE));
|
| 2048 |
}
|
| 2049 |
|
| 2050 |
drupal_add_js(array('ahah' => array($element['#id'] => $ahah_binding)), 'setting');
|
| 2051 |
|
| 2052 |
$js_added[$element['#id']] = TRUE;
|
| 2053 |
$element['#cache'] = TRUE;
|
| 2054 |
}
|
| 2055 |
return $element;
|
| 2056 |
}
|
| 2057 |
|
| 2058 |
|
| 2059 |
|
| 2060 |
|
| 2061 |
|
| 2062 |
|
| 2063 |
|
| 2064 |
|
| 2065 |
|
| 2066 |
|
| 2067 |
|
| 2068 |
|
| 2069 |
function theme_checkbox($element) {
|
| 2070 |
_form_set_class($element, array('form-checkbox'));
|
| 2071 |
$checkbox = '<input ';
|
| 2072 |
$checkbox .= 'type="checkbox" ';
|
| 2073 |
$checkbox .= 'name="' . $element['#name'] . '" ';
|
| 2074 |
$checkbox .= 'id="' . $element['#id'] . '" ' ;
|
| 2075 |
$checkbox .= 'value="' . $element['#return_value'] . '" ';
|
| 2076 |
$checkbox .= $element['#value'] ? ' checked="checked" ' : ' ';
|
| 2077 |
$checkbox .= drupal_attributes($element['#attributes']) . ' />';
|
| 2078 |
|
| 2079 |
if (!is_null($element['#title'])) {
|
| 2080 |
$checkbox = '<label class="option" for="' . $element['#id'] . '">' . $checkbox . ' ' . $element['#title'] . '</label>';
|
| 2081 |
}
|
| 2082 |
|
| 2083 |
return $checkbox;
|
| 2084 |
}
|
| 2085 |
|
| 2086 |
|
| 2087 |
|
| 2088 |
|
| 2089 |
|
| 2090 |
|
| 2091 |
|
| 2092 |
|
| 2093 |
|
| 2094 |
|
| 2095 |
|
| 2096 |
function theme_checkboxes($element) {
|
| 2097 |
$class = 'form-checkboxes';
|
| 2098 |
if (isset($element['#attributes']['class'])) {
|
| 2099 |
$class .= ' ' . $element['#attributes']['class'];
|
| 2100 |
}
|
| 2101 |
$element['#children'] = '<div class="' . $class . '">' . (!empty($element['#children']) ? $element['#children'] : '') . '</div>';
|
| 2102 |
|
| 2103 |
return $element['#children'];
|
| 2104 |
}
|
| 2105 |
|
| 2106 |
|
| 2107 |
|
| 2108 |
|
| 2109 |
|
| 2110 |
|
| 2111 |
function form_pre_render_conditional_form_element($element) {
|
| 2112 |
if ($element['#title'] || $element['#description']) {
|
| 2113 |
unset($element['#id']);
|
| 2114 |
$element['#theme_wrappers'][] = 'form_element';
|
| 2115 |
}
|
| 2116 |
return $element;
|
| 2117 |
}
|
| 2118 |
|
| 2119 |
function form_process_checkboxes($element) {
|
| 2120 |
$value = is_array($element['#value']) ? $element['#value'] : array();
|
| 2121 |
$element['#tree'] = TRUE;
|
| 2122 |
if (count($element['#options']) > 0) {
|
| 2123 |
if (!isset($element['#default_value']) || $element['#default_value'] == 0) {
|
| 2124 |
$element['#default_value'] = array();
|
| 2125 |
}
|
| 2126 |
foreach ($element['#options'] as $key => $choice) {
|
| 2127 |
if (!isset($element[$key])) {
|
| 2128 |
$element[$key] = array(
|
| 2129 |
'#type' => 'checkbox',
|
| 2130 |
'#processed' => TRUE,
|
| 2131 |
'#title' => $choice,
|
| 2132 |
'#return_value' => $key,
|
| 2133 |
'#default_value' => isset($value[$key]),
|
| 2134 |
'#attributes' => $element['#attributes'],
|
| 2135 |
'#ahah' => isset($element['#ahah']) ? $element['#ahah'] : NULL,
|
| 2136 |
|
| 2137 |
}
|
| 2138 |
}
|
| 2139 |
}
|
| 2140 |
return $element;
|
| 2141 |
}
|
| 2142 |
|
| 2143 |
|
| 2144 |
|
| 2145 |
|
| 2146 |
|
| 2147 |
|
| 2148 |
|
| 2149 |
|
| 2150 |
|
| 2151 |
|
| 2152 |
|
| 2153 |
|
| 2154 |
|
| 2155 |
|
| 2156 |
|
| 2157 |
|
| 2158 |
|
| 2159 |
|
| 2160 |
|
| 2161 |
|
| 2162 |
|
| 2163 |
|
| 2164 |
|
| 2165 |
|
| 2166 |
|
| 2167 |
|
| 2168 |
|
| 2169 |
|
| 2170 |
|
| 2171 |
|
| 2172 |
function theme_tableselect($element) {
|
| 2173 |
$rows = array();
|
| 2174 |
if (!empty($element['#options'])) {
|
| 2175 |
|
| 2176 |
foreach ($element['#options'] as $key => $value) {
|
| 2177 |
$row = array();
|
| 2178 |
|
| 2179 |
$row['data'] = array();
|
| 2180 |
if (isset($value['#attributes'])) {
|
| 2181 |
$row += $value['#attributes'];
|
| 2182 |
}
|
| 2183 |
|
| 2184 |
$row['data'][] = drupal_render($element[$key]);
|
| 2185 |
|
| 2186 |
|
| 2187 |
|
| 2188 |
foreach ($element['#header'] as $fieldname => $title) {
|
| 2189 |
$row['data'][] = $element['#options'][$key][$fieldname];
|
| 2190 |
}
|
| 2191 |
$rows[] = $row;
|
| 2192 |
}
|
| 2193 |
|
| 2194 |
|
| 2195 |
$first_col = $element['#js_select'] ? array(theme('table_select_header_cell')) : array('');
|
| 2196 |
$header = array_merge($first_col, $element['#header']);
|
| 2197 |
}
|
| 2198 |
|
| 2199 |
|
| 2200 |
|
| 2201 |
$header = $element['#header'];
|
| 2202 |
$rows[] = array(array('data' => $element['#empty'], 'colspan' => count($header)));
|
| 2203 |
|
| 2204 |
return theme('table', $header, $rows);
|
| 2205 |
}
|
| 2206 |
|
| 2207 |
|
| 2208 |
|
| 2209 |
|
| 2210 |
|
| 2211 |
|
| 2212 |
|
| 2213 |
|
| 2214 |
|
| 2215 |
|
| 2216 |
function form_process_tableselect($element) {
|
| 2217 |
|
| 2218 |
if ($element['#multiple']) {
|
| 2219 |
$value = is_array($element['#value']) ? $element['#value'] : array();
|
| 2220 |
}
|
| 2221 |
|
| 2222 |
|
| 2223 |
$element['#js_select'] = FALSE;
|
| 2224 |
|
| 2225 |
|
| 2226 |
$element['#tree'] = TRUE;
|
| 2227 |
|
| 2228 |
if (count($element['#options']) > 0) {
|
| 2229 |
if (!isset($element['#default_value']) || $element['#default_value'] === 0) {
|
| 2230 |
$element['#default_value'] = array();
|
| 2231 |
}
|
| 2232 |
|
| 2233 |
|
| 2234 |
uasort($element['#options'], 'element_sort');
|
| 2235 |
|
| 2236 |
|
| 2237 |
|
| 2238 |
foreach ($element['#options'] as $key => $choice) {
|
| 2239 |
|
| 2240 |
if (!isset($element[$key])) {
|
| 2241 |
if ($element['#multiple']) {
|
| 2242 |
$element[$key] = array(
|
| 2243 |
'#type' => 'checkbox',
|
| 2244 |
'#title' => '',
|
| 2245 |
'#return_value' => $key,
|
| 2246 |
'#default_value' => isset($value[$key]),
|
| 2247 |
'#attributes' => $element['#attributes'],
|
| 2248 |
'#ahah' => isset($element['#ahah']) ? $element['#ahah'] : NULL,
|
| 2249 |
|
| 2250 |
}
|
| 2251 |
|
| 2252 |
|
| 2253 |
|
| 2254 |
$parents_for_id = array_merge($element['#parents'], array($key));
|
| 2255 |
$element[$key] = array(
|
| 2256 |
'#type' => 'radio',
|
| 2257 |
'#title' => '',
|
| 2258 |
'#return_value' => $key,
|
| 2259 |
'#default_value' => ($element['#default_value'] == $key) ? $key : NULL,
|
| 2260 |
'#attributes' => $element['#attributes'],
|
| 2261 |
'#parents' => $element['#parents'],
|
| 2262 |
'#id' => form_clean_id('edit-' . implode('-', $parents_for_id)),
|
| 2263 |
'#ahah' => isset($element['#ahah']) ? $element['#ahah'] : NULL,
|
| 2264 |
|
| 2265 |
|
| 2266 |
}
|
| 2267 |
}
|
| 2268 |
}
|
| 2269 |
|
| 2270 |
$element['#value'] = array();
|
| 2271 |
|
| 2272 |
return $element;
|
| 2273 |
}
|
| 2274 |
|
| 2275 |
|
| 2276 |
|
| 2277 |
|
| 2278 |
|
| 2279 |
|
| 2280 |
|
| 2281 |
|
| 2282 |
|
| 2283 |
|
| 2284 |
|
| 2285 |
|
| 2286 |
|
| 2287 |
function form_process_fieldset(&$element, &$form_state) {
|
| 2288 |
$parents = implode('][', $element['#parents']);
|
| 2289 |
|
| 2290 |
|
| 2291 |
|
| 2292 |
if (isset($element['#group']) && $element['#group'] != $parents) {
|
| 2293 |
if (isset($form_state['groups'][$element['#group']]) && !empty($form_state['groups'][$element['#group']]['#group_exists'])) {
|
| 2294 |
|
| 2295 |
|
| 2296 |
|
| 2297 |
|
| 2298 |
|
| 2299 |
|
| 2300 |
|
| 2301 |
|
| 2302 |
|
| 2303 |
$element['#printed'] = TRUE;
|
| 2304 |
}
|
| 2305 |
|
| 2306 |
|
| 2307 |
|
| 2308 |
$form_state['groups'][$element['#group']][] = &$element;
|
| 2309 |
}
|
| 2310 |
|
| 2311 |
|
| 2312 |
|
| 2313 |
$form_state['groups'][$parents]['#group_exists'] = TRUE;
|
| 2314 |
|
| 2315 |
|
| 2316 |
|
| 2317 |
|
| 2318 |
|
| 2319 |
foreach (element_children($form_state['groups'][$parents]) as $key) {
|
| 2320 |
$form_state['groups'][$parents][$key]['#printed'] = TRUE;
|
| 2321 |
}
|
| 2322 |
$element['#group_members'] = &$form_state['groups'][$parents];
|
| 2323 |
|
| 2324 |
|
| 2325 |
drupal_add_js('misc/form.js', array('weight' => JS_LIBRARY + 1));
|
| 2326 |
|
| 2327 |
return $element;
|
| 2328 |
}
|
| 2329 |
|
| 2330 |
|
| 2331 |
|
| 2332 |
|
| 2333 |
|
| 2334 |
|
| 2335 |
|
| 2336 |
|
| 2337 |
|
| 2338 |
|
| 2339 |
function form_pre_render_fieldset($element) {
|
| 2340 |
if (!empty($element['#group_members'])) {
|
| 2341 |
|
| 2342 |
foreach (element_children($element['#group_members']) as $key) {
|
| 2343 |
|
| 2344 |
|
| 2345 |
|
| 2346 |
unset($element['#group_members'][$key]['#printed']);
|
| 2347 |
$element[] = &$element['#group_members'][$key];
|
| 2348 |
}
|
| 2349 |
|
| 2350 |
|
| 2351 |
$element['#sorted'] = FALSE;
|
| 2352 |
}
|
| 2353 |
|
| 2354 |
return $element;
|
| 2355 |
}
|
| 2356 |
|
| 2357 |
|
| 2358 |
|
| 2359 |
|
| 2360 |
|
| 2361 |
|
| 2362 |
|
| 2363 |
|
| 2364 |
|
| 2365 |
|
| 2366 |
|
| 2367 |
|
| 2368 |
function form_process_vertical_tabs($element, &$form_state) {
|
| 2369 |
|
| 2370 |
|
| 2371 |
|
| 2372 |
|
| 2373 |
$element['group'] = array(
|
| 2374 |
'#type' => 'fieldset',
|
| 2375 |
'#theme_wrappers' => array(),
|
| 2376 |
'#parents' => $element['#parents'],
|
| 2377 |
|
| 2378 |
|
| 2379 |
|
| 2380 |
|
| 2381 |
|
| 2382 |
|
| 2383 |
$name = implode('__', $element['#parents']);
|
| 2384 |
if (isset($form_state['values'][$name . '__active_tab'])) {
|
| 2385 |
$element['#default_tab'] = $form_state['values'][$name . '__active_tab'];
|
| 2386 |
}
|
| 2387 |
$element[$name . '__active_tab'] = array(
|
| 2388 |
'#type' => 'hidden',
|
| 2389 |
'#default_value' => $element['#default_tab'],
|
| 2390 |
'#attributes' => array('class' => 'vertical-tabs-active-tab'),
|
| 2391 |
|
| 2392 |
|
| 2393 |
return $element;
|
| 2394 |
}
|
| 2395 |
|
| 2396 |
|
| 2397 |
|
| 2398 |
|
| 2399 |
|
| 2400 |
|
| 2401 |
|
| 2402 |
|
| 2403 |
function theme_vertical_tabs($element) {
|
| 2404 |
|
| 2405 |
drupal_add_js('misc/vertical-tabs.js', array('weight' => JS_DEFAULT - 1));
|
| 2406 |
drupal_add_css('misc/vertical-tabs.css');
|
| 2407 |
|
| 2408 |
return '<div class="vertical-tabs-panes">' . $element['#children'] . '</div>';
|
| 2409 |
}
|
| 2410 |
|
| 2411 |
|
| 2412 |
|
| 2413 |
|
| 2414 |
|
| 2415 |
|
| 2416 |
function theme_submit($element) {
|
| 2417 |
return theme('button', $element);
|
| 2418 |
}
|
| 2419 |
|
| 2420 |
|
| 2421 |
|
| 2422 |
|
| 2423 |
|
| 2424 |
|
| 2425 |
function theme_button($element) {
|
| 2426 |
|
| 2427 |
if (isset($element['#attributes']['class'])) {
|
| 2428 |
$element['#attributes']['class'] = 'form-' . $element['#button_type'] . ' ' . $element['#attributes']['class'];
|
| 2429 |
}
|
| 2430 |
|
| 2431 |
$element['#attributes']['class'] = 'form-' . $element['#button_type'];
|
| 2432 |
|
| 2433 |
|
| 2434 |
return '<input type="submit" ' . (empty($element['#name']) ? '' : 'name="' . $element['#name'] . '" ') . 'id="' . $element['#id'] . '" value="' . check_plain($element['#value']) . '" ' . drupal_attributes($element['#attributes']) . " />\n";
|
| 2435 |
}
|
| 2436 |
|
| 2437 |
|
| 2438 |
|
| 2439 |
|
| 2440 |
|
| 2441 |
|
| 2442 |
function theme_image_button($element) {
|
| 2443 |
|
| 2444 |
if (isset($element['#attributes']['class'])) {
|
| 2445 |
$element['#attributes']['class'] = 'form-' . $element['#button_type'] . ' ' . $element['#attributes']['class'];
|
| 2446 |
}
|
| 2447 |
|
| 2448 |
$element['#attributes']['class'] = 'form-' . $element['#button_type'];
|
| 2449 |
|
| 2450 |
|
| 2451 |
return '<input type="image" name="' . $element['#name'] . '" ' .
|
| 2452 |
(!empty($element['#value']) ? ('value="' . check_plain($element['#value']) . '" ') : '') .
|
| 2453 |
'id="' . $element['#id'] . '" ' .
|
| 2454 |
drupal_attributes($element['#attributes']) .
|
| 2455 |
' src="' . base_path() . $element['#src'] . '" ' .
|
| 2456 |
(!empty($element['#title']) ? 'alt="' . check_plain($element['#title']) . '" title="' . check_plain($element['#title']) . '" ' : '' ) .
|
| 2457 |
"/>\n";
|
| 2458 |
}
|
| 2459 |
|
| 2460 |
|
| 2461 |
|
| 2462 |
|
| 2463 |
|
| 2464 |
|
| 2465 |
|
| 2466 |
|
| 2467 |
|
| 2468 |
|
| 2469 |
|
| 2470 |
function theme_hidden($element) {
|
| 2471 |
return '<input type="hidden" name="' . $element['#name'] . '" id="' . $element['#id'] . '" value="' . check_plain($element['#value']) . "\" " . drupal_attributes($element['#attributes']) . " />\n";
|
| 2472 |
}
|
| 2473 |
|
| 2474 |
|
| 2475 |
|
| 2476 |
|
| 2477 |
|
| 2478 |
|
| 2479 |
|
| 2480 |
|
| 2481 |
|
| 2482 |
|
| 2483 |
|
| 2484 |
|
| 2485 |
function theme_textfield($element) {
|
| 2486 |
$size = empty($element['#size']) ? '' : ' size="' . $element['#size'] . '"';
|
| 2487 |
$maxlength = empty($element['#maxlength']) ? '' : ' maxlength="' . $element['#maxlength'] . '"';
|
| 2488 |
$class = array('form-text');
|
| 2489 |
$extra = '';
|
| 2490 |
$output = '';
|
| 2491 |
|
| 2492 |
if ($element['#autocomplete_path'] && menu_valid_path(array('link_path' => $element['#autocomplete_path']))) {
|
| 2493 |
drupal_add_js('misc/autocomplete.js');
|
| 2494 |
$class[] = 'form-autocomplete';
|
| 2495 |
$extra = '<input class="autocomplete" type="hidden" id="' . $element['#id'] . '-autocomplete" value="' . check_url(url($element['#autocomplete_path'], array('absolute' => TRUE))) . '" disabled="disabled" />';
|
| 2496 |
}
|
| 2497 |
_form_set_class($element, $class);
|
| 2498 |
|
| 2499 |
if (isset($element['#field_prefix'])) {
|
| 2500 |
$output .= '<span class="field-prefix">' . $element['#field_prefix'] . '</span> ';
|
| 2501 |
}
|
| 2502 |
|
| 2503 |
$output .= '<input type="text"' . $maxlength . ' name="' . $element['#name'] . '" id="' . $element['#id'] . '"' . $size . ' value="' . check_plain($element['#value']) . '"' . drupal_attributes($element['#attributes']) . ' />';
|
| 2504 |
|
| 2505 |
if (isset($element['#field_suffix'])) {
|
| 2506 |
$output .= ' <span class="field-suffix">' . $element['#field_suffix'] . '</span>';
|
| 2507 |
}
|
| 2508 |
return $output . $extra;
|
| 2509 |
}
|
| 2510 |
|
| 2511 |
|
| 2512 |
|
| 2513 |
|
| 2514 |
|
| 2515 |
|
| 2516 |
|
| 2517 |
|
| 2518 |
|
| 2519 |
|
| 2520 |
|
| 2521 |
|
| 2522 |
function theme_form($element) {
|
| 2523 |
|
| 2524 |
$action = $element['#action'] ? 'action="' . check_url($element['#action']) . '" ' : '';
|
| 2525 |
return '<form ' . $action . ' accept-charset="UTF-8" method="' . $element['#method'] . '" id="' . $element['#id'] . '"' . drupal_attributes($element['#attributes']) . ">\n<div>" . $element['#children'] . "\n</div></form>\n";
|
| 2526 |
}
|
| 2527 |
|
| 2528 |
|
| 2529 |
|
| 2530 |
|
| 2531 |
|
| 2532 |
|
| 2533 |
|
| 2534 |
|
| 2535 |
|
| 2536 |
|
| 2537 |
|
| 2538 |
|
| 2539 |
function theme_textarea($element) {
|
| 2540 |
$class = array('form-textarea');
|
| 2541 |
|
| 2542 |
|
| 2543 |
if ($element['#resizable'] !== FALSE) {
|
| 2544 |
drupal_add_js('misc/textarea.js');
|
| 2545 |
$class[] = 'resizable';
|
| 2546 |
}
|
| 2547 |
|
| 2548 |
_form_set_class($element, $class);
|
| 2549 |
return '<textarea cols="' . $element['#cols'] . '" rows="' . $element['#rows'] . '" name="' . $element['#name'] . '" id="' . $element['#id'] . '" ' . drupal_attributes($element['#attributes']) . '>' . check_plain($element['#value']) . '</textarea>';
|
| 2550 |
}
|
| 2551 |
|
| 2552 |
|
| 2553 |
|
| 2554 |
|
| 2555 |
|
| 2556 |
|
| 2557 |
|
| 2558 |
|
| 2559 |
|
| 2560 |
|
| 2561 |
|
| 2562 |
|
| 2563 |
|
| 2564 |
function theme_markup($element) {
|
| 2565 |
return (!empty($element['#markup']) ? $element['#markup'] : '') . drupal_render_children($element);
|
| 2566 |
}
|
| 2567 |
|
| 2568 |
|
| 2569 |
|
| 2570 |
|
| 2571 |
|
| 2572 |
|
| 2573 |
|
| 2574 |
|
| 2575 |
|
| 2576 |
|
| 2577 |
|
| 2578 |
|
| 2579 |
function theme_password($element) {
|
| 2580 |
$size = $element['#size'] ? ' size="' . $element['#size'] . '" ' : '';
|
| 2581 |
$maxlength = $element['#maxlength'] ? ' maxlength="' . $element['#maxlength'] . '" ' : '';
|
| 2582 |
|
| 2583 |
_form_set_class($element, array('form-text'));
|
| 2584 |
$output = '<input type="password" name="' . $element['#name'] . '" id="' . $element['#id'] . '" ' . $maxlength . $size . drupal_attributes($element['#attributes']) . ' />';
|
| 2585 |
return $output;
|
| 2586 |
}
|
| 2587 |
|
| 2588 |
|
| 2589 |
|
| 2590 |
|
| 2591 |
function form_process_weight($element) {
|
| 2592 |
for ($n = (-1 * $element['#delta']); $n <= $element['#delta']; $n++) {
|
| 2593 |
$weights[$n] = $n;
|
| 2594 |
}
|
| 2595 |
$element['#options'] = $weights;
|
| 2596 |
$element['#type'] = 'select';
|
| 2597 |
$element['#is_weight'] = TRUE;
|
| 2598 |
$element += element_info('select');
|
| 2599 |
return $element;
|
| 2600 |
}
|
| 2601 |
|
| 2602 |
|
| 2603 |
|
| 2604 |
|
| 2605 |
|
| 2606 |
|
| 2607 |
|
| 2608 |
|
| 2609 |
|
| 2610 |
|
| 2611 |
|
| 2612 |
|
| 2613 |
|
| 2614 |
|
| 2615 |
|
| 2616 |
|
| 2617 |
|
| 2618 |
|
| 2619 |
|
| 2620 |
|
| 2621 |
|
| 2622 |
|
| 2623 |
function theme_file($element) {
|
| 2624 |
_form_set_class($element, array('form-file'));
|
| 2625 |
return '<input type="file" name="' . $element['#name'] . '"' . ($element['#attributes'] ? ' ' . drupal_attributes($element['#attributes']) : '') . ' id="' . $element['#id'] . '" size="' . $element['#size'] . "\" />\n";
|
| 2626 |
}
|
| 2627 |
|
| 2628 |
|
| 2629 |
|
| 2630 |
|
| 2631 |
|
| 2632 |
|
| 2633 |
|
| 2634 |
|
| 2635 |
|
| 2636 |
|
| 2637 |
|
| 2638 |
|
| 2639 |
function theme_form_element($element) {
|
| 2640 |
|
| 2641 |
$t = get_t();
|
| 2642 |
|
| 2643 |
|
| 2644 |
$class = array('form-item');
|
| 2645 |
if (!empty($element['#type'])) {
|
| 2646 |
$class[] = 'form-item-' . strtr($element['#type'], array('_' => '-'));
|
| 2647 |
}
|
| 2648 |
if (!empty($element['#name'])) {
|
| 2649 |
$class[] = strtr($element['#name'], array(' ' => '-', '_' => '-', '[' => '-', ']' => '')) . '-wrapper';
|
| 2650 |
}
|
| 2651 |
|
| 2652 |
$output = '<div class="' . implode(' ', $class) . '">' . "\n";
|
| 2653 |
$required = !empty($element['#required']) ? '<span class="form-required" title="' . $t('This field is required.') . '">*</span>' : '';
|
| 2654 |
|
| 2655 |
if (!empty($element['#title']) && empty($element['#form_element_skip_title'])) {
|
| 2656 |
$title = $element['#title'];
|
| 2657 |
if (!empty($element['#id'])) {
|
| 2658 |
$output .= ' <label for="' . $element['#id'] . '">' . $t('!title !required', array('!title' => filter_xss_admin($title), '!required' => $required)) . "</label>\n";
|
| 2659 |
}
|
| 2660 |
|
| 2661 |
$output .= ' <label>' . $t('!title !required', array('!title' => filter_xss_admin($title), '!required' => $required)) . "</label>\n";
|
| 2662 |
|
| 2663 |
}
|
| 2664 |
|
| 2665 |
$output .= " " . $element['#children'] . "\n";
|
| 2666 |
|
| 2667 |
if (!empty($element['#description'])) {
|
| 2668 |
$output .= ' <div class="description">' . $element['#description'] . "</div>\n";
|
| 2669 |
}
|
| 2670 |
|
| 2671 |
$output .= "</div>\n";
|
| 2672 |
|
| 2673 |
return $output;
|
| 2674 |
}
|
| 2675 |
|
| 2676 |
|
| 2677 |
|
| 2678 |
|
| 2679 |
|
| 2680 |
|
| 2681 |
|
| 2682 |
|
| 2683 |
|
| 2684 |
|
| 2685 |
|
| 2686 |
function _form_set_class(&$element, $class = array()) {
|
| 2687 |
if ($element['#required']) {
|
| 2688 |
$class[] = 'required';
|
| 2689 |
}
|
| 2690 |
if (form_get_error($element)) {
|
| 2691 |
$class[] = 'error';
|
| 2692 |
}
|
| 2693 |
if (isset($element['#attributes']['class'])) {
|
| 2694 |
$class[] = $element['#attributes']['class'];
|
| 2695 |
}
|
| 2696 |
$element['#attributes']['class'] = implode(' ', $class);
|
| 2697 |
}
|
| 2698 |
|
| 2699 |
|
| 2700 |
|
| 2701 |
|
| 2702 |
|
| 2703 |
|
| 2704 |
|
| 2705 |
|
| 2706 |
|
| 2707 |
|
| 2708 |
|
| 2709 |
|
| 2710 |
|
| 2711 |
|
| 2712 |
|
| 2713 |
|
| 2714 |
|
| 2715 |
function form_clean_id($id = NULL) {
|
| 2716 |
$seen_ids = &drupal_static(__FUNCTION__, array());
|
| 2717 |
$id = str_replace(array('][', '_', ' '), '-', $id);
|
| 2718 |
|
| 2719 |
|
| 2720 |
|
| 2721 |
|
| 2722 |
|
| 2723 |
|
| 2724 |
|
| 2725 |
if (isset($seen_ids[$id])) {
|
| 2726 |
$id = $id . '-' . $seen_ids[$id]++;
|
| 2727 |
}
|
| 2728 |
|
| 2729 |
$seen_ids[$id] = 1;
|
| 2730 |
|
| 2731 |
|
| 2732 |
return $id;
|
| 2733 |
}
|
| 2734 |
|
| 2735 |
|
| 2736 |
|
| 2737 |
|
| 2738 |
|
| 2739 |
|
| 2740 |
|
| 2741 |
|
| 2742 |
|
| 2743 |
|
| 2744 |
|
| 2745 |
|
| 2746 |
|
| 2747 |
|
| 2748 |
|
| 2749 |
|
| 2750 |
|
| 2751 |
|
| 2752 |
|
| 2753 |
|
| 2754 |
|
| 2755 |
|
| 2756 |
|
| 2757 |
|
| 2758 |
|
| 2759 |
|
| 2760 |
|
| 2761 |
|
| 2762 |
|
| 2763 |
|
| 2764 |
|
| 2765 |
|
| 2766 |
|
| 2767 |
|
| 2768 |
|
| 2769 |
|
| 2770 |
|
| 2771 |
|
| 2772 |
|
| 2773 |
|
| 2774 |
|
| 2775 |
|
| 2776 |
|
| 2777 |
|
| 2778 |
|
| 2779 |
|
| 2780 |
|
| 2781 |
|
| 2782 |
|
| 2783 |
|
| 2784 |
|
| 2785 |
|
| 2786 |
|
| 2787 |
|
| 2788 |
|
| 2789 |
|
| 2790 |
|
| 2791 |
|
| 2792 |
|
| 2793 |
|
| 2794 |
|
| 2795 |
|
| 2796 |
|
| 2797 |
|
| 2798 |
|
| 2799 |
|
| 2800 |
|
| 2801 |
|
| 2802 |
|
| 2803 |
|
| 2804 |
|
| 2805 |
|
| 2806 |
|
| 2807 |
|
| 2808 |
|
| 2809 |
|
| 2810 |
|
| 2811 |
|
| 2812 |
|
| 2813 |
|
| 2814 |
|
| 2815 |
|
| 2816 |
|
| 2817 |
|
| 2818 |
|
| 2819 |
|
| 2820 |
|
| 2821 |
|
| 2822 |
|
| 2823 |
|
| 2824 |
|
| 2825 |
|
| 2826 |
|
| 2827 |
|
| 2828 |
|
| 2829 |
|
| 2830 |
|
| 2831 |
|
| 2832 |
|
| 2833 |
|
| 2834 |
|
| 2835 |
|
| 2836 |
|
| 2837 |
|
| 2838 |
|
| 2839 |
|
| 2840 |
|
| 2841 |
|
| 2842 |
|
| 2843 |
|
| 2844 |
|
| 2845 |
|
| 2846 |
|
| 2847 |
|
| 2848 |
|
| 2849 |
|
| 2850 |
|
| 2851 |
|
| 2852 |
|
| 2853 |
|
| 2854 |
|
| 2855 |
|
| 2856 |
|
| 2857 |
|
| 2858 |
|
| 2859 |
|
| 2860 |
|
| 2861 |
|
| 2862 |
|
| 2863 |
|
| 2864 |
|
| 2865 |
|
| 2866 |
|
| 2867 |
|
| 2868 |
|
| 2869 |
|
| 2870 |
|
| 2871 |
|
| 2872 |
|
| 2873 |
|
| 2874 |
|
| 2875 |
|
| 2876 |
|
| 2877 |
|
| 2878 |
|
| 2879 |
|
| 2880 |
|
| 2881 |
|
| 2882 |
|
| 2883 |
|
| 2884 |
|
| 2885 |
|
| 2886 |
|
| 2887 |
function batch_set($batch_definition) {
|
| 2888 |
if ($batch_definition) {
|
| 2889 |
$batch =& batch_get();
|
| 2890 |
|
| 2891 |
if (empty($batch)) {
|
| 2892 |
|
| 2893 |
'sets' => array(),
|
| 2894 |
);
|
| 2895 |
}
|
| 2896 |
|
| 2897 |
|
| 2898 |
'sandbox' => array(),
|
| 2899 |
'results' => array(),
|
| 2900 |
'success' => FALSE,
|
| 2901 |
'start' => microtime(TRUE),
|
| 2902 |
'elapsed' => 0,
|
| 2903 |
);
|
| 2904 |
|
| 2905 |
$t = get_t();
|
| 2906 |
|
| 2907 |
'title' => $t('Processing'),
|
| 2908 |
'init_message' => $t('Initializing.'),
|
| 2909 |
'progress_message' => $t('Completed @current of @total.'),
|
| 2910 |
'error_message' => $t('An error has occurred.'),
|
| 2911 |
'css' => array(),
|
| 2912 |
);
|
| 2913 |
$batch_set = $init + $batch_definition + $defaults;
|
| 2914 |
|
| 2915 |
|
| 2916 |
$batch_set['init_message'] .= '<br/> ';
|
| 2917 |
$batch_set['total'] = count($batch_set['operations']);
|
| 2918 |
|
| 2919 |
|
| 2920 |
|
| 2921 |
if (isset($batch['current_set'])) {
|
| 2922 |
|
| 2923 |
$slice1 = array_slice($batch['sets'], 0, $batch['current_set'] + 1);
|
| 2924 |
$slice2 = array_slice($batch['sets'], $batch['current_set'] + 1);
|
| 2925 |
$batch['sets'] = array_merge($slice1, array($batch_set), $slice2);
|
| 2926 |
}
|
| 2927 |
|
| 2928 |
$batch['sets'][] = $batch_set;
|
| 2929 |
|
| 2930 |
}
|
| 2931 |
}
|
| 2932 |
|
| 2933 |
|
| 2934 |
|
| 2935 |
|
| 2936 |
|
| 2937 |
|
| 2938 |
|
| 2939 |
|
| 2940 |
|
| 2941 |
|
| 2942 |
|
| 2943 |
|
| 2944 |
|
| 2945 |
|
| 2946 |
|
| 2947 |
|
| 2948 |
function batch_process($redirect = NULL, $url = NULL) {
|
| 2949 |
$batch =& batch_get();
|
| 2950 |
|
| 2951 |
if (isset($batch)) {
|
| 2952 |
|
| 2953 |
$url = isset($url) ? $url : 'batch';
|
| 2954 |
|
| 2955 |
'current_set' => 0,
|
| 2956 |
'progressive' => TRUE,
|
| 2957 |
'url' => isset($url) ? $url : 'batch',
|
| 2958 |
'source_page' => $_GET['q'],
|
| 2959 |
'redirect' => $redirect,
|
| 2960 |
);
|
| 2961 |
$batch += $process_info;
|
| 2962 |
|
| 2963 |
if ($batch['progressive']) {
|
| 2964 |
|
| 2965 |
|
| 2966 |
|
| 2967 |
if (isset($_REQUEST['destination'])) {
|
| 2968 |
$batch['destination'] = $_REQUEST['destination'];
|
| 2969 |
unset($_REQUEST['destination']);
|
| 2970 |
}
|
| 2971 |
|
| 2972 |
|
| 2973 |
|
| 2974 |
$batch['id'] = db_insert('batch')
|
| 2975 |
->fields(array(
|
| 2976 |
'token' => '',
|
| 2977 |
'timestamp' => REQUEST_TIME,
|
| 2978 |
))
|
| 2979 |
->execute();
|
| 2980 |
|
| 2981 |
|
| 2982 |
|
| 2983 |
$t = get_t();
|
| 2984 |
$batch['error_message'] = $t('Please continue to <a href="@error_url">the error page</a>', array('@error_url' => url($url, array('query' => array('id' => $batch['id'], 'op' => 'finished')))));
|
| 2985 |
|
| 2986 |
|
| 2987 |
db_update('batch')
|
| 2988 |
->condition('bid', $batch['id'])
|
| 2989 |
->fields(array(
|
| 2990 |
'token' => drupal_get_token($batch['id']),
|
| 2991 |
'batch' => serialize($batch),
|
| 2992 |
))
|
| 2993 |
->execute();
|
| 2994 |
|
| 2995 |
|
| 2996 |
$_SESSION['batches'][$batch['id']] = TRUE;
|
| 2997 |
|
| 2998 |
drupal_goto($batch['url'], 'op=start&id=' . $batch['id']);
|
| 2999 |
}
|
| 3000 |
|
| 3001 |
|
| 3002 |
|
| 3003 |
require_once DRUPAL_ROOT . '/includes/batch.inc';
|
| 3004 |
_batch_process();
|
| 3005 |
|
| 3006 |
}
|
| 3007 |
}
|
| 3008 |
|
| 3009 |
|
| 3010 |
|
| 3011 |
|
| 3012 |
function &batch_get() {
|
| 3013 |
$batch = &drupal_static(__FUNCTION__, array());
|
| 3014 |
return $batch;
|
| 3015 |
}
|
| 3016 |
|
| 3017 |
|
| 3018 |
|
| 3019 |
|
| 3020 |
|