/** * Implements ResourceInterface::routes(). */ public function routes() { $collection = parent::routes(); $path_prefix = strtr($this->pluginId, ':', '/'); $route_name = strtr($this->pluginId, ':', '.'); $methods = $this->getAnnotatedMethods(); foreach ($methods as $method) { $lower_method = strtolower($method); $annotation = $this->getMethodAnnotation($method); $route = new Route('/' . $annotation['uri'], array('_controller' => 'Drupal\\services\\AnnotationRequestHandler::handle', '_plugin' => $this->pluginId), array('_method' => $annotation['httpMethod'], '_operation' => $method, '_permission' => 'access content')); $collection->add("{$route_name}.{$lower_method}", $route); } return $collection; }
/** * {@inheritdoc} */ protected function getBaseRoute($canonical_path, $method) { $route = parent::getBaseRoute($canonical_path, $method); $definition = $this->getPluginDefinition(); $parameters = $route->getOption('parameters') ?: array(); $parameters[$definition['entity_type']]['type'] = 'entity:' . $definition['entity_type']; $route->setOption('parameters', $parameters); return $route; }
/** * {@inheritdoc} */ public function availableMethods() { $methods = parent::availableMethods(); if ($this->isConfigEntityResource()) { // Currently only GET is supported for Config Entities. // @todo Remove when supported https://www.drupal.org/node/2300677 $unsupported_methods = ['POST', 'PUT', 'DELETE', 'PATCH']; $methods = array_diff($methods, $unsupported_methods); } return $methods; }
/** * Constructs a Drupal\rest\Plugin\ResourceBase object. * * @param array $configuration * A configuration array containing information about the plugin instance. * @param string $plugin_id * The plugin_id for the plugin instance. * @param mixed $plugin_definition * The plugin implementation definition. * @param array $serializer_formats * The available serialization formats. * @param \Psr\Log\LoggerInterface $logger * A logger instance. */ public function __construct(array $configuration, $plugin_id, $plugin_definition, array $serializer_formats, LoggerInterface $logger, EntityManagerInterface $entity_manager, AccountProxyInterface $current_user) { parent::__construct($configuration, $plugin_id, $plugin_definition, $serializer_formats, $logger); $this->entityManager = $entity_manager; $this->currentUser = $current_user; }
/** * Constructs a Drupal\rest\Plugin\ResourceBase object. * * @param array $configuration * A configuration array containing information about the plugin instance. * @param string $plugin_id * The plugin_id for the plugin instance. * @param mixed $plugin_definition * The plugin implementation definition. * @param array $serializer_formats * The available serialization formats. * @param \Psr\Log\LoggerInterface $logger * A logger instance. * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager * An instance of entity manager. * @param \Drupal\Core\Menu\MenuLinkTreeInterface $menu_tree * The menu tree service. */ public function __construct(array $configuration, $plugin_id, $plugin_definition, array $serializer_formats, LoggerInterface $logger, EntityManagerInterface $entity_manager, MenuLinkTreeInterface $menu_tree) { parent::__construct($configuration, $plugin_id, $plugin_definition, $serializer_formats, $logger); $this->entityManager = $entity_manager; $this->menuTree = $menu_tree; }
/** * {@inheritdoc} */ public function routes() { $collection = parent::routes(); // ResourceBase class has no support PUT method by some reason. $definition = $this->getPluginDefinition(); $canonical_path = $definition['uri_paths']['canonical']; $route = $this->getBaseRoute($canonical_path, 'PUT'); $route->addRequirements(array('_content_type_format' => implode('|', $this->serializerFormats))); $collection->add('example_foo.PUT', $route); return $collection; }