Questions tagged [page-controller]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
44 votes
7 answers
98k views

How to get $_POST and $_GET parameters

I call a route via AJAX and pass data to it. In a controller, I want to get $_POST['var'], but it does seem to work on Drupal 8. How I can get values contained in $_POST from a controller?
Yuseferi's user avatar
  • 22k
7 votes
2 answers
5k views

Cache controller with json response

I want to return a cached response in a controller that returns JSON data. I tried the following code. $build = array( '#cache' => array( 'contexts' => ['ip'], ), ); return (new ...
BOES's user avatar
  • 1,023
7 votes
2 answers
15k views

How to add Pager to a custom page?

I have a list of items which is fetched from an REST API and displayed in a page 10 at a time. These items are not stored in Drupal database in any way. I managed to have a basic pager which is just a ...
Malabya Tewari's user avatar
5 votes
2 answers
3k views

Take over display of a content type node route

I have a discussion content type. I would like the primary viewing experience (at "discussion/discussion-name") to be a cacheable form using a form mode. Basically, I'm trying to create something ...
Jonathan's user avatar
  • 1,128
5 votes
1 answer
3k views

Is there a "best practice" for overriding a contributed module's controller?

I'm still relatively new to Drupal 8 and recently I came across an occasion to override the WebFormSubmissionListBuilder Controller. I eventually found another project which had exactly the same need ...
user5429087's user avatar
3 votes
2 answers
2k views

Override html.twig.html within custom module

According to this Drupal 7 answer, I'm looking for a Drupal 8 solution to simply print the page content within a custom html.twig.html. namespace Drupal\custom_module\Controller; use Drupal\Core\...
MΞDIΞNVΞRBINDΞR's user avatar
5 votes
1 answer
643 views

How to deal with Bubbleable Metadata when there's no rendering context and no render array

Since Drupal 8.0.0-beta12 "all rendering must happen in a render context", as stated by this change record. This is to avoid bubbleable metadata lost. So far, so good. Let's say I'm implementing a ...
sanzante's user avatar
  • 6,981
4 votes
1 answer
8k views

How to render a template in a module controller?

I want to render a custom template in a module controller but I don't know how. How do I achieve this?
Lhassan Baazzi's user avatar
2 votes
2 answers
6k views

Call AJAX callback on page load

I've been reading the whole day but I cannot find a complete example for a basic AJAX call on load page. I followed this tutorial: and this example: I was able to register the callback, controller ...
Manuel Rodriguez's user avatar
2 votes
3 answers
3k views

How do I redirect users to an external URL?

I implemented a controller class in Drupal 8, which redirects to an external site. If I use \Symfony\Component\HttpFoundation\RedirectResponse, I get this error. Redirects to external URLs are not ...
MH35's user avatar
  • 31
2 votes
2 answers
5k views

Create route that returns XML Feed [closed]

How do I create a page that returns an XML feed?
BOES's user avatar
  • 1,023
1 vote
1 answer
2k views

Add JavaScript inside controller

How to add JavaScript inside controller? I don't want to call build form. I can call css or js in src/Form/Form.php but I want to call css or js inside Controller src/Controller/Controller.php This ...
Abhinaw Anand's user avatar
0 votes
1 answer
609 views

Redirect from within controller always goes to home page

I have a custom module named rsc. My Default 404 (not found) page is set to /page-not-found in Basic site settings. My rsc.routing.yml file contains rsc.pageNotFound: path: '/page-not-found' ...
Marshall Morrise's user avatar
0 votes
2 answers
2k views

Generate meta in controller

I'm creating a custom module. This module displays public custom content without node and views . For this content custom page , I would like to add dynamic meta keyword and meta description . I ...
Agriesean's user avatar