未找到 Drupal 8.7.8 自定义模块创建 Rest 资源 (API)
Drupal 8.7.8 Custome Module Created Rest Resource (API) not found
目录结构:
module_name -> config -> install -> rest.resource.location_api.yml
id: location_api
plugin_id: location_api
granularity: resource
configuration:
methods:
- GET
- POST
- PATCH
- DELETE
formats:
- json
authentication:
- cookie
module_name/src/plugin/rest/resource/LocationApi.php
<?php
namespace Drupal\locations\Plugin\rest\resource;
use Drupal\rest\Plugin\ResourceBase;
use Drupal\rest\ResourceResponse;
use Drupal\Core\Controller\ControllerBase;
//use Drupal\node\Entity\Node;
//use Drupal\taxonomy\Entity\Term;
use Drupal\user\Entity\User;
//use Drupal\Core\Database\Connection;
use Symfony\Component\HttpFoundation\JsonResponse;
/**
* Provides a KDR's Rest Custom Resource For Locations
*
* @RestResource(
* id = "location_api",
* label = @Translation("KDR's Rest Custom Resource For Location"),
* uri_paths = {
* "canonical" = "/kdr-apis/v1.0/location/{sl_id}",
* "https://www.drupal.org/link-relations/create" = "/kdr-apis/v1.0/location"
* }
* )
*/
class LocationApi extends ResourceBase {
}
但是当我安装模块时,returns出错,
留言
Drupal\Component\Plugin\Exception\PluginNotFoundException: The "entity_bundle:node" plugin does not exist. Valid plugin IDs for Drupal\Core\Condition\ConditionManager are: node_type, request_path, current_theme, user_role in Drupal\Core\Plugin\DefaultPluginManager->doGetDefinition() (line 53 of /home/linuxdem/kdr.linuxdemos.me/core/lib/Drupal/Component/Plugin/Discovery/DiscoveryTrait.php).
这是 Drupal 8 缓存问题,我已通过清除缓存并重新安装模块解决。
目录结构:
module_name -> config -> install -> rest.resource.location_api.yml
id: location_api
plugin_id: location_api
granularity: resource
configuration:
methods:
- GET
- POST
- PATCH
- DELETE
formats:
- json
authentication:
- cookie
module_name/src/plugin/rest/resource/LocationApi.php
<?php
namespace Drupal\locations\Plugin\rest\resource;
use Drupal\rest\Plugin\ResourceBase;
use Drupal\rest\ResourceResponse;
use Drupal\Core\Controller\ControllerBase;
//use Drupal\node\Entity\Node;
//use Drupal\taxonomy\Entity\Term;
use Drupal\user\Entity\User;
//use Drupal\Core\Database\Connection;
use Symfony\Component\HttpFoundation\JsonResponse;
/**
* Provides a KDR's Rest Custom Resource For Locations
*
* @RestResource(
* id = "location_api",
* label = @Translation("KDR's Rest Custom Resource For Location"),
* uri_paths = {
* "canonical" = "/kdr-apis/v1.0/location/{sl_id}",
* "https://www.drupal.org/link-relations/create" = "/kdr-apis/v1.0/location"
* }
* )
*/
class LocationApi extends ResourceBase {
}
但是当我安装模块时,returns出错,
留言
Drupal\Component\Plugin\Exception\PluginNotFoundException: The "entity_bundle:node" plugin does not exist. Valid plugin IDs for Drupal\Core\Condition\ConditionManager are: node_type, request_path, current_theme, user_role in Drupal\Core\Plugin\DefaultPluginManager->doGetDefinition() (line 53 of /home/linuxdem/kdr.linuxdemos.me/core/lib/Drupal/Component/Plugin/Discovery/DiscoveryTrait.php).
这是 Drupal 8 缓存问题,我已通过清除缓存并重新安装模块解决。