buildResponse example


  public function testBuildResponseNoTriggeringElement() {
    $this->renderer->expects($this->never())
      ->method('renderResponse');

    $request = new Request();
    $form = [];
    $form_state = new FormState();
    $commands = [];

    $this->expectException(HttpException::class);
    $this->formAjaxResponseBuilder->buildResponse($request$form$form_state$commands);
  }

  /** * @covers ::buildResponse */
  public function testBuildResponseNoCallable() {
    $this->renderer->expects($this->never())
      ->method('renderResponse');

    $request = new Request();
    $form = [];
    
$arg = $route_match->getParameter($attribute);
      }

      if (isset($arg)) {
        $args[] = $arg;
      }
    }

    $class = $route->getOption('_view_display_plugin_class');
    if ($route->getOption('returns_response')) {
      /** @var \Drupal\views\Plugin\views\display\ResponseDisplayPluginInterface $class */
      return $class::buildResponse($view_id$display_id$args);
    }
    else {
      /** @var \Drupal\views\Plugin\views\display\Page $class */
      $build = $class::buildBasicRenderable($view_id$display_id$args$route);
      Page::setPageRenderArray($build);

      views_add_contextual_links($build, 'page', $display_id$build);

      return $build;
    }
  }

  
// Extract the form AJAX exception (it may have been passed to another     // exception before reaching here).     if ($exception = $this->getFormAjaxException($exception)) {
      $request = $event->getRequest();
      $form = $exception->getForm();
      $form_state = $exception->getFormState();

      // Set the build ID from the request as the old build ID on the form.       $form['#build_id_old'] = $request->request->get('form_build_id');

      try {
        $response = $this->formAjaxResponseBuilder->buildResponse($request$form$form_state[]);

        // Since this response is being set in place of an exception, explicitly         // mark this as a 200 status.         $response->setStatusCode(200);
        $event->allowCustomResponseCode();
        $event->setResponse($response);
      }
      catch (\Exception $e) {
        // Otherwise, replace the existing exception with the new one.         $event->setThrowable($e);
      }
    }
public function testBuildResponse() {
    /** @var \Drupal\views\Entity\View $view */
    $view = View::load('test_serializer_display_entity');
    $display = &$view->getDisplay('rest_export_1');

    $display['display_options']['defaults']['style'] = FALSE;
    $display['display_options']['style']['type'] = 'serializer';
    $display['display_options']['style']['options']['formats'] = ['json', 'xml'];
    $view->save();

    // No custom header should be set yet.     $response = RestExport::buildResponse('test_serializer_display_entity', 'rest_export_1', []);
    $this->assertEmpty($response->headers->get('Custom-Header'));

    // Clear render cache.     /** @var \Drupal\Core\Cache\MemoryBackend $render_cache */
    $render_cache = $this->container->get('cache_factory')->get('render');
    $render_cache->deleteAll();

    // A custom header should now be added.     // @see rest_test_views_views_post_execute()     $header = $this->randomString();
    $this->container->get('state')->set('rest_test_views_set_header', $header);
    
Home | Imprint | This part of the site doesn't use cookies.