updated rules

This commit is contained in:
2020-06-23 12:29:12 +02:00
parent 35b78db5c0
commit da7085e201
72 changed files with 2402 additions and 1060 deletions
@@ -1,10 +1,10 @@
<?php
/**
* @file Contains data type related forms.
* @file
* Contains data type related forms.
*/
/**
* Interface for data types providing a direct input form.
*/
@@ -13,15 +13,15 @@ interface RulesDataDirectInputFormInterface {
/**
* Constructs the direct input form.
*
* @return Array
* The direct input form.
* @return array
* The direct input form.
*/
public static function inputForm($name, $info, $settings, RulesPlugin $element);
/**
* Render the configured value.
*
* @return Array
* @return array
* A renderable array.
*/
public static function render($value);
@@ -36,21 +36,22 @@ interface RulesDataInputOptionsListInterface extends RulesDataDirectInputFormInt
/**
* Returns the options list for the data type.
*
* @param RulesPlugin $element
* The rules element to get the options for.
* @param string $name
* The name of the parameter for which to get options.
*
* For retrieving information about the used data type and parameter, the
* helper RulesDataUI::getTypeInfo() may be used as following:
* @code
* list($type, $parameter_info) = RulesDataUI::getTypeInfo($element, $name);
* @endcode
*
* @return
* @param RulesPlugin $element
* The rules element to get the options for.
* @param string $name
* The name of the parameter for which to get options.
*
* @return array
* An array of options as used by hook_options_list().
*/
public static function optionsList(RulesPlugin $element, $name);
}
/**
@@ -138,7 +139,7 @@ class RulesDataUI {
}
/**
* Renders the value by making use of the label if an options list is available.
* Renders the value with a label if an options list is available.
*
* Used for data UI classes implementing the
* RulesDataDirectInputFormInterface.
@@ -181,6 +182,7 @@ class RulesDataUI {
$parameters = $element->pluginParameterInfo();
return array($parameters[$name]['type'], $parameters[$name]);
}
}
/**
@@ -188,10 +190,16 @@ class RulesDataUI {
*/
class RulesDataUIText extends RulesDataUI implements RulesDataDirectInputFormInterface {
/**
* Overrides RulesDataUI::getDefaultMode().
*/
public static function getDefaultMode() {
return 'input';
}
/**
* Implements RulesDataDirectInputFormInterface::inputForm().
*/
public static function inputForm($name, $info, $settings, RulesPlugin $element) {
if (!empty($info['options list'])) {
// Make sure the .rules.inc of the providing module is included as the
@@ -205,6 +213,7 @@ class RulesDataUIText extends RulesDataUI implements RulesDataDirectInputFormInt
else {
$form[$name] = array(
'#type' => 'textarea',
'#rows' => 3,
);
RulesDataInputEvaluator::attachForm($form, $settings, $info, $element->availableVariables());
}
@@ -214,17 +223,20 @@ class RulesDataUIText extends RulesDataUI implements RulesDataDirectInputFormInt
'#default_value' => $settings[$name],
'#required' => empty($info['optional']),
'#after_build' => array('rules_ui_element_fix_empty_after_build'),
'#rows' => 3,
);
return $form;
}
/**
* Implements RulesDataDirectInputFormInterface::render().
*/
public static function render($value) {
return array(
'content' => array('#markup' => check_plain($value)),
'#attributes' => array('class' => array('rules-parameter-text')),
);
}
}
/**
@@ -232,6 +244,9 @@ class RulesDataUIText extends RulesDataUI implements RulesDataDirectInputFormInt
*/
class RulesDataUITextToken extends RulesDataUIText {
/**
* Implements RulesDataDirectInputFormInterface::inputForm().
*/
public static function inputForm($name, $info, $settings, RulesPlugin $element) {
$form = parent::inputForm($name, $info, $settings, $element);
if ($form[$name]['#type'] == 'textarea') {
@@ -241,6 +256,7 @@ class RulesDataUITextToken extends RulesDataUIText {
}
return $form;
}
}
/**
@@ -248,6 +264,9 @@ class RulesDataUITextToken extends RulesDataUIText {
*/
class RulesDataUITextFormatted extends RulesDataUIText {
/**
* Implements RulesDataDirectInputFormInterface::inputForm().
*/
public static function inputForm($name, $info, $settings, RulesPlugin $element) {
$form = parent::inputForm($name, $info, $settings, $element);
$settings += array($name => isset($info['default value']) ? $info['default value'] : array('value' => NULL, 'format' => NULL));
@@ -259,21 +278,26 @@ class RulesDataUITextFormatted extends RulesDataUIText {
return $form;
}
/**
* Implements RulesDataDirectInputFormInterface::render().
*/
public static function render($value) {
return array(
'content' => array('#markup' => check_plain($value['value'])),
'#attributes' => array('class' => array('rules-parameter-text-formatted')),
);
}
}
/**
* UI for decimal data.
*/
class RulesDataUIDecimal extends RulesDataUIText {
/**
* Implements RulesDataDirectInputFormInterface::inputForm().
*/
public static function inputForm($name, $info, $settings, RulesPlugin $element) {
$form = parent::inputForm($name, $info, $settings, $element);
if (empty($info['options list'])) {
@@ -283,6 +307,7 @@ class RulesDataUIDecimal extends RulesDataUIText {
$form[$name]['#rows'] = 1;
return $form;
}
}
/**
@@ -290,6 +315,9 @@ class RulesDataUIDecimal extends RulesDataUIText {
*/
class RulesDataUIInteger extends RulesDataUIText {
/**
* Implements RulesDataDirectInputFormInterface::inputForm().
*/
public static function inputForm($name, $info, $settings, RulesPlugin $element) {
$form = parent::inputForm($name, $info, $settings, $element);
if (empty($info['options list'])) {
@@ -298,6 +326,7 @@ class RulesDataUIInteger extends RulesDataUIText {
$form[$name]['#element_validate'][] = 'rules_ui_element_integer_validate';
return $form;
}
}
/**
@@ -305,6 +334,9 @@ class RulesDataUIInteger extends RulesDataUIText {
*/
class RulesDataUIIPAddress extends RulesDataUIText {
/**
* Implements RulesDataDirectInputFormInterface::inputForm().
*/
public static function inputForm($name, $info, $settings, RulesPlugin $element) {
$form = parent::inputForm($name, $info, $settings, $element);
if (empty($info['options list'])) {
@@ -315,6 +347,7 @@ class RulesDataUIIPAddress extends RulesDataUIText {
$form[$name]['#rows'] = 1;
return $form;
}
}
/**
@@ -322,10 +355,16 @@ class RulesDataUIIPAddress extends RulesDataUIText {
*/
class RulesDataUIBoolean extends RulesDataUI implements RulesDataDirectInputFormInterface {
/**
* Overrides RulesDataUI::getDefaultMode().
*/
public static function getDefaultMode() {
return 'input';
}
/**
* Implements RulesDataDirectInputFormInterface::inputForm().
*/
public static function inputForm($name, $info, $settings, RulesPlugin $element) {
$settings += array($name => isset($info['default value']) ? $info['default value'] : NULL);
// Note: Due to the checkbox even optional parameter always receive a value.
@@ -340,12 +379,16 @@ class RulesDataUIBoolean extends RulesDataUI implements RulesDataDirectInputForm
return $form;
}
/**
* Implements RulesDataDirectInputFormInterface::render().
*/
public static function render($value) {
return array(
'content' => array('#markup' => !empty($value) ? t('true') : t('false')),
'#attributes' => array('class' => array('rules-parameter-boolean')),
);
}
}
/**
@@ -353,6 +396,9 @@ class RulesDataUIBoolean extends RulesDataUI implements RulesDataDirectInputForm
*/
class RulesDataUIDate extends RulesDataUIText {
/**
* Implements RulesDataDirectInputFormInterface::inputForm().
*/
public static function inputForm($name, $info, $settings, RulesPlugin $element) {
$settings += array($name => isset($info['default value']) ? $info['default value'] : (empty($info['optional']) ? gmdate('Y-m-d H:i:s', time()) : NULL));
@@ -369,11 +415,14 @@ class RulesDataUIDate extends RulesDataUIText {
array('%format' => gmdate('Y-m-d H:i:s', time() + 86400),
'!strtotime' => l('strtotime()', 'http://php.net/strtotime')));
//TODO: Leverage the jquery datepicker+timepicker once a module providing
//the timpeicker is available.
// @todo Leverage the jquery datepicker+timepicker once a module providing
// The timepicker is available.
return $form;
}
/**
* Implements RulesDataDirectInputFormInterface::render().
*/
public static function render($value) {
$value = is_numeric($value) ? format_date($value, 'short') : check_plain($value);
return array(
@@ -381,6 +430,7 @@ class RulesDataUIDate extends RulesDataUIText {
'#attributes' => array('class' => array('rules-parameter-date')),
);
}
}
/**
@@ -388,6 +438,9 @@ class RulesDataUIDate extends RulesDataUIText {
*/
class RulesDataUIDuration extends RulesDataUIText {
/**
* Implements RulesDataDirectInputFormInterface::inputForm().
*/
public static function inputForm($name, $info, $settings, RulesPlugin $element) {
$form = parent::inputForm($name, $info, $settings, $element);
$form[$name]['#type'] = 'rules_duration';
@@ -395,6 +448,9 @@ class RulesDataUIDuration extends RulesDataUIText {
return $form;
}
/**
* Implements RulesDataDirectInputFormInterface::render().
*/
public static function render($value) {
$value = is_numeric($value) ? format_interval($value) : check_plain($value);
return array(
@@ -402,6 +458,7 @@ class RulesDataUIDuration extends RulesDataUIText {
'#attributes' => array('class' => array('rules-parameter-duration')),
);
}
}
/**
@@ -409,12 +466,16 @@ class RulesDataUIDuration extends RulesDataUIText {
*/
class RulesDataUIURI extends RulesDataUIText {
/**
* Implements RulesDataDirectInputFormInterface::inputForm().
*/
public static function inputForm($name, $info, $settings, RulesPlugin $element) {
$form = parent::inputForm($name, $info, $settings, $element);
$form[$name]['#rows'] = 1;
$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'));
$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'));
return $form;
}
}
/**
@@ -422,11 +483,16 @@ class RulesDataUIURI extends RulesDataUIText {
*/
class RulesDataUIListText extends RulesDataUIText {
/**
* Overrides RulesDataUI::getDefaultMode().
*/
public static function getDefaultMode() {
return 'input';
}
/**
* Implements RulesDataDirectInputFormInterface::inputForm().
*
* @todo This does not work for inputting textual values including "\n".
*/
public static function inputForm($name, $info, $settings, RulesPlugin $element) {
@@ -447,12 +513,16 @@ class RulesDataUIListText extends RulesDataUIText {
return $form;
}
/**
* Implements RulesDataDirectInputFormInterface::render().
*/
public static function render($value) {
return array(
'content' => array('#markup' => check_plain(implode(', ', $value))),
'#attributes' => array('class' => array('rules-parameter-list')),
);
}
}
/**
@@ -460,6 +530,9 @@ class RulesDataUIListText extends RulesDataUIText {
*/
class RulesDataUIListInteger extends RulesDataUIListText {
/**
* Implements RulesDataDirectInputFormInterface::inputForm().
*/
public static function inputForm($name, $info, $settings, RulesPlugin $element) {
$settings += array($name => isset($info['default value']) ? $info['default value'] : NULL);
$form = parent::inputForm($name, $info, $settings, $element);
@@ -473,6 +546,7 @@ class RulesDataUIListInteger extends RulesDataUIListText {
}
return $form;
}
}
/**
@@ -480,6 +554,9 @@ class RulesDataUIListInteger extends RulesDataUIListText {
*/
class RulesDataUIListToken extends RulesDataUIListInteger {
/**
* Implements RulesDataDirectInputFormInterface::inputForm().
*/
public static function inputForm($name, $info, $settings, RulesPlugin $element) {
$form = parent::inputForm($name, $info, $settings, $element);
@@ -489,6 +566,7 @@ class RulesDataUIListToken extends RulesDataUIListInteger {
}
return $form;
}
}
/**
@@ -496,10 +574,16 @@ class RulesDataUIListToken extends RulesDataUIListInteger {
*/
class RulesDataUIEntity extends RulesDataUIText {
/**
* Overrides RulesDataUI::getDefaultMode().
*/
public static function getDefaultMode() {
return 'selector';
}
/**
* Implements RulesDataDirectInputFormInterface::inputForm().
*/
public static function inputForm($name, $info, $settings, RulesPlugin $element) {
$form = parent::inputForm($name, $info, $settings, $element);
if (empty($info['options list'])) {
@@ -515,6 +599,7 @@ class RulesDataUIEntity extends RulesDataUIText {
}
return $form;
}
}
/**
@@ -522,9 +607,13 @@ class RulesDataUIEntity extends RulesDataUIText {
*/
class RulesDataUIEntityExportable extends RulesDataUIEntity {
/**
* Overrides RulesDataUI::getDefaultMode().
*/
public static function getDefaultMode() {
return 'input';
}
}
/**
@@ -535,6 +624,9 @@ class RulesDataUIEntityExportable extends RulesDataUIEntity {
*/
class RulesDataUIBundleEntity extends RulesDataUIEntity implements RulesDataInputOptionsListInterface {
/**
* Overrides RulesDataUI::getDefaultMode().
*/
public static function getDefaultMode() {
return 'input';
}
@@ -554,6 +646,7 @@ class RulesDataUIBundleEntity extends RulesDataUIEntity implements RulesDataInpu
}
return $bundles;
}
}
/**
@@ -563,6 +656,9 @@ class RulesDataUIBundleEntity extends RulesDataUIEntity implements RulesDataInpu
*/
class RulesDataUITaxonomyVocabulary extends RulesDataUIEntity implements RulesDataInputOptionsListInterface {
/**
* Overrides RulesDataUI::getDefaultMode().
*/
public static function getDefaultMode() {
return 'input';
}
@@ -577,6 +673,7 @@ class RulesDataUITaxonomyVocabulary extends RulesDataUIEntity implements RulesDa
}
return $options;
}
}
/**
@@ -584,6 +681,9 @@ class RulesDataUITaxonomyVocabulary extends RulesDataUIEntity implements RulesDa
*/
class RulesDataUIListEntity extends RulesDataUIListInteger {
/**
* Implements RulesDataDirectInputFormInterface::inputForm().
*/
public static function inputForm($name, $info, $settings, RulesPlugin $element) {
$form = parent::inputForm($name, $info, $settings, $element);
if (empty($info['options list'])) {
@@ -598,4 +698,5 @@ class RulesDataUIListEntity extends RulesDataUIListInteger {
}
return $form;
}
}