I occasionally am getting an error that I can't figure out that references views.

warning: class_exists() expects parameter 1 to be string, array given in /sites/all/modules/views/includes/handlers.inc on line 17.

I've searched all over but can't find any information on this particular error.

CommentFileSizeAuthor
#3 jenkins_bytes.jpg13.61 KBdkinzer
#3 views_data_class_warning.jpg37.09 KBdkinzer

Comments

dawehner’s picture

What do you mean with "references views"?

I suggest you to update to 2.10 first.

cerup’s picture

Version: 6.x-2.9 » 6.x-2.10
Status: Active » Closed (fixed)

Sorry I marked this for the wrong version. I am on 2.10.

However, I narrowed this down to a problem with the date module so i'll close the issue here for the time being.

dkinzer’s picture

Title: warning: class_exists() expects parameter 1 to be string error » warning: class_exists() expects parameter 1 to be string error - How to override a views handler
Priority: Normal » Minor
Status: Closed (fixed) » Active
Issue tags: +views override handlers
StatusFileSize
new37.09 KB
new13.61 KB

I'm reopening this issue only to see if I can learn the correct way of overriding a handler in views.

I needed to override the 'views_handler_field_file_size' in order to add a custom format (@see img#1). So I defined my own handler and then I tried to override the filesize field default field handler by defining and returning this $data array:

  // filesize
  $data['files']['filesize'] = array(
    'field' => array(
      'handler' => 'rb_handler_field_file_size',
      'click sortable' => TRUE,
     ),
    'sort' => array(
      'handler' => 'views_handler_sort',
    ),
    'filter' => array(
      'handler' => 'views_handler_filter_numeric',
    ),
  );

But this cuased a problem with Views, because instead of using my handler for the 'filesize' field, it merged it's default handler with the one I gave into an array. This was causing views to return an error of "warning: class_exists() expects parameter 1 to be a string" (@see img#2).

I ended up creating a new psudo field and using it to accomplish my need:

  $data['files']['jenkins_filesize'] = array(
    'title' => t('J-Size'),
    'help' => t('The filesize field but with a special Jenkins formatter handler.'),
    'real field' => 'filesize',
    'field' => array(
      'handler' => 'rb_handler_field_file_size',
      'click sortable' => TRUE,
     ),
    'sort' => array(
      'handler' => 'views_handler_sort',
    ),
    'filter' => array(
      'handler' => 'views_handler_filter_numeric',
    ),
  );

That work.

But I'm still wondering if I just missed something and there was a way to override the default handler?

dawehner’s picture

Status: Active » Fixed
But this cuased a problem with Views, because instead of using my handler for the 'filesize' field, it merged it's default handler with the one I gave into an array. 

So you didn't used hook_views_data_alter. If you want to change something alter is nearly always the better use case

dkinzer’s picture

Thanks!

Status: Fixed » Closed (fixed)
Issue tags: -views override handlers

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