function views_php_form_element in Views PHP 6
Same name and namespace in other branches
- 8 views_php.module \views_php_form_element()
- 7.2 views_php.module \views_php_form_element()
- 7 views_php.module \views_php_form_element()
Helper function; builds form for PHP code options of views handlers/plugins.
6 calls to views_php_form_element()
- views_php_handler_area::options_form in plugins/
views/ views_php_handler_area.inc - Implements views_handler#option_definition().
- views_php_handler_field::options_form in plugins/
views/ views_php_handler_field.inc - Implements views_handler#options_form().
- views_php_handler_filter::options_form in plugins/
views/ views_php_handler_filter.inc - Implements views_handler#option_definition().
- views_php_handler_sort::options_form in plugins/
views/ views_php_handler_sort.inc - Implements views_handler#option_definition().
- views_php_plugin_access::options_form in plugins/
views/ views_php_plugin_access.inc - Implements views_plugin#options_form().
File
- ./
views_php.module, line 42 - Allows to use PHP in views.
Code
function views_php_form_element($handler, $checkbox = FALSE, $input, $variables = array(), $parents = array(
'options',
)) {
static $default_variables;
if (!isset($default_variables)) {
$default_variables = array(
'$view' => t('The view object.'),
'$handler' => t('The handler object.'),
'$plugin' => t('The plugin object.'),
'$static' => t('A variable that can be used to store reusable data per row.'),
'$row' => t('Contains the normalized record with consistent field name (e.g. $row->title).'),
'$data' => t('Contains the raw record as created by Views (e.g. $data->nid).'),
'$results' => t('Array containing the view\'s result.'),
'$cache' => t('The cache object.'),
);
}
list($name, $title, $description, $use_delimiters) = $input;
$container = array(
'#parents' => $parents,
);
if (!empty($checkbox)) {
list($checkbox_name, $checkbox_title, $checkbox_description) = $checkbox;
$checkbox = array(
'#type' => 'checkbox',
'#title' => $checkbox_title,
'#description' => $checkbox_description,
'#default_value' => $handler->options[$checkbox_name] && !empty($handler->options[$name]),
);
}
$container[$name] = array(
'#type' => 'textarea',
'#id' => str_replace('_', '-', 'edit-options-' . $name),
'#title' => $title,
'#default_value' => $handler->options[$name],
'#rows' => 5,
'#description' => $description . ' <strong>' . ($use_delimiters ? t('Use <?php ?> delimiters to enclose PHP code.') : t('Do not use <?php ?> delimiters.')) . '</strong>',
);
// Only users with use PHP permission can set/modify input.
if (!user_access('Use PHP input for field settings (dangerous - grant with care)')) {
$container[$name]['#disabled'] = TRUE;
$container[$name]['#value'] = $container[$name]['#default_value'];
$container[$name]['#description'] .= ' <strong>' . t('You do not have permission to modify this.') . '</strong>';
}
$items = array();
foreach ($variables as $variable_name => $description) {
if (is_int($variable_name)) {
$variable_name = $description;
$description = isset($default_variables[$description]) ? $default_variables[$description] : '';
}
$items[] = l($variable_name, '', array(
'fragment' => $container[$name]['#id'],
'external' => TRUE,
)) . ': ' . $description;
if (strpos($variable_name, '$row') === 0) {
foreach ($handler->view->display_handler
->get_handlers('field') as $field => $field_handler) {
$title = $field_handler
->label();
if (empty($title)) {
$title = $field_handler
->ui_name();
}
$items[] = l($variable_name . '->' . $field, '', array(
'fragment' => $container[$name]['#id'],
'external' => TRUE,
)) . ': ' . $title;
}
}
}
drupal_add_js(drupal_get_path('module', 'views_php') . '/views_php.js');
$container[$name . '_variables'] = array(
'#type' => 'fieldset',
'#title' => t('Available variables'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#attributes' => array(
'class' => array(
'views-php-variables',
),
),
);
$container[$name . '_variables']['variables'] = array(
'#value' => theme('item_list', $items),
);
if (!empty($checkbox)) {
return array(
$checkbox_name => $checkbox,
$name => $container,
);
}
return array(
$name => $container,
);
}