--- nodereference.module.orig 2009-04-15 11:00:07.000000000 +1000 +++ nodereference.module 2009-04-27 12:59:54.000000000 +1000 @@ -114,6 +114,29 @@ function nodereference_field_settings($o '#required' => FALSE, '#description' => t('Provide a comma separated list of arguments to pass to the view.'), ); + $form['advanced']['code'] = array( + '#type' => 'fieldset', + '#title' => t('PHP code'), + '#collapsible' => TRUE, + '#collapsed' => empty($field['advanced_view_args_php']), + ); + if (user_access('Use PHP input for field settings (dangerous - grant with care)')) { + $form['advanced']['code']['advanced_view_args_php'] = array( + '#type' => 'textarea', + '#title' => t('Code'), + '#default_value' => !empty($field['advanced_view_args_php']) ? $field['advanced_view_args_php'] : '', + '#rows' => 6, + '#description' => t('Advanced Usage Only: PHP code that returns a keyed array of view arguments. Should not include <?php ?> delimiters. If this field is filled out, the array returned by this code will override the view arguments above.'), + ); + } + else { + $form['advanced']['code']['markup_advanced_view_args_php'] = array( + '#type' => 'item', + '#title' => t('Code'), + '#value' => !empty($field['advanced_view_args_php']) ? ''. check_plain($field['advanced_view_args_php']) .'' : t('<none>'), + '#description' => empty($field['advanced_view_args_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.'), + ); + } } else { $form['advanced']['no_view_help'] = array( @@ -129,6 +152,7 @@ function nodereference_field_settings($o if (module_exists('views')) { $settings[] = 'advanced_view'; $settings[] = 'advanced_view_args'; + $settings[] = 'advanced_view_args_php'; } return $settings; @@ -808,7 +832,12 @@ function _nodereference_potential_refere $view->display_handler->set_option('items_per_page', $limit); // Get arguments for the view. - if (!empty($field['advanced_view_args'])) { + if (!empty($field['advanced_view_args_php'])) { + ob_start(); + $view_args = eval($field['advanced_view_args_php']); + ob_end_clean(); + } + elseif (!empty($field['advanced_view_args'])) { // TODO: Support Tokens using token.module ? $view_args = array_map('trim', explode(',', $field['advanced_view_args'])); }