Commit 3ae89682 authored by yched's avatar yched

#227951 by pwolanin : Add a permission for PHP 'default values' and 'allowed values'

parent d748fcb7
......@@ -8,6 +8,7 @@ Bugfix
General
- #198420 Make sure internal field and widget names are truncated to 32 characters to match the database values.
- #227951 by pwolanin : Add a permission for PHP 'default values' and 'allowed values'
Field / widget modules
- #140687 OptionWidgets : fix 'single checkbox' stick on checked when used with text values.
......
......@@ -47,6 +47,7 @@ function content_perm() {
$perms[] = 'create '. $name .' content';
$perms[] = 'edit own '. $name .' content';
$perms[] = 'edit '. $name .' content';
$perms[] = 'Use PHP input for field settings (dangerous - grant with care)';
}
return $perms;
}
......
......@@ -956,26 +956,37 @@ function _content_admin_field($type_name, $field_name) {
'#collapsible' => TRUE,
'#collapsed' => empty($field['widget']['default_value_php']),
);
$db_info = content_database_info($field);
$columns = array_keys($db_info['columns']);
foreach ($columns as $key => $column) {
$columns[$key] = "'$column' => value for $column";
if (user_access('Use PHP input for field settings (dangerous - grant with care)')) {
$db_info = content_database_info($field);
$columns = array_keys($db_info['columns']);
foreach ($columns as $key => $column) {
$columns[$key] = "'$column' => value for $column";
}
$sample = 'array(
0 => array('. implode(', ', $columns) .'),
// You\'ll usually want to stop here. Provide more values
// if you want your \'default value\' to be multi-valued :
1 => array('. implode(', ', $columns) .'),
2 => ...
);';
$form['widget']['default_value_fieldset']['advanced_options']['default_value_php'] = array(
'#type' => 'textarea',
'#title' => t('Code'),
'#default_value' => isset($field['widget']['default_value_php']) ? $field['widget']['default_value_php'] : '',
'#rows' => 6,
'#tree' => TRUE,
'#description' => t('Advanced Usage Only: PHP code that returns a default value. Should not include &lt;?php ?&gt; delimiters. If this field is filled out, the value returned by this code will override any value specified above. Expected format :<pre>%sample</pre>Using %link_devel\'s \'devel load\' tab on a %type content page might help you figure out the expected format.', array('%sample' => $sample, '%link_devel' => l('devel.module', 'http://www.drupal.org/project/devel'), '%type' => theme('placeholder', check_plain($type_name)))),
);
}
else {
$form['widget']['default_value_fieldset']['advanced_options']['markup_default_value_php'] = array(
'#type' => 'item',
'#title' => t('Code'),
'#value' => !empty($field['widget']['default_value_php']) ? '<code>'. check_plain($field['widget']['default_value_php']) .'</code>' : t('&lt;none&gt;'),
'#description' => empty($field['widget']['default_value_php']) ? t("You're not allowed to input PHP code.") : t('This PHP code was set by an administrator and will override any value specified above.'),
);
}
$sample = 'array(
0 => array('. implode(', ', $columns) .'),
// You\'ll usually want to stop here. Provide more values
// if you want your \'default value\' to be multi-valued :
1 => array('. implode(', ', $columns) .'),
2 => ...
);';
$form['widget']['default_value_fieldset']['advanced_options']['default_value_php'] = array(
'#type' => 'textarea',
'#title' => t('Code'),
'#default_value' => $field['widget']['default_value_php'],
'#rows' => 6,
'#tree' => TRUE,
'#description' => t('Advanced Usage Only: PHP code that returns a default value. Should not include &lt;?php ?&gt; delimiters. If this field is filled out, the value returned by this code will override any value specified above. Expected format :<pre>%sample</pre>Using %link_devel\'s \'devel load\' tab on a %type content page might help you figure out the expected format.', array('%sample' => $sample, '%link_devel' => l('devel.module', 'http://www.drupal.org/project/devel'), '%type' => theme('placeholder', check_plain($type_name)))),
);
}
$form['field'] = array(
......
......@@ -74,15 +74,26 @@ function number_field_settings($op, $field) {
'#type' => 'fieldset',
'#title' => t('Php code'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$form['advanced_options']['allowed_values_php'] = array(
'#type' => 'textarea',
'#title' => t('Code'),
'#default_value' => $field['allowed_values_php'],
'#rows' => 6,
'#description' => t('Advanced Usage Only: PHP code that returns a keyed array of allowed values. Should not include &lt;?php ?&gt; delimiters. If this field is filled out, the array returned by this code will override the allowed values list above.'),
'#collapsed' => empty($field['allowed_values_php']),
);
if (user_access('Use PHP input for field settings (dangerous - grant with care)')) {
$form['advanced_options']['allowed_values_php'] = array(
'#type' => 'textarea',
'#title' => t('Code'),
'#default_value' => !empty($field['allowed_values_php']) ? $field['allowed_values_php'] : '',
'#rows' => 6,
'#description' => t('Advanced Usage Only: PHP code that returns a keyed array of allowed values. Should not include &lt;?php ?&gt; delimiters. If this field is filled out, the array returned by this code will override the allowed values list above.'),
);
}
else {
$form['advanced_options']['markup_allowed_values_php'] = array(
'#type' => 'item',
'#title' => t('Code'),
'#value' => !empty($field['allowed_values_php']) ? '<code>'. check_plain($field['allowed_values_php']) .'</code>' : t('&lt;none&gt;'),
'#description' => empty($field['allowed_values_php']) ? t("You're not allowed to input PHP code.") : t('This PHP code was set by an administrator and will override the allowed values list above.'),
);
}
return $form;
case 'validate':
......
......@@ -58,15 +58,25 @@ function text_field_settings($op, $field) {
'#type' => 'fieldset',
'#title' => t('Php code'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$form['advanced_options']['allowed_values_php'] = array(
'#type' => 'textarea',
'#title' => t('Code'),
'#default_value' => $field['allowed_values_php'],
'#rows' => 6,
'#description' => t('Advanced Usage Only: PHP code that returns a keyed array of allowed values. Should not include &lt;?php ?&gt; delimiters. If this field is filled out, the array returned by this code will override the allowed values list above.'),
'#collapsed' => empty($field['allowed_values_php']),
);
if (user_access('Use PHP input for field settings (dangerous - grant with care)')) {
$form['advanced_options']['allowed_values_php'] = array(
'#type' => 'textarea',
'#title' => t('Code'),
'#default_value' => !empty($field['allowed_values_php']) ? $field['allowed_values_php'] : '',
'#rows' => 6,
'#description' => t('Advanced Usage Only: PHP code that returns a keyed array of allowed values. Should not include &lt;?php ?&gt; delimiters. If this field is filled out, the array returned by this code will override the allowed values list above.'),
);
}
else {
$form['advanced_options']['markup_allowed_values_php'] = array(
'#type' => 'item',
'#title' => t('Code'),
'#value' => !empty($field['allowed_values_php']) ? '<code>'. check_plain($field['allowed_values_php']) .'</code>' : t('&lt;none&gt;'),
'#description' => empty($field['allowed_values_php']) ? t("You're not allowed to input PHP code.") : t('This PHP code was set by an administrator and will override the allowed values list above.'),
);
}
return $form;
case 'save':
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment