1

I had this piece of code in a module developed for some previous version of Drupal 8.

protected function getOutput() { $content = $this->buildContent(); //print_r($content); $page = array( '#theme' => 'html', '#page_object' => new Html(render($content)), ); $rendered_page = render($page); return $rendered_page; } 

Now, in the present beta release, it shows this error:

Fatal error: Class 'Drupal\hardcopy\Plugin\Html' not found in C:\xampp\htdocs\drupalbeta7\modules\custom\hardcopy\src\Plugin\HardcopyFormatBase.php on line 175

Can someone tell me how to pass the HTML of the whole page in the response object?

1 Answer 1

2

As D8 uses Symfony responses it's as simple as:

use Symfony\Component\HttpFoundation\Response; ... $response = new Response( 'Your HTML content here', Response::HTTP_OK, array('content-type' => 'text/html') ); return $response; 

See the docs for more information.

2
  • I think this will be useful to me(will be trying). Can help me with this I have generated an array containing information related to a node by using this: ($content = $this->entityManager()->getViewBuilder($entity->getEntityTypeId())->view($entity, 'copy');). But I want to get rid of comment section present in the array. Any idea how to do so? Feeling bad I can't even upvote since I am novice over here Commented Apr 21, 2015 at 13:30
  • 1
    The comment output can be controlled per view mode/display. You can add your view mode and display configuration to your module and then hide the comment field there. Commented Apr 21, 2015 at 18:19

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.