function ResourceController::get

Same name in other branches
  1. 9 core/modules/media/tests/modules/media_test_oembed/src/Controller/ResourceController.php \Drupal\media_test_oembed\Controller\ResourceController::get()
  2. 8.9.x core/modules/media/tests/modules/media_test_oembed/src/Controller/ResourceController.php \Drupal\media_test_oembed\Controller\ResourceController::get()
  3. 11.x core/modules/media/tests/modules/media_test_oembed/src/Controller/ResourceController.php \Drupal\media_test_oembed\Controller\ResourceController::get()

Creates an oEmbed resource response.

Parameters

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

Return value

\Symfony\Component\HttpFoundation\Response The oEmbed resource response.

1 string reference to 'ResourceController::get'
media_test_oembed.routing.yml in core/modules/media/tests/modules/media_test_oembed/media_test_oembed.routing.yml
core/modules/media/tests/modules/media_test_oembed/media_test_oembed.routing.yml

File

core/modules/media/tests/modules/media_test_oembed/src/Controller/ResourceController.php, line 23

Class

ResourceController
Test controller returning oEmbed resources from Media's test fixtures.

Namespace

Drupal\media_test_oembed\Controller

Code

public function get(Request $request) {
    $asset_url = $request->query
        ->get('url');
    $resource = \Drupal::keyValue('media_test_oembed')->get($asset_url);
    if ($resource === 404) {
        $response = new Response('Not Found', 404);
    }
    else {
        $content = file_get_contents($resource);
        $response = new Response($content);
        $response->headers
            ->set('Content-Type', 'application/' . pathinfo($resource, PATHINFO_EXTENSION));
    }
    return $response;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.