[ Index ]

PHP Cross Reference of Drupal 6 (gatewave)

title

Body

[close]

/sites/all/modules/views/plugins/ -> views_plugin_argument_validate_php.inc (source)

   1  <?php
   2  // $Id: views_plugin_argument_validate_php.inc,v 1.1 2008/09/03 19:21:30 merlinofchaos Exp $
   3  /**
   4   * @file
   5   * Contains the php code argument validator plugin.
   6   */
   7  
   8  /**
   9   * Provide PHP code to validate whether or not an argument is ok.
  10   *
  11   * @ingroup views_argument_validate_plugins
  12   */
  13  class views_plugin_argument_validate_php extends views_plugin_argument_validate {
  14    var $option_name = 'validate_argument_php';
  15  
  16    function validate_form(&$form, &$form_state) {
  17      $form[$this->option_name] = array(
  18        '#type' => 'textarea',
  19        '#title' => t('PHP validate code'),
  20        '#default_value' => $this->get_argument(),
  21        '#description' => t('Enter PHP code that returns TRUE or FALSE. No return is the same as FALSE, so be SURE to return something if you do not want to declare the argument invalid. Do not use &lt;?php ?&gt;. The argument to validate will be "$argument" and the view will be "$view". You may change the argument by setting "$handler->argument".'),
  22        '#process' => array('views_process_dependency'),
  23        '#dependency' => array('edit-options-validate-type' => array($this->id)),
  24      );
  25  
  26      $this->check_access($form);
  27    }
  28  
  29    /**
  30     * Only let users with PHP block visibility permissions set/modify this
  31     * validate plugin.
  32     */
  33    function access() {
  34      return user_access('use PHP for block visibility');
  35    }
  36  
  37    function validate_argument($argument) {
  38      // set up variables to make it easier to reference during the argument.
  39      $view = &$this->view;
  40      $handler = &$this->argument;
  41  
  42      ob_start();
  43      $result = eval($this->argument->options[$this->option_name]);
  44      ob_end_clean();
  45      return $result;
  46    }
  47  }
  48  


Generated: Thu Mar 24 11:18:33 2011 Cross-referenced by PHPXref 0.7