Skip to main content

Questions tagged [page-controller]

Filter by
Sorted by
Tagged with
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 ...
The Unknown Dev's user avatar
0 votes
1 answer
408 views

Instantiate Controller with Interface not concrete class [closed]

As background, I am rebuilding some old code and want to wrap all the curl based requests in an interface (HttpRequestInterface) so I can swap that out later without having to write all the api calls ...
Rob Allen's user avatar
  • 103
0 votes
1 answer
68 views

Inject variables from Controller to Blocks?

I have a Product module that implement's an entity, a Repository, a Controller and 2 Blocks The problem is, in the product page, I'm querying the entity in every block and also in the Controller. I'm ...
Juan Miret's user avatar
0 votes
1 answer
206 views

Render page with theme wrapper from custom controller?

I've created a page layout using panels in the Drupal admin UI (page_machine_id). I'm trying to load that page into a custom controller like so and render one of the variants (Drupal 8): public ...
iamamused's user avatar
  • 101
0 votes
0 answers
114 views

Assign a controller to all book pages

I am trying to build a module that checks if user session set in all pages of a certain book. if the session is not set it will be set. I am using a sso system so the user data will come from there, ...
DavSev's user avatar
  • 153
-2 votes
1 answer
490 views

Page not found error when creating a simple module [closed]

I have my first module in drupal 8 with three files in modules section of my drupal: hello_world.routing.yml: hello_world: path: '/hello/world' defaults: _controller: '\Drupal\...
golsa emdadi's user avatar
1 vote
1 answer
2k views

Creating iframe to be used in other websites

I've created a controller with the route "/get-info", the controller return a template custom-info.html.twig my_module/src/Controller/MyController.php file: <?php namespace Drupal\my_module\...
MiharbKH's user avatar
  • 808
2 votes
1 answer
2k views

How to send formatted html email using swiftmailer?

How can I send styled html body using custom module to send an email. I am using swiftmailer module. With that I am able to send normal body, but I am not able to use html tags or css. How can I do ...
Rifas Ali's user avatar
  • 510
-1 votes
2 answers
459 views

How do I pass a CSS class to the controller? [closed]

I want to pass a CSS class to a controller. In the case of nodes, I am using the following code. $node = \Drupal::routeMatch()->getParameter('node'); if ($node) { $variables['attributes']['...
amol's user avatar
  • 357
-2 votes
1 answer
3k views

How to create a dynamic front page [closed]

I have created page--front.html in drupal 8 custom theme then how to make dynamic this page section ? where I write custom code. i.e. how to showing slider images to which is added in admin side. ...
Chandrakant's user avatar
0 votes
1 answer
67 views

How to set a url in drupal database or settings.php?

I had created a controller in custom module using drupal 8. public function subscribe(Request $request) { $url='https://username:[email protected]/v1/subscriptions'; } I am using git ...
Rifas Ali's user avatar
  • 510
5 votes
2 answers
9k views

How to check whether a username already exists?

I had created a controller where I can create a new user programmitically by the following code. $user = User::create(); //Mandatory settings $user->setPassword($password); $...
Rifas Ali's user avatar
  • 510
3 votes
1 answer
2k views

Edit a config variable of a custom module in controller

Is it possible to edit/create a config variable of a module in a controller created in the same module? For example: module_name/src/Controller/MyController.php: class MyController extends ...
MiharbKH's user avatar
  • 808
0 votes
1 answer
60 views

module controller does not respond!

I'm trying to create a controller within my custom module, but the controller still doesn't response when visiting the associated path. Here are my files: my_module/my_module.routing.yml: my_module....
MiharbKH's user avatar
  • 808
0 votes
3 answers
2k views

How to change payment state programmatically?

I had created a custom module to update order state and payment state. In my controller I used the following code to change the order state of order. $order = \Drupal\commerce_order\Entity\Order::...
Rifas Ali's user avatar
  • 510
2 votes
1 answer
2k views

How to attach a library to a page controller that returns a plain Symfony response?

I created a custom module with a page controller that returns a Symfony response (Symfony\Component\HttpFoundation\Response). The thing is I don't want to render my custom theme in this controller, ...
ptinca's user avatar
  • 123
0 votes
1 answer
7k views

Get variable from controller in twig using template

I have a php variable in my controller and i want to use it in twig. So i do this : Controller : $firstLetter = '2017'; //dynamic variable but for the test it's a constant $build ['list'] = ...
user avatar
3 votes
1 answer
1k views

How to add a default controller to the <front> route?

Is it possible to add a default controller to the '<front>' route? There's no default controller defined in system.routing.yml. I'm trying to get a handle on it by using the following code: &...
AdamB's user avatar
  • 164
2 votes
1 answer
4k views

Render node from Controller

I have a controller that passes a list of nodes to a template for rendering. I think I'm missing something simple. I've tried this with no success: public function content() { $students = $this-&...
icicleking's user avatar
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
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 ...
Bernard Brillo'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
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-...
vcorusa's user avatar
  • 21
0 votes
1 answer
1k views

Drupal 8: Class not found from module Controller, but works fine from module EventSubscriber

I created a custom D8 module in: <root>/modules/custom/mymodule In that custom module are src/Controller/MyController.php and src/EventSubscriber/MySubscriber.php. I wrote some custom code ...
Jon Paul Vivere's user avatar
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 ...
lchabrand's user avatar
  • 376
2 votes
1 answer
4k views

How to render a custom entity in a controller?

I created a custom entity called foo. This entity has a unique name field as well as the standard id key. I would like to build a page where the user can see the entity rendered similarly to how it ...
Kevin Nowaczyk's user avatar
0 votes
0 answers
130 views

Tabledrag do not set values

I have a problem using page manager and tabledrag to change order of my blocks. When I place more than 20+ blocks, tabledrag stop working, one block has set "null" value in weight field. When I place ...
lamp5's user avatar
  • 320
3 votes
1 answer
184 views

How do I capture a page as HTML?

I have a controller that generates a custom 500 page. I have set up a route at the path: '/500'. I would like to capture this as HTML and save as a static file, so that I don't need to bootstrap ...
oknate's user avatar
  • 14.5k
-1 votes
1 answer
14 views

How to deny access to menu items that aren't expected

I want to find a way to make requests to hook_menu that I don't expect be denied. For example I have defined a menu like this: $items[$my_url] = array( 'title' => $my_title, 'page callback' =&...
Dave's user avatar
  • 129
2 votes
2 answers
695 views

What is the best way to verify controller arguments?

For example, I have a path on my site. Let it be www.mysite.com/year/{year}/month/{month}/day/{day} Could you clarify me, what is the best way to avoid getting of wrong arguments, such as year/3000/...
Yakimkin Roman's user avatar
1 vote
1 answer
425 views

Render custom html below a custom form

I am new to drupal, I am using drupal 8, I have develop a custom form by extending FormBase controller and i am trying to render it using a custom controller like below. $form = $this->formBuilder-...
Udit Rawat's user avatar
0 votes
1 answer
949 views

How can i render webform on custom url with custom html in drupal 8

Basically I am using sample code which shown in below. public function test(){ $webform = \Drupal::entityTypeManager()->getStorage('webform')->load('contact_us'); $webform = $webform->...
Bhavesh maffia's user avatar
4 votes
2 answers
1k views

How do I define a route and controller for the home page?

A custom module called TSA contains almost all of the functionality for the /tsa subsite on my Drupal 8 multisite. I want to define a route for http://localhost/tsa/, so that I can serve up dynamic ...
Lincoln Bergeson's user avatar
2 votes
1 answer
5k views

How do I pass parameters from a form redirect to a controller?

I feel like it should be easier to find this stuff out. I'm trying to pass some data from a form submission to a controller, and do something based on that data. What is the most Drupal way to do this ...
Lincoln Bergeson's user avatar
1 vote
4 answers
2k views

How to debug a variable in a controller class (var_dump)

I am trying to do a var dump from a Drupal 8 Controller class. This is not working because controllers need to send a response. I just need to see the contents of a variable and I have not idea how to ...
Stan Alachniewicz's user avatar
1 vote
1 answer
387 views

how to debug a controller not being run

my code below results in a page not found when I browse to the path. How can I debug what is going wrong? I dont see any errors and I have cleared the cache. mymodule.content: path: '/admin/...
Diana's user avatar
  • 3,020
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 ...
Zen's user avatar
  • 21
0 votes
1 answer
481 views

Create a controller and a empty theme page

On Drupal 8, I'm looking for a way for creating an empty page (a page without any theme) that contains JavaScript code. I created a controller via Drupal Console, and I searched for an example on the ...
spacecodeur's user avatar
  • 1,339
1 vote
0 answers
670 views

One route, multiple controllers

How can I go around having a single route that would internally be forwarded to a controller depending on some internal logic. I've looked into dynamic routes but it doesn't help since the route is ...
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
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 ...
turnerd18's user avatar
  • 113
3 votes
2 answers
7k views

How can I add a custom form to the output of a controller class?

I have a controller in my custom module. Inside this controller I need to render a whole bunch of different things (some basic html, multiple forms, etc). My main problem is I can't figure out how ...
Bobby's user avatar
  • 217
1 vote
2 answers
899 views

Create form via a controller

I have a template in which I've manually built a form. It renders some variables that come from a controller. I've looked over the Form API and I think I should build the form using that. But I'm not ...
Andrew's user avatar
  • 731
0 votes
1 answer
142 views

creating a function that can create GET url variables as object when I need it

I am trying to parse my form's GET method and create a function that can get all the parameters from the URL in DRUPAL 8. I have a form that I am gonna use it to filter my library items as search( I ...
Mr.T's user avatar
  • 133
0 votes
2 answers
4k views

Render blocks in custom page

I followed steps given in this link to create a custom Page. Page is created and 'Hello world' is printing in the page, now i want to render some blocks in that page. How can I achieve this task?
rks's user avatar
  • 399
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
1 vote
0 answers
2k views

How do I call a function from a class/controller in another class/controller? [closed]

There are two modules "field_collection" and "tasks" I have a controller called "task" from the custom module "tasks". I'd like to use a function in this controller (this function from custom module ...
user71719's user avatar
  • 137
0 votes
0 answers
399 views

Routing Parameter Directly Passed And Upcast

Has anyone come across a way to both pass a dynamic route parameter as well as upcasting it? something like: /module/custom/mymodule/src/Routing/MyRoutes.php $routes["my.custom.route"] = new Route( ...
LittleCoding's user avatar
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');...
injetkilo's user avatar
  • 325
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