You are here

function restful_get_restful_handler_by_name in RESTful 7

Return the handler based on major and minor version, and resource name.

Parameters

$plugin_name: The name of the plugin, including version. (e.g. "articles__1_2").

Return value

RestfulInterface The handler object if found, or NULL.

Throws

\RestfulException

2 calls to restful_get_restful_handler_by_name()
RestfulListTestCase::testSort in tests/RestfulListTestCase.test
Test the sorting of entities.
restful_get_restful_handler in ./restful.module
Return the handler based on major and minor version, and resource name.

File

./restful.module, line 299

Code

function restful_get_restful_handler_by_name($plugin_name) {
  ctools_include('plugins');
  $plugin = ctools_get_plugins('restful', 'restful', $plugin_name);
  if (!($class = ctools_plugin_load_class('restful', 'restful', $plugin_name, 'class'))) {
    throw new \RestfulServiceUnavailable(format_string('Restful plugin class (@plugin) was not found.', array(
      '@plugin' => $plugin_name,
    )));
  }
  $handler = new $class($plugin);

  // If the restful plugin needs authentication load the corresponding
  // authentication plugin.
  // Handler set explicitly to allow all authentication types.
  $auth_plugins = $plugin['authentication_types'] === TRUE ? array_keys(restful_get_authentication_plugins()) : $plugin['authentication_types'];

  // We can have multiple authentication plugins.
  foreach ($auth_plugins as $auth_plugin_name) {
    $auth_handler = restful_get_authentication_handler($auth_plugin_name);
    $handler
      ->getAuthenticationManager()
      ->addAuthenticationProvider($auth_handler);
  }

  // Set the "optional" flag of the authentication manager.
  $handler
    ->getAuthenticationManager()
    ->setIsOptional($plugin['authentication_optional']);
  return $handler;
}