Permalink
Browse files

Added a path argument.

  • Loading branch information...
pmelab committed Aug 9, 2017
1 parent c06d828 commit 9a862aa6b01f43c01dd4b00a24df65ef60155b19
Showing with 9 additions and 6 deletions.
  1. +9 −6 src/Plugin/GraphQL/Fields/PageTitle.php
@@ -4,6 +4,7 @@
use Drupal\graphql_core\GraphQL\FieldPluginBase;
use Symfony\Cmf\Component\Routing\RouteObjectInterface;
use Symfony\Component\HttpFoundation\Request;
use Youshido\GraphQL\Execution\ResolveInfo;
/**
@@ -16,7 +17,10 @@
* type = "String",
* name = "pageTitle",
* nullable = true,
* multi = false
* multi = false,
* arguments = {
* "path" = "String",
* }
* )
*/
class PageTitle extends FieldPluginBase {
@@ -25,14 +29,13 @@ class PageTitle extends FieldPluginBase {
* {@inheritdoc}
*/
protected function resolveValues($value, array $args, ResolveInfo $info) {
// Get the current Druapl request.
$request = \Drupal::request();
$request = Request::create($args['path']);
$route = \Drupal::service('router.no_access_checks')->matchRequest($request);
// Get the request route.
if ($route = $request->attributes->get(RouteObjectInterface::ROUTE_OBJECT)) {
if (isset($route[RouteObjectInterface::ROUTE_OBJECT])) {
// If there is a route, yield the generated title.
yield \Drupal::service('title_resolver')->getTitle($request, $route);
yield \Drupal::service('title_resolver')->getTitle($request, $route[RouteObjectInterface::ROUTE_OBJECT]);
}
}

0 comments on commit 9a862aa

Please sign in to comment.