RESTful-Drupal / restful

RESTful best practices for Drupal
https://drupal.org/project/restful
419 stars 173 forks source link

Plugin ID 'json_api' was not found. #1067

Closed OnGitHubSchatz closed 3 years ago

OnGitHubSchatz commented 3 years ago

/login-token with correct params returns a response with:

"title": "Plugin ID 'json_api' was not found.",
"status": 503,

$ drush vget restful_default_output_formatter restful_default_output_formatter: json_api

So the config is set properly and I see this plugin class in the registry.

Tried registry-rebuild, disable/enable and other permutations.

OnGitHubSchatz commented 3 years ago

I found a workaround by manually setting the plugin definitions with a hook cribbed from the 'plug' module:

function test_module_formatter_plugin_alter(&$plugins) {
    $plugin_manager = FormatterPluginManager::create();

    $lost_defs = array(
            'json_api' => array ( 'id' => 'json_api', 'label' => 'JSON API', 'description' => 'Output in using the JSON API format.', 'class' => 'Drupal\restful\Plugin\formatter\FormatterJsonApi', 'provider' => 'restful', ),
            'hal_json' => array ( 'id' => 'hal_json', 'label' => 'HAL+JSON', 'description' => 'Output in using the HAL conventions and JSON format.', 'curie' => array ( 'name' => 'hal', 'path' => 'doc/rels', 'template' => '/{rel}', ), 'class' => 'Drupal\restful\Plugin\formatter\FormatterHalJson', 'provider' => 'restful', ), 
            'single_json' => array ( 'id' => 'single_json', 'label' => 'Single JSON', 'description' => 'Output a single item using the JSON format.', 'class' => 'Drupal\restful\Plugin\formatter\FormatterSingleJson', 'provider' => 'restful', ),
            'json' => array ( 'id' => 'json', 'label' => 'Simple JSON', 'description' => 'Output in using the JSON format.', 'class' => 'Drupal\restful\Plugin\formatter\FormatterJson', 'provider' => 'restful', ) 
    );

    foreach ($lost_defs as $base_def) {
        $plugin_manager->processDefinition($base_def);
        $plugins[$base_def['id']] = $base_def;
    }
}

Still no clue why doGetDefinition() fails to find anything for plugin formatters specifically in my environment.