Projet

Général

Profil

Révision 950416da

Ajouté par Assos Assos il y a plus de 5 ans

Weekly update of contrib modules

Voir les différences:

drupal7/sites/all/modules/rules/ui/ui.data.inc
1 1
<?php
2 2

  
3 3
/**
4
 * @file Contains data type related forms.
4
 * @file
5
 * Contains data type related forms.
5 6
 */
6 7

  
7

  
8 8
/**
9 9
 * Interface for data types providing a direct input form.
10 10
 */
......
13 13
  /**
14 14
   * Constructs the direct input form.
15 15
   *
16
   * @return Array
17
   *  The direct input form.
16
   * @return array
17
   *   The direct input form.
18 18
   */
19 19
  public static function inputForm($name, $info, $settings, RulesPlugin $element);
20 20

  
21 21
  /**
22 22
   * Render the configured value.
23 23
   *
24
   * @return Array
24
   * @return array
25 25
   *   A renderable array.
26 26
   */
27 27
  public static function render($value);
......
36 36
  /**
37 37
   * Returns the options list for the data type.
38 38
   *
39
   * @param RulesPlugin $element
40
   *   The rules element to get the options for.
41
   * @param string $name
42
   *   The name of the parameter for which to get options.
43
   *
44 39
   * For retrieving information about the used data type and parameter, the
45 40
   * helper RulesDataUI::getTypeInfo() may be used as following:
46 41
   * @code
47 42
   *   list($type, $parameter_info) = RulesDataUI::getTypeInfo($element, $name);
48 43
   * @endcode
49 44
   *
50
   * @return
45
   * @param RulesPlugin $element
46
   *   The rules element to get the options for.
47
   * @param string $name
48
   *   The name of the parameter for which to get options.
49
   *
50
   * @return array
51 51
   *   An array of options as used by hook_options_list().
52 52
   */
53 53
  public static function optionsList(RulesPlugin $element, $name);
54

  
54 55
}
55 56

  
56 57
/**
......
138 139
  }
139 140

  
140 141
  /**
141
   * Renders the value by making use of the label if an options list is available.
142
   * Renders the value with a label if an options list is available.
142 143
   *
143 144
   * Used for data UI classes implementing the
144 145
   * RulesDataDirectInputFormInterface.
......
181 182
    $parameters = $element->pluginParameterInfo();
182 183
    return array($parameters[$name]['type'], $parameters[$name]);
183 184
  }
185

  
184 186
}
185 187

  
186 188
/**
......
188 190
 */
189 191
class RulesDataUIText extends RulesDataUI implements RulesDataDirectInputFormInterface {
190 192

  
193
  /**
194
   * Overrides RulesDataUI::getDefaultMode().
195
   */
191 196
  public static function getDefaultMode() {
192 197
    return 'input';
193 198
  }
194 199

  
200
  /**
201
   * Implements RulesDataDirectInputFormInterface::inputForm().
202
   */
195 203
  public static function inputForm($name, $info, $settings, RulesPlugin $element) {
196 204
    if (!empty($info['options list'])) {
197 205
      // Make sure the .rules.inc of the providing module is included as the
......
205 213
    else {
206 214
      $form[$name] = array(
207 215
        '#type' => 'textarea',
216
        '#rows' => 3,
208 217
      );
209 218
      RulesDataInputEvaluator::attachForm($form, $settings, $info, $element->availableVariables());
210 219
    }
......
214 223
      '#default_value' => $settings[$name],
215 224
      '#required' => empty($info['optional']),
216 225
      '#after_build' => array('rules_ui_element_fix_empty_after_build'),
217
      '#rows' => 3,
218 226
    );
219 227
    return $form;
220 228
  }
221 229

  
230
  /**
231
   * Implements RulesDataDirectInputFormInterface::render().
232
   */
222 233
  public static function render($value) {
223 234
    return array(
224 235
      'content' => array('#markup' => check_plain($value)),
225 236
      '#attributes' => array('class' => array('rules-parameter-text')),
226 237
    );
227 238
  }
239

  
228 240
}
229 241

  
230 242
/**
......
232 244
 */
233 245
class RulesDataUITextToken extends RulesDataUIText {
234 246

  
247
  /**
248
   * Implements RulesDataDirectInputFormInterface::inputForm().
249
   */
235 250
  public static function inputForm($name, $info, $settings, RulesPlugin $element) {
236 251
    $form = parent::inputForm($name, $info, $settings, $element);
237 252
    if ($form[$name]['#type'] == 'textarea') {
......
241 256
    }
242 257
    return $form;
243 258
  }
259

  
244 260
}
245 261

  
246 262
/**
......
248 264
 */
249 265
class RulesDataUITextFormatted extends RulesDataUIText {
250 266

  
267
  /**
268
   * Implements RulesDataDirectInputFormInterface::inputForm().
269
   */
251 270
  public static function inputForm($name, $info, $settings, RulesPlugin $element) {
252 271
    $form = parent::inputForm($name, $info, $settings, $element);
253 272
    $settings += array($name => isset($info['default value']) ? $info['default value'] : array('value' => NULL, 'format' => NULL));
......
259 278
    return $form;
260 279
  }
261 280

  
281
  /**
282
   * Implements RulesDataDirectInputFormInterface::render().
283
   */
262 284
  public static function render($value) {
263 285
    return array(
264 286
      'content' => array('#markup' => check_plain($value['value'])),
265 287
      '#attributes' => array('class' => array('rules-parameter-text-formatted')),
266 288
    );
267 289
  }
268
}
269

  
270 290

  
291
}
271 292

  
272 293
/**
273 294
 * UI for decimal data.
274 295
 */
275 296
class RulesDataUIDecimal extends RulesDataUIText {
276 297

  
298
  /**
299
   * Implements RulesDataDirectInputFormInterface::inputForm().
300
   */
277 301
  public static function inputForm($name, $info, $settings, RulesPlugin $element) {
278 302
    $form = parent::inputForm($name, $info, $settings, $element);
279 303
    if (empty($info['options list'])) {
......
283 307
    $form[$name]['#rows'] = 1;
284 308
    return $form;
285 309
  }
310

  
286 311
}
287 312

  
288 313
/**
......
290 315
 */
291 316
class RulesDataUIInteger extends RulesDataUIText {
292 317

  
318
  /**
319
   * Implements RulesDataDirectInputFormInterface::inputForm().
320
   */
293 321
  public static function inputForm($name, $info, $settings, RulesPlugin $element) {
294 322
    $form = parent::inputForm($name, $info, $settings, $element);
295 323
    if (empty($info['options list'])) {
......
298 326
    $form[$name]['#element_validate'][] = 'rules_ui_element_integer_validate';
299 327
    return $form;
300 328
  }
329

  
301 330
}
302 331

  
303 332
/**
......
305 334
 */
306 335
class RulesDataUIIPAddress extends RulesDataUIText {
307 336

  
337
  /**
338
   * Implements RulesDataDirectInputFormInterface::inputForm().
339
   */
308 340
  public static function inputForm($name, $info, $settings, RulesPlugin $element) {
309 341
    $form = parent::inputForm($name, $info, $settings, $element);
310 342
    if (empty($info['options list'])) {
......
315 347
    $form[$name]['#rows'] = 1;
316 348
    return $form;
317 349
  }
350

  
318 351
}
319 352

  
320 353
/**
......
322 355
 */
323 356
class RulesDataUIBoolean extends RulesDataUI implements RulesDataDirectInputFormInterface {
324 357

  
358
  /**
359
   * Overrides RulesDataUI::getDefaultMode().
360
   */
325 361
  public static function getDefaultMode() {
326 362
    return 'input';
327 363
  }
328 364

  
365
  /**
366
   * Implements RulesDataDirectInputFormInterface::inputForm().
367
   */
329 368
  public static function inputForm($name, $info, $settings, RulesPlugin $element) {
330 369
    $settings += array($name => isset($info['default value']) ? $info['default value'] : NULL);
331 370
    // Note: Due to the checkbox even optional parameter always receive a value.
......
340 379
    return $form;
341 380
  }
342 381

  
382
  /**
383
   * Implements RulesDataDirectInputFormInterface::render().
384
   */
343 385
  public static function render($value) {
344 386
    return array(
345 387
      'content' => array('#markup' => !empty($value) ? t('true') : t('false')),
346 388
      '#attributes' => array('class' => array('rules-parameter-boolean')),
347 389
    );
348 390
  }
391

  
349 392
}
350 393

  
351 394
/**
......
353 396
 */
354 397
class RulesDataUIDate extends RulesDataUIText {
355 398

  
399
  /**
400
   * Implements RulesDataDirectInputFormInterface::inputForm().
401
   */
356 402
  public static function inputForm($name, $info, $settings, RulesPlugin $element) {
357 403
    $settings += array($name => isset($info['default value']) ? $info['default value'] : (empty($info['optional']) ? gmdate('Y-m-d H:i:s', time()) : NULL));
358 404

  
......
369 415
      array('%format' => gmdate('Y-m-d H:i:s', time() + 86400),
370 416
            '!strtotime' => l('strtotime()', 'http://php.net/strtotime')));
371 417

  
372
    //TODO: Leverage the jquery datepicker+timepicker once a module providing
373
    //the timpeicker is available.
418
    // @todo Leverage the jquery datepicker+timepicker once a module providing
419
    // The timepicker is available.
374 420
    return $form;
375 421
  }
376 422

  
423
  /**
424
   * Implements RulesDataDirectInputFormInterface::render().
425
   */
377 426
  public static function render($value) {
378 427
    $value = is_numeric($value) ? format_date($value, 'short') : check_plain($value);
379 428
    return array(
......
381 430
      '#attributes' => array('class' => array('rules-parameter-date')),
382 431
    );
383 432
  }
433

  
384 434
}
385 435

  
386 436
/**
......
388 438
 */
389 439
class RulesDataUIDuration extends RulesDataUIText {
390 440

  
441
  /**
442
   * Implements RulesDataDirectInputFormInterface::inputForm().
443
   */
391 444
  public static function inputForm($name, $info, $settings, RulesPlugin $element) {
392 445
    $form = parent::inputForm($name, $info, $settings, $element);
393 446
    $form[$name]['#type'] = 'rules_duration';
......
395 448
    return $form;
396 449
  }
397 450

  
451
  /**
452
   * Implements RulesDataDirectInputFormInterface::render().
453
   */
398 454
  public static function render($value) {
399 455
    $value = is_numeric($value) ? format_interval($value) : check_plain($value);
400 456
    return array(
......
402 458
      '#attributes' => array('class' => array('rules-parameter-duration')),
403 459
    );
404 460
  }
461

  
405 462
}
406 463

  
407 464
/**
......
409 466
 */
410 467
class RulesDataUIURI extends RulesDataUIText {
411 468

  
469
  /**
470
   * Implements RulesDataDirectInputFormInterface::inputForm().
471
   */
412 472
  public static function inputForm($name, $info, $settings, RulesPlugin $element) {
413 473
    $form = parent::inputForm($name, $info, $settings, $element);
414 474
    $form[$name]['#rows'] = 1;
415
    $form[$name]['#description'] = t('You may enter relative URLs like %url as well as absolute URLs like %absolute-url.', array('%url' => 'user/login?destination=node', '%absolute-url' => 'http://drupal.org'));
475
    $form[$name]['#description'] = t('You may enter relative URLs like %url as well as absolute URLs like %absolute-url.', array('%url' => 'user/login?destination=node', '%absolute-url' => 'https://www.drupal.org'));
416 476
    return $form;
417 477
  }
478

  
418 479
}
419 480

  
420 481
/**
......
422 483
 */
423 484
class RulesDataUIListText extends RulesDataUIText {
424 485

  
486
  /**
487
   * Overrides RulesDataUI::getDefaultMode().
488
   */
425 489
  public static function getDefaultMode() {
426 490
    return 'input';
427 491
  }
428 492

  
429 493
  /**
494
   * Implements RulesDataDirectInputFormInterface::inputForm().
495
   *
430 496
   * @todo This does not work for inputting textual values including "\n".
431 497
   */
432 498
  public static function inputForm($name, $info, $settings, RulesPlugin $element) {
......
447 513
    return $form;
448 514
  }
449 515

  
516
  /**
517
   * Implements RulesDataDirectInputFormInterface::render().
518
   */
450 519
  public static function render($value) {
451 520
    return array(
452 521
      'content' => array('#markup' => check_plain(implode(', ', $value))),
453 522
      '#attributes' => array('class' => array('rules-parameter-list')),
454 523
    );
455 524
  }
525

  
456 526
}
457 527

  
458 528
/**
......
460 530
 */
461 531
class RulesDataUIListInteger extends RulesDataUIListText {
462 532

  
533
  /**
534
   * Implements RulesDataDirectInputFormInterface::inputForm().
535
   */
463 536
  public static function inputForm($name, $info, $settings, RulesPlugin $element) {
464 537
    $settings += array($name => isset($info['default value']) ? $info['default value'] : NULL);
465 538
    $form = parent::inputForm($name, $info, $settings, $element);
......
473 546
    }
474 547
    return $form;
475 548
  }
549

  
476 550
}
477 551

  
478 552
/**
......
480 554
 */
481 555
class RulesDataUIListToken extends RulesDataUIListInteger {
482 556

  
557
  /**
558
   * Implements RulesDataDirectInputFormInterface::inputForm().
559
   */
483 560
  public static function inputForm($name, $info, $settings, RulesPlugin $element) {
484 561
    $form = parent::inputForm($name, $info, $settings, $element);
485 562

  
......
489 566
    }
490 567
    return $form;
491 568
  }
569

  
492 570
}
493 571

  
494 572
/**
......
496 574
 */
497 575
class RulesDataUIEntity extends RulesDataUIText {
498 576

  
577
  /**
578
   * Overrides RulesDataUI::getDefaultMode().
579
   */
499 580
  public static function getDefaultMode() {
500 581
    return 'selector';
501 582
  }
502 583

  
584
  /**
585
   * Implements RulesDataDirectInputFormInterface::inputForm().
586
   */
503 587
  public static function inputForm($name, $info, $settings, RulesPlugin $element) {
504 588
    $form = parent::inputForm($name, $info, $settings, $element);
505 589
    if (empty($info['options list'])) {
......
515 599
    }
516 600
    return $form;
517 601
  }
602

  
518 603
}
519 604

  
520 605
/**
......
522 607
 */
523 608
class RulesDataUIEntityExportable extends RulesDataUIEntity {
524 609

  
610
  /**
611
   * Overrides RulesDataUI::getDefaultMode().
612
   */
525 613
  public static function getDefaultMode() {
526 614
    return 'input';
527 615
  }
616

  
528 617
}
529 618

  
530 619
/**
......
535 624
 */
536 625
class RulesDataUIBundleEntity extends RulesDataUIEntity implements RulesDataInputOptionsListInterface {
537 626

  
627
  /**
628
   * Overrides RulesDataUI::getDefaultMode().
629
   */
538 630
  public static function getDefaultMode() {
539 631
    return 'input';
540 632
  }
......
554 646
    }
555 647
    return $bundles;
556 648
  }
649

  
557 650
}
558 651

  
559 652
/**
......
563 656
 */
564 657
class RulesDataUITaxonomyVocabulary extends RulesDataUIEntity implements RulesDataInputOptionsListInterface {
565 658

  
659
  /**
660
   * Overrides RulesDataUI::getDefaultMode().
661
   */
566 662
  public static function getDefaultMode() {
567 663
    return 'input';
568 664
  }
......
577 673
    }
578 674
    return $options;
579 675
  }
676

  
580 677
}
581 678

  
582 679
/**
......
584 681
 */
585 682
class RulesDataUIListEntity extends RulesDataUIListInteger {
586 683

  
684
  /**
685
   * Implements RulesDataDirectInputFormInterface::inputForm().
686
   */
587 687
  public static function inputForm($name, $info, $settings, RulesPlugin $element) {
588 688
    $form = parent::inputForm($name, $info, $settings, $element);
589 689
    if (empty($info['options list'])) {
......
598 698
    }
599 699
    return $form;
600 700
  }
701

  
601 702
}

Formats disponibles : Unified diff