0

I have a custom entity, with a controller class that extends EntityViewController much like the node module does in core. The view method in this class returns a render array $build and it is called by the router for my entity.

I would now like to attach some more content to this render array, specifically some articles from another site. I have a class of my own that I am able to implement like this inside the view() function:

$client = new FrontpageArticlesBuilder();
$articles = $client->toRenderArray();

Where $articles is a render array. I would like to know how I can append this render array to my existing $build render array returned by view() method in my controller.

1

You can simply add this to the build array with an arbitrary key name. The only condition is of course that it does not already exist. Every key that does not start with a '#'-sign will be interpreted as another render element or an array of nested render elements.

$build['articles'] = $articles;
|improve this answer|||||
  • It was slightly more complicated in my case considering $build = parent::view($listing, $view_mode, $langcode); I had initiate a new empty $page_array, then do $page_array[] = $build; $page_array[] = $articles; – iain maitland Jul 19 '16 at 21:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.