Skip to main content

Questions tagged [page-controller]

Filter by
Sorted by
Tagged with
0 votes
1 answer
2k views

How to configure a custom POST api to accept a request with Content-Type as "application/x-www-form-urlencoded" in the header?

I created a controller in a custom module that accepts a POST request. I have a setup such that I get a POST request from a third-party application server to this API. But the POST request has a ...
0 votes
1 answer
790 views

submitForm() isn't called

Goal: Have a custom page that shows various elements including links, logos, images and a custom form to help the users reset their passwords (we have a custom reset password interface which sends the ...
2 votes
2 answers
5k views

Pass variables from controller to existing node template file

In the Drupal 8 documentation I have found a way how to pass variable from controller to custom twig template https://www.drupal.org/docs/8/theming/twig/create-custom-twig-templates-from-custom-...
0 votes
1 answer
57 views

Theme template not found in module controller

I'm very new to Drupal 10 and I'm having an issue with a custom module I'm trying to create. I have a controller that I'm querying nodes of an FAQ content type that I created. The defined route works ...
1 vote
2 answers
572 views

Forwarding request to a content page

How can I forward a request from module to a content page? I have got a module that authenticates users; once authenticated, the module should forward the request to a content page or node (not ...
0 votes
1 answer
73 views

Passing parametes to a twig template

I am creating a custom module to create a controller that runs every time we access a certain route. I have university entities created and a view to represent them in a list. When I click on one I ...
0 votes
0 answers
23 views

Limit Per User Tokens in Drupal Simple OAuth

I'm looking for a way to limit the maximum number of tokens granted to each user in Drupal 10, similar to how we can limit the number of sessions per user using the Drupal Session Limit module. Is ...
1 vote
2 answers
296 views

PHP constructor property promotion: how to call the parent constructor?

So I have a Controller that I am trying to rewrite to use PHP constructor property promotion: class MyUserController extends UserController { /** * Constructs MyUserController. * * @param \...
0 votes
1 answer
96 views

Can't pass variables from a controller to the template if I use base hook to override the theme template

I've created a custom route that uses a controller to use a custom template. If I don't mess with base hook my template is rendered somewhere inside page.html.twig as a block and all the variables are ...
0 votes
1 answer
114 views

Why am I getting "Page not found" for a simple "hello world" custom page

In my custom module, ed_helper, I have this ed_helper.routing.yml: ed_helper.my_page: path: '/mypage/page' defaults: _controller: '\Drupal\ed_helper\Controller\EdHelperController::myPage' ...
44 votes
7 answers
100k 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?
-1 votes
1 answer
394 views

"No route found for GET" on custom REST resource when posting

I'm seeing really weird behavior. I've created a custom REST resource at the route /user/login-special. This is a passwordless login resource, so I pass the mail address and then get a response that ...
3 votes
1 answer
759 views

Using OAuth2 on non-REST endpoints

I have a custom module which includes a ControllerBase. The controller has a content() function that returns a JsonResponse(). The code for this function returns a complete list of a certain entity ...
1 vote
3 answers
2k views

Routing for controller with multilingual enabled

On my Drupal 8 multilingual project, I have made a custom controller which create a basic page, but I can't figure out which parameter I must use in the routing. Is this _locale? This is the ...
0 votes
1 answer
332 views

Stripe doesn't see API key after TrustedRedirectResponse

I have a controller that calls the Stripe API using stripe-php to create a checkout session. /** * Checkout using Stripe. * * @param \Symfony\Component\HttpFoundation\Request $request * ...
0 votes
1 answer
96 views

How do I get my custom module controller logic to trigger on only certain url paths?

Hi all I am very new to Drupal and am trying to write a custom module. So my site has a bunch of different urls for example example.com/users/3 or example.com/articles/47. I want my custom module code ...
1 vote
0 answers
56 views

How do I set/get cookies in a controller (custom module)? [duplicate]

I have a module and I need to set a simple cookie (if not exists). And after each request I need to read the value of the cookie and maybe update. I have read many articles and tried many ways but no ...
0 votes
0 answers
278 views

How can I add inline JavaScript on a page returned from a custom controller (not with a library)?

How can I add another render element that contains my custom JavaScript code? Do I use ['#attached']['html_head'] or code similar to the following one? $build['body']['script'] = [ '#type' => '...
6 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 ...
0 votes
1 answer
902 views

How to use 'use-ajax' class with pages created by controller?

I'm trying to use 'use-ajax' class to load a page inside a modal box. My Page is dynamically created using node id pass on my page controller My link looks like this Any idea on how can I achieve ...
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 ...
0 votes
0 answers
580 views

"LogicException: The controller result claims to be providing relevant cache metadata, but leaked metadata was detected."

Hi I've created a module with a controller but now i'm getting this message; The controller result claims to be providing relevant cache metadata, but leaked metadata was detected. Please ensure you ...
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 ...
2 votes
1 answer
989 views

Return AccessDenied for custom page

I've setup a custom page in my system which is expecting 2 parameters that will be used to generate part of the content on that page, I'm able to retrieve the information from my page, but I'm ...
0 votes
0 answers
226 views

Off-site payment gateway success/failure return is caught by a differnt custom module

I have created an offsite (redirect form) payment gateway Drupal 8 module for Opayo.co.uk. following drupal commerce documentation. Issue: My custom off-site payment gateway module based on form ...
0 votes
2 answers
227 views

Custom access method for a Page Manager page

I've created a page using Page Manager, at the route /project/(node}/attendance. I need to add a custom access check on it, comparing information about the current user with the node to see if they ...
0 votes
1 answer
51 views

Override a access check but also pass control back to the primary controller under certain conditions?

I use a contrib controller that has a _custom_access function that I need to override. I add a RouteSubscriber, and point the access check to my own controller. Now I want something like: if ($...
0 votes
0 answers
69 views

How to Manage Webhook Notifications?

I had developed a controller to retrieve data from an API via a webhook. This is the type of data I received with https://webhook.site for testing : { "owner": { "id": "...
0 votes
2 answers
318 views

How can i render a file using a formatter programmatically in a controller?

I'm trying to create a controller to render a swagger documentation using the module swagger_ui_formatter that provide a formatter to the file field that render swagger files (yml, yaml, json) using ...
1 vote
1 answer
772 views

I cannot use drupal_set_message() in a custom controller module

In a custom controller, when I try to use drupal_set_message(), it works only if I use the following code. // The message is shown via {{ page.highlighted }}. drupal_set_message('Test error', 'error');...
0 votes
0 answers
521 views

Alter a controller's render array via KernelEvents::VIEW

I'm trying to alter a contrib module controller's output via KernelEvents::VIEW. I want to display the output from the controller and append the markup returned from the event handler. This is the ...
1 vote
1 answer
275 views

How can I delete a file served by a custom controller after it has been downloaded?

Starting from How do I create a file download URL? I've build a custom controller that allows users to download a PDF file. my_module.routing.yml my_module.pdf_link: path: '/my-module/pdf/download' ...
-2 votes
1 answer
248 views

Adding select list to tableselect output

I'm trying to add a select-list to some table output but the markup is rendering as text. $header = [ 'col1' => t('COL1'), 'col2' => t('COL2'), ]; $rows = [ 1 => [ 'col1' => '...
1 vote
1 answer
1k views

Creating a table with pagination in a Node Edit form

I have a content type article that has a field for Category. In order to help our editors find related articles, I included a table on the article Edit page that pulls in other article entities that ...
7 votes
2 answers
16k 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 ...
8 votes
3 answers
9k views

How to inject the database connection into a custom service?

I have a custom module that pulls data from several different external databases that have been defined as connections in settings.php. The current setup includes a series of controllers that have a ...
0 votes
1 answer
48 views

How to force display of a specific page of paged data

I'm displaying a table of dated items ordered from old to new and am using the full pager. How can I force my page to initially display those items that are current ie. on initial load, display the ...
2 votes
1 answer
237 views

Redirect After Creating New Taxonomy Term

I am new to Drupal. I am trying to figure out if it is possible to redirect back to the Taxonomy page right after adding the new vocabulary term instead of being directed to the manage page of the ...
1 vote
1 answer
87 views

Keep entity object after getTitle() method in render() method in a custom controller

I've setup my controller like this: my_controller: path: '/controller/{id}' defaults: _controller: '\Drupal\Mymodule\Controller\MyController::Render' _title_callback: '\Drupal\Mymodule\...
0 votes
1 answer
764 views

Is there a way to get the controller class from a Request object or any other service class?

My controller class holds some not-so-easy logic to receive some data from a route parameter I need in a block plugin. As this block will only be rendered on this specific route, I would like to ...
1 vote
0 answers
308 views

Use one controller in custom Block and Page

I have a custom module with a page and block. Both will use same API but with different queries and also both will display API data in the same page. To be more explicit, I have a simple search on my ...
0 votes
1 answer
109 views

Controller is loading twice after search form is submitted

I created a custom module that I consume an external api. I have also created a custom form (its action points to controller url) which filters the data. However, when I press the search button and ...
0 votes
1 answer
658 views

Access hook_preprocess_node variables from page controller

I have a custom controller created for a custom URL, where the URL is a URL for an existing node with an additional parameter. The display for the URL defined by the controller needs to use the the ...
1 vote
1 answer
192 views

How can I avoid to return HTML markup for access denied? [duplicate]

I've developed a custom controller that serves as a simple endpoint, POST method. This controller has custom access control. Custom access is done by looking for a header in the HTTP request, by ...
1 vote
1 answer
2k views

Override page template and preserve administration navigation bar

Short version; I am trying to override the default page.html.twig (in D8) for a controller from my module and the following examples I've found have not worked: https://www.drupal.org/node/2499827 ...
0 votes
1 answer
2k views

LogicException : The controller must return a response (success ! given) [duplicate]

i have a service that return for me true in the node (article) successfully create and false if something wrong , but in the controller i am getting this error 'LogicException : The controller must ...
0 votes
1 answer
244 views

How can I render more than one field value in the controller?

in my case i have a controller that it send for me the title , to the view , but i want to send the tittle and the body of the article both , i have tried to send them from the controller but it doesn'...
1 vote
1 answer
1k views

Custom POST request [duplicate]

I am very new to Drupal. My project requires me to create a custom module. I am working with Headless Drupal and I want to make a POST request. I cannot pass the POSTMAN Body to my Request argument in ...
-1 votes
1 answer
227 views

Why do I get an error related to a controller when I created a custom module?

I created custom module following the Creating a custom module on Drupal tutorial. The teacher of this tutorial demonstrated how you can create a custom module that displays on the page Hello world. ...
1 vote
0 answers
211 views

What is the difference between access method in controller and custom access check

I am trying to create a module with custom access checks. I would like to know what additional features does implementing AccessInterface provide. For example I can check access within the ...