Revision 76bdcd04
Added by Assos Assos almost 6 years ago
drupal7/sites/all/modules/webform/webform.api.php | ||
---|---|---|
446 | 446 |
* - conditional |
447 | 447 |
* - spam_analysis |
448 | 448 |
* - group |
449 |
* - private |
|
449 | 450 |
* |
450 | 451 |
* Note that most of these features do not indicate the default state, but |
451 | 452 |
* determine if the component can have this property at all. Setting |
... | ... | |
542 | 543 |
// If this component reflects a time range and should use labels such as |
543 | 544 |
// "Before" and "After" when exposed as filters in Views module. |
544 | 545 |
'views_range' => FALSE, |
546 |
|
|
547 |
// Set this to FALSE if this component cannot be used as a private |
|
548 |
// component. If this is not FALSE, in your implementation of |
|
549 |
// _webform_defaults_COMPONENT(), set ['extra']['private'] property to |
|
550 |
// TRUE or FALSE. |
|
551 |
'private' => FALSE, |
|
545 | 552 |
), |
546 | 553 |
|
547 | 554 |
// Specify the conditional behaviour of this component. |
... | ... | |
759 | 766 |
* Alter default settings for a newly created webform node. |
760 | 767 |
* |
761 | 768 |
* @param array $defaults |
762 |
* Default settings for a newly created webform node as defined by webform_node_defaults(). |
|
769 |
* Default settings for a newly created webform node as defined by |
|
770 |
* webform_node_defaults(). |
|
763 | 771 |
* |
764 | 772 |
* @see webform_node_defaults() |
765 | 773 |
*/ |
... | ... | |
932 | 940 |
} |
933 | 941 |
|
934 | 942 |
/** |
935 |
* Allow modules to modify a webform component that is going to be rendered in a form.
|
|
943 |
* Allow modules to modify a webform component that will be rendered in a form.
|
|
936 | 944 |
* |
937 | 945 |
* @param array $element |
938 | 946 |
* The display element as returned by _webform_render_component(). |
... | ... | |
1410 | 1418 |
$exporters['excel']['file'] = drupal_get_path('module', 'yourmodule') . '/includes/customized_excel_exporter.inc'; |
1411 | 1419 |
} |
1412 | 1420 |
|
1421 |
/** |
|
1422 |
* Declare conditional types and their operators. |
|
1423 |
* |
|
1424 |
* Each conditional type defined here may then be referenced in |
|
1425 |
* hook_webform_component_info(). For each type this hook also declares a set of |
|
1426 |
* operators that may be applied to a component of this conditional type in |
|
1427 |
* conditionals. |
|
1428 |
* |
|
1429 |
* @return array |
|
1430 |
* A 2-dimensional array of operator configurations. The configurations are |
|
1431 |
* keyed first by their conditional type then by operator key. Each operator |
|
1432 |
* declaration is an array with the following keys: |
|
1433 |
* - label: Translated label for this operator that is shown in the UI. |
|
1434 |
* - comparison callback: A callback for server-side evaluation. |
|
1435 |
* - js comparison callback: A JavaScript callback for client-side evaluation. |
|
1436 |
* The callback will be looked for in the Drupal.webform object. |
|
1437 |
* - form callback (optional): A form callback that allows configuring |
|
1438 |
* additional parameters for this operator. Default: |
|
1439 |
* 'webform_conditional_operator_text'. |
|
1440 |
* |
|
1441 |
* @see hook_webform_component_info() |
|
1442 |
* @see callback_webform_conditional_comparision_operator() |
|
1443 |
* @see callback_webform_conditional_rule_value_form() |
|
1444 |
*/ |
|
1445 |
function hook_webform_conditional_operator_info() { |
|
1446 |
$operators = array(); |
|
1447 |
$operators['string']['not_equal'] = array( |
|
1448 |
'label' => t('is not'), |
|
1449 |
'comparison callback' => 'webform_conditional_operator_string_not_equal', |
|
1450 |
'js comparison callback' => 'conditionalOperatorStringNotEqual', |
|
1451 |
); |
|
1452 |
return $operators; |
|
1453 |
} |
|
1454 |
|
|
1455 |
/** |
|
1456 |
* Alter the list of operators and conditional types. |
|
1457 |
* |
|
1458 |
* @param array $operators |
|
1459 |
* A data structure as described in hook_webform_conditional_operator_info(). |
|
1460 |
* |
|
1461 |
* @see hook_webform_conditional_operator_info() |
|
1462 |
*/ |
|
1463 |
function hook_webform_conditional_operators_alter(array &$operators) { |
|
1464 |
$operators['string']['not_equal']['label'] = t('not equal'); |
|
1465 |
} |
|
1466 |
|
|
1467 |
/** |
|
1468 |
* Evaluate the operator for a given set of values. |
|
1469 |
* |
|
1470 |
* This function will be called two times with potentially different kinds of |
|
1471 |
* values: Once in _webform_client_form_validate() before any of the validate |
|
1472 |
* handlers or the _webform_submit_COMPONENT() callback is called, and once in |
|
1473 |
* webform_client_form_pages() after those handlers have been called. |
|
1474 |
* |
|
1475 |
* @param array $input_values |
|
1476 |
* The values received from the browser. |
|
1477 |
* @param mixed $rule_value |
|
1478 |
* The value as configured in the form callback. |
|
1479 |
* @param array $component |
|
1480 |
* The component for which we are evaluating the operator. |
|
1481 |
* |
|
1482 |
* @return bool |
|
1483 |
* The operation result. |
|
1484 |
*/ |
|
1485 |
function callback_webfom_conditional_comparison_operator(array $input_values, $rule_value, array $component) { |
|
1486 |
foreach ($input_values as $value) { |
|
1487 |
if (strcasecmp($value, $rule_value)) { |
|
1488 |
return TRUE; |
|
1489 |
} |
|
1490 |
} |
|
1491 |
return FALSE; |
|
1492 |
} |
|
1493 |
|
|
1494 |
/** |
|
1495 |
* Define a form element that configures your operator. |
|
1496 |
* |
|
1497 |
* @param object $node |
|
1498 |
* The node for which the conditionals are being configured. |
|
1499 |
* |
|
1500 |
* @return string|string[] |
|
1501 |
* Either a single rendered form element or a rendered form element per |
|
1502 |
* component (keyed by cid). Make sure that none of the rendered strings |
|
1503 |
* contains any HTML IDs as the form element will be rendered multiple times. |
|
1504 |
* The JavaScript will take care of adding the appropriate name attributes. |
|
1505 |
* |
|
1506 |
* @see _webform_conditional_expand_value_forms() |
|
1507 |
*/ |
|
1508 |
function callback_webform_conditional_rule_value_form($node) { |
|
1509 |
$forms = []; |
|
1510 |
foreach ($node->webform['components'] as $cid => $component) { |
|
1511 |
if (webform_component_property($component['type'], 'conditional_type') == 'newsletter') { |
|
1512 |
$element = [ |
|
1513 |
'#type' => 'select', |
|
1514 |
'#options' => [ |
|
1515 |
'yes' => t('Opt-in'), |
|
1516 |
'no' => t('No opt-in'), |
|
1517 |
], |
|
1518 |
]; |
|
1519 |
$forms[$cid] = drupal_render($element); |
|
1520 |
} |
|
1521 |
} |
|
1522 |
return $forms; |
|
1523 |
} |
|
1524 |
|
|
1413 | 1525 |
/** |
1414 | 1526 |
* @} |
1415 | 1527 |
*/ |
Also available in: Unified diff
Weekly update of contrib modules