1 utility.inc _views_create_handler($definition, $type = 'handler', $handler_type = NULL)

Instantiate and construct a new handler

File

core/modules/views/includes/utility.inc, line 10
Utility functions for assembling Views queries.

Code

function _views_create_handler($definition, $type = 'handler', $handler_type = NULL) {
  if (empty($definition['handler'])) {
    watchdog('views', '_views_create_handler - type: @type - failed: handler has not been provided.', 
    array('@type' => isset($handler_type) ? ($type . '(handler type: ' . $handler_type . ')') : $type)
    );
    return;
  }

  // class_exists will automatically load the code file.
  if (!empty($definition['override handler']) && !class_exists($definition['override handler'])) {
    watchdog('views', 
    '_views_create_handler - loading override handler @type failed: class @override_handler could not be loaded. ' .
      'Verify the class file has been registered in the corresponding .info-file (files[]).', 
    array(
      '@type' => isset($handler_type) ? ($type . '(handler type: ' . $handler_type . ')') : $type,
      '@override_handler' => $definition['override handler']
    )
    );
    return;
  }

  if (!class_exists($definition['handler'])) {
    watchdog('views', 
    '_views_create_handler - loading handler @type failed: class @handler could not be loaded. ' .
      'Verify the class file has been registered in the corresponding .info-file (files[]).', 
    array(
      '@type' => isset($handler_type) ? ($type . '(handler type: ' . $handler_type . ')') : $type,
      '@handler' => $definition['handler']
    )
    );
    return;
  }

  if (!empty($definition['override handler'])) {
    $handler = new $definition['override handler'];
  }
  else {
    $handler = new $definition['handler'];
  }

  $handler->set_definition($definition);
  if ($type == 'handler') {
    $handler->is_handler = TRUE;
    $handler->handler_type = $handler_type;
  }
  else {
    $handler->is_plugin = TRUE;
    $handler->plugin_type = $type;
    $handler->plugin_name = $definition['name'];
  }

  // Let the handler have something like a constructor.
  $handler->construct();

  return $handler;
}