Download & Extend

PHP Fatal error: Call to undefined method can_expose() in views/plugins/views_plugin_display.inc on line 1872

Project:Views
Version:6.x-2.x-dev
Component:exposed filters
Category:bug report
Priority:critical
Assigned:Unassigned
Status:closed (fixed)

Issue Summary

PHP Fatal error: Call to undefined method can_expose() in views/plugins/views_plugin_display.inc on line 1872

This error happens when trying to save the settings form for certain filters. It happened to us with User name filters and Date filters.

This is the original problem, I think. The following code found in views_plugin_display.inc:

<?php
 
/**
   * Check if the provided identifier is unique.
   */
 
function is_identifier_unique($id, $identifier) {  
    foreach (
views_object_types() as $type => $info) {
      foreach (
$this->get_handlers($type) as $key => $handler) {
        if (
$handler->can_expose() && $handler->is_exposed()) {
          if (
$id != $key && $identifier == $handler->options['expose']['identifier']) {
            return
FALSE;
          }
        }
      }
    }
    return
TRUE;
  }
?>

views_object_types() is defined in includes/view.inc and looks like this:

<?php
function views_object_types() {
  static
$retval = NULL;

 
// statically cache this so t() doesn't run a bajillion times.
 
if (!isset($retval)) {
   
$retval = array(
     
'field' => array(
       
'title' => t('Fields'), // title
       
'ltitle' => t('fields'), // lowercase title for mid-sentence
       
'stitle' => t('Field'), // singular title
       
'lstitle' => t('field'), // singular lowercase title for mid sentence
       
'plural' => 'fields',
      ),
     
'argument' => array(
       
'title' => t('Arguments'),
       
'ltitle' => t('arguments'),
       
'stitle' => t('Argument'),
       
'lstitle' => t('Argument'),
       
'plural' => 'arguments',
      ),
     
'sort' => array(
       
'title' => t('Sort criteria'),
       
'ltitle' => t('sort criteria'),
       
'stitle' => t('Sort criterion'),
       
'lstitle' => t('sort criterion'),
       
'plural' => 'sorts',
      ),
     
'filter' => array(
       
'title' => t('Filters'),
       
'ltitle' => t('filters'),
       
'stitle' => t('Filter'),
       
'lstitle' => t('filter'),
       
'plural' => 'filters',
       
'options' => 'views_ui_config_filters_form',
      ),
     
'relationship' => array(
       
'title' => t('Relationships'),
       
'ltitle' => t('relationships'),
       
'stitle' => t('Relationship'),
       
'lstitle' => t('Relationship'),
       
'plural' => 'relationships',
      ),
    );
  }

  return
$retval;
}
?>

This means the method is_identifier_unique() tries to invoke can_expose() for all handlers of all these types. However, can_expose() is not defined for all handlers.

I have added function can_expose() { return FALSE; } to views_handler class definition temporarily. Though, I'm not 100% sure this is correct.

Comments

#1

Status:active» needs review

Additional testing, and it seems to happen every time one tries to save an exposed filter. The visible symthom is that an error similar to the following is reported by AHAH handler:

An error occurred at admin/build/views/ajax/config-item/VIEWNAME/default/filter/field_xxxx_value_many_to_one.

Adding the following to views_handler class defined in includes/handlers.inc

<?php
 
function can_expose() { return FALSE; }
?>

#2

Status:needs review» reviewed & tested by the community

This is the original problem, I think. The following code found in views_plugin_display.inc:

Well, in fact, the problem is that #458140: Allow any handler to use exposed form was only committed for 3.x branch, and function can_expose() is not present in handlers.inc for 2.x version. But #363516: No validation to ensure exposed filter identifiers are unique was committed to 2.x and 3.x

As markus_petrus said, adding this function to views_handler solve the problem. Here is a patch.

AttachmentSize
views2-bug-623580.patch 634 bytes

#3

This makes 100% sense. A RTBC from me.

#4

Status:reviewed & tested by the community» fixed

Makes sense. Committed. Only with some extra spaces inside the { }

#5

Status:fixed» closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

nobody click here