Skip to content
Snippets Groups Projects
Commit e00b8c6a authored by fago's avatar fago
Browse files

added a new date data type,

added the possibility to specify longer help in an extra callback
parent 52337ef1
No related branches found
No related tags found
No related merge requests found
......@@ -4,6 +4,8 @@
* @file rules integration for the rules module
*/
define('RULES_DATE_REGEX_LOOSE', '/^(\d{4})-?(\d{2})-?(\d{2})([T\s]?(\d{2}):?(\d{2}):?(\d{2})?)?$/');
/**
* Implementation of hook_rules_data_type_info()
*/
......@@ -21,6 +23,12 @@ function rules_rules_data_type_info() {
'identifiable' => FALSE,
'eval input' => TRUE,
),
'date' => array(
'label' => t('Date'),
'class' => 'rules_data_type_date',
'identifiable' => FALSE,
'eval input' => TRUE,
),
'boolean' => array(
'label' => t('Truth value'),
'class' => 'rules_data_type_boolean',
......@@ -68,6 +76,31 @@ class rules_data_type_number extends rules_data_type_string {
}
}
/**
* Rules date data type
*/
class rules_data_type_date extends rules_data_type_string {
function get_default_input_form($info, $value) {
$info += array('long' => FALSE, 'required' => TRUE, 'description' => '');
$value = isset($value) ? $value : date('Y-m-d H:i:s', time() + 86400);
$info['description'] .= ' '. t('Format: %format or a timestamp in GMT. ', array('%format' => date('Y-m-d H:i:s', time() + 86400)));
$info['description'] .= '<br />'. t('E.g. use !code together with the PHP input evalutor to specify a date one day after the evaluation time. ', array('!code' => '<pre>'. check_plain('<?php echo time() + 86400 * 1; ?>'). '</pre>'));
return parent::get_default_input_form($info, $value);
}
function check_value($info, $value) {
if (is_numeric($value)) {
$value = date('Y-m-d H:i:s', $value);
}
if (is_string($value) && preg_match(RULES_DATE_REGEX_LOOSE, $value)) {
return $value;
}
rules_log(t('The argument %label is no valid date.', array('%label' => $info['label'])));
}
}
/**
* Rules boolean data type
*/
......@@ -79,7 +112,7 @@ class rules_data_type_boolean extends rules_data_type_string {
function get_default_input_form($info, $value) {
$info += array('long' => FALSE, 'required' => TRUE, 'description' => '');
$info['description'] = t('Just enter 1 for TRUE, 0 for FALSE or make use of an input evaluator.') . ' ' . $info['description'];
$info['description'] .= ' '. t('Just enter 1 for TRUE, 0 for FALSE or make use of an input evaluator.');
return parent::get_default_input_form($info, isset($value) ? $value : 1);
}
}
......
......@@ -809,10 +809,17 @@ function rules_admin_map_get_configured_argument($name, $element) {
function rules_admin_element_help(&$form, $element) {
$info = rules_get_element_info($element);
if (isset($info['help']) || isset($element['help'])) {
$help = isset($element['help']) ? $element['help'] : $info['help'];
}
else if (isset($element['#type']) && in_array($element['#type'], array('action', 'condition'))) {
rules_include('rules_forms');
$help = rules_element_invoke($element, 'help', array());
}
if (isset($help) && $help) {
$form['help'] = array(
'#type' => 'fieldset',
'#title' => t('Description'),
'#description' => isset($element['help']) ? $element['help'] : $info['help'],
'#description' => $help,
);
}
}
......
......@@ -66,7 +66,7 @@ function rules_get_variables($names, &$state, $load = TRUE, $element = NULL) {
else if (isset($element['#info']['arguments'][$name]) && array_key_exists('default value', $element['#info']['arguments'][$name])) {
$args[$name] = $element['#info']['arguments'][$name]['default value'];
}
else {
if (!isset($args[$name])) {
return FALSE;
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment