You are here

public function UserLogout::processRequest in Services 8.4

Same name and namespace in other branches
  1. 9.0.x src/Plugin/ServiceDefinition/UserLogout.php \Drupal\services\Plugin\ServiceDefinition\UserLogout::processRequest()

Processes the request and returns an array of data as appropriate.

Parameters

\Symfony\Component\HttpFoundation\Request $request: The request object.

\Drupal\Core\Routing\RouteMatchInterface $route_match: The route match object.

\Symfony\Component\Serializer\SerializerInterface $serializer: The serializer. Some methods might require the plugin to leverage the serializer after extracting the request contents.

Return value

array The response.

Throws

\Symfony\Component\HttpKernel\Exception\HttpException

Overrides ServiceDefinitionInterface::processRequest

File

src/Plugin/ServiceDefinition/UserLogout.php, line 38

Class

UserLogout
Plugin annotation @ServiceDefinition( id = "user_logout", methods = { "POST" }, title = @Translation("User logout"), description = @Translation("Allows users to logout."), category = @Translation("User"), path = "user/logout" )

Namespace

Drupal\services\Plugin\ServiceDefinition

Code

public function processRequest(Request $request, RouteMatchInterface $route_match, SerializerInterface $serializer) {
  user_logout();
  $this
    ->messenger()
    ->addMessage(t('User successfully logged out'), 'status', FALSE);
  return [];
}