Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [8]

Version tags should be used only for questions that apply to a version only, not to merely say what version a site is using.

7
votes
1answer
4k views

Working with template suggestions on Drupal 8

I need Drupal to use a custom page template if the URL contains a particular _GET parameter. In D7 I would do something like this in the theme's template.php: function mytheme_preprocess_page(&$...
6
votes
1answer
4k views

form_state->setRedirect(to_a_new_node_page) from the submitForm function, route “does not exist” issue

I created a custom module, It generate a custom Form in a page. When I submit my form, I create a new node. So, I am redirect to the form page but I would like be redirect to the new node page. I add ...
4
votes
2answers
2k views

How can I dynamically add URL or taxonomy to body class

Am creating my own theme and have successfully added the URL into the node class in node.html.twig with {% set classes = [ 'url' ~ url|clean_class, ] %} but I need to be able to style each page ...
4
votes
2answers
6k views

Add a “autocomplete” field in a buildForm

How do I add an autocomplete field in a class that extends FormBase? I created a custom module, which uses a class that extends FormBase. I want to programmatically create a form field that ...
2
votes
1answer
3k views

Override theme template from module without implementing a theme

I have a project on D8 where I don't use any custom themes, I use default seven theme for everything because there is no need of any visual theming. So My question: Is it possible to override theme ...
1
vote
1answer
4k views

How do I submit a form via AJAX?

I'm using the Webform module for Drupal 8. The module confirmation settings for a form are the following: Page (redirects to new page and displays the confirmation message) Inline (reloads the ...
12
votes
3answers
15k views

Running Drush returns an error

I am running Drush version 6.2.0 and the latest Drupal 8 beta on Dreamhosters. When I run drush cc all within the sites directory, I receive the following error immediately after executing the command:...
5
votes
2answers
2k views

Where is the “auto submit” option?

I have an exposed filter for one of my views and I added a drop-down select for the users to pick from. In Views for Drupal 7 there was an Auto-Submit check box, but I can not seem to find it in ...
4
votes
5answers
3k views

How to programmatically create a title for a new node?

I want the title field of each new node of the Agenda content type to be constructed automatically from a date field in that same node. I have variously tried setting the #default_value and #value on ...
3
votes
1answer
675 views

Update a field without changing the node

I need to change a field in a node without altering the 'changed' timestamp. I know this was possible in D7 using field_attach_update but that has been removed since then. I could use an update query ...
2
votes
1answer
496 views

How can I exclude API keys, passwords, and so on from configuration management?

I am using Drupal 8 and drush cex to commit my configuration to my repository. However, I want to keep passwords and API keys out of the repository. How do I do that? (selectively exclude sensitive ...
2
votes
3answers
796 views

How to add a class to the image tag

The input in file field.html.twig is normally like this: {% for item in items %} <div{{ attributes }}>{{ item.content }}</div> {% endfor %} And you get the output in HTML like this: <...
2
votes
1answer
1k views

How can we catch the acces denied exception?

I've run into a case where users need to be redirected to the login page when they try to access a page without having the permission to access it. How can I catch an exception of the ...
2
votes
2answers
877 views

Cannot deal with multiple iterations of same form on one page

I am designing a site that has a variety of points in which I need to render "workflow" buttons that are used to send actions to an external application. I used the form API to generate these ...
1
vote
1answer
954 views

Make canonical URL in document HEAD absolute

I have a requirement to use absolute URLs for the canonical URL element generated by Drupal 8. hook_page_attachments_alter doesn't seem to have access the HTML element. Is there any other way I can ...
0
votes
3answers
2k views

Get result view with formatter programmattically

Example a view with show fields: I want retrive array result like this: [ [title, date_start data_end ... ] ]
31
votes
4answers
38k views

How to get instance of referenced entity?

I have a node object with image field named field_image. When I do $node ->get('field_image') ->first() ->getValue() I get array with some properties instead of entity object. The ...
25
votes
4answers
860 views

With current D8 status, what's the decision tree for creating a new content entity type versus creating a Content Type for the “Node” content entity?

We have seen four years and Drupal 8's first release since the accepted answer was written for the question "When is it appropriate to create an Entity versus just adding a new content type?" And, ...
14
votes
1answer
4k views

How to make a theme hook suggestion for blocks according to region?

Since Drupal 8 it is not possible with template naming conventions to load a specific block template according to the region it is placed in ("Per-region block markup and per-region block templating ...
33
votes
8answers
41k views

How do I enable developer/debug mode?

Installing drupal 8 core (using standard profile). whenever I get exception/error, I get blank page with "The website has encountered an error. Please try again later." (as below image) text and no ...
21
votes
10answers
14k views

Change article date format

I'd like to change the date format that is used for articles in Drupal 8. It looks like it uses the Default medium date format by default. I added my own format at admin/config/regional/date-time, but ...
15
votes
9answers
14k views

Add class to content field (link)

I want to add a class to the <a> tag of a field that consists of a link and text. (It's a field of type Link.) The name of the field is content.field_c_button_link. In the template file, I ...
12
votes
6answers
8k views

How to redirect an anonymous user to the login form after a 403 error?

I want to redirect an anonymous user to the login form if such user encounters a 403 error. I have created event subscriber and this is my code, but I end up on loop on the current page. /** * ...
11
votes
1answer
2k views

Multilingual content and single language admin interface

I want my site's content to be multi-lingual. I have a language switcher that can toggle between both the English and Spanish translations of a page. I want the administrative interface to always be ...
10
votes
2answers
14k views

Render a node field inside page.html.twig

I have an image field on my content type (field_hero_image). I don't want it to render in the node.html.twig file. However, I DO want to render it in the page.html.twig file. Specifically, I want to ...
30
votes
3answers
34k views

How to get the base URL of a site

My site is on http://drupal8.local/. How do I get the drupal8.local part of that URL? Url::fromRoute('<'current'>') or base_path() returns the path parth of the URL; For example, for http://...
19
votes
1answer
29k views

Untrusted Host “localhost” in [duplicate]

From Drupal 8 beta 6 (released today), I have this error : Error message UnexpectedValueException: Untrusted Host "localhost" in Symfony\Component\HttpFoundation\Request->getHost() (line 1221 of ...
14
votes
1answer
2k views

How do I use dependency injection on \Drupal::moduleHandler() to a Controller?

I am using the following line in a controller class. \Drupal::moduleHandler()->alter('mymodule_myfunction', $plugin_items); Pareview.sh is giving me this error message. \Drupal calls ...
9
votes
2answers
2k views

How to add a variable to a twig field template?

On a node page I would like to add the node title to the output alongside another another field (the example field). I have created a new field--field-example.html.twig but am unable to access the ...
18
votes
3answers
15k views

How do I render nodes, now that node_view() has been deprecated?

In Drupal 7 I frequently use node_view() for rendering nodes (using view modes) in blocks or pages as follows: $nids = array(123,456,789); $nodes = node_load_multiple($nids); foreach ($nodes as $node)...
12
votes
4answers
15k views

Storing data / session for anonymous user

I am working on a shop, and for the cart, i need to store items before payment. $tempstore = \Drupal::service('user.private_tempstore')->get('boutique'); $tempstore->set('poids', $...
11
votes
4answers
10k views

How can I get the page title?

drupal_get_title() has been removed from Drupal 8. How I can get the page title in Drupal 8?
5
votes
1answer
7k views

How to Create twig template files in drupal 8 for customizing user login,profile edit and forget password forms?

Earlier we use the below code for creating custom template of user login ,user profile edit and forget password forms: function Yourtheme_theme($existing, $type, $theme, $path){ return array( '...
2
votes
3answers
1k views

Updated >= Drupal 8.0.5+: Rendering forms/entities programmatically on theming level

There are several attempts and questions already asked about near to that topic in combination with the new Drupal core (8), but non of them came down to the bottom of the basic question. And non of ...
11
votes
1answer
8k views

How to create custom entity in Drupal 8 [closed]

I have a big personal project build on Drupal 7 that has many custom entities. I want to start upgrading the project into Drupal 8 but the completly rewritten Drupal 8 core is too big for me to get my ...
6
votes
2answers
8k views

How do I get a field translated in Drupal 8

I have a multilingual site in Drupal 8, and several node, some translated and others not. As I can programmatically get the translated field or by default they give it back from the original language. ...
6
votes
1answer
4k views

How do I theme a taxonomy term page?

I am working on Drupal 8, trying to get a page template for each vocabulary. I have tried using hook_theme_suggestions_HOOK_alter() to achieve this, but I was not able to do it. I tried using Devel ...
6
votes
2answers
1k views

Drush @sites not implemented in drush 9

Since drush 9 (drupal 8.4 requirement), alias @sites does not seem to be implemented anymore (or yet ?). $ drush @sites cr The alias @sites could not be found. Is this a way to get the same behavior ...
4
votes
2answers
4k views

How to extend the basic user object upon installation?

I need to build a module to handle Users profiles, and need to extend automatically the basic Drupal user object upon installation. For Drupal 7 I found a way with: field_create_field($field); But ...
2
votes
2answers
5k views

How to create a custom Twig Template for Menu Block

I'm using a menu block to output a section of my main menu into a region so I can have a "In This Section" type of sub menu on every page. Unfortunately, I can't find a way to pinpoint in menu.html....
16
votes
4answers
12k views

Access user fields?

$account = \Drupal::currentUser() loads the user object into $account, but how do I access custom fields I've created on the user object (via the admin UI)? With dpm($account) I can't see any of my ...
10
votes
1answer
6k views

How do I use a jQuery version different from the default one used by core?

I need to use a different jQuery version. Currently, Drupal is using jQuery 3.2.1, but I need a previous version. In Drupal 7 you could easily change jQuery version with the jQuery Update module. How ...
10
votes
1answer
4k views

How to remove mymodule configurations on uninstall [duplicate]

I have created a custom module and created a yml file to create a menu system.menu.custom_menu.yml id: custom_menu label: 'Custom menu' description: 'Custom menu.' langcode: en locked: true ...
10
votes
4answers
5k views

Why does “composer update drupal/drupal” not work?

I installed a drupal 8.2.0 site with composer create-project drupal/drupal testsite. Now I would like to upgrade this to drupal 8.2.1. However, navigating into testsite and running composer update ...
7
votes
3answers
6k views

How can I embed a View inside a content of a node?

How can I embed a view inside a content of a node in Drupal 8? I found something similar, for example in the question about "How do I embed a view inside a node?" or the Viewfield module, but it is ...
7
votes
6answers
15k views

What function/method can I use to redirect users to a different page?

In Drupal 7, I use the following code. function my_goto($path) { drupal_goto($path, array(), 301); } What code should I use in Drupal 8?
5
votes
1answer
1k views

Use a twig template instead of a render array in a custom module admin page

I have a Drupal 8 custom module, and I want to display its configuration page using the admin theme. Usually, for this kind of pages I use, in the _controller property of my route, rather : a class ...
5
votes
2answers
353 views

Do new routes in Drupal 8 *require* a static first portion?

Using mymodule.routing.yml, I can successfully create a custom route at /foo/{bar}/{baz}. I cannot seem to do either of /{bar}/{baz} or /{bar}/foo/{baz}. It just returns 404. Why? Is there any way ...
4
votes
1answer
5k views

Custom entity operation links

I've built a couple of custom entities in Drupal 8 Vendor, defined as such: /** * Defines the vendor entity. * * @EntityType( * id = "vendor", * label = @Translation("Vendor"), * module ...
4
votes
1answer
8k views

Render image field from node in page.html.twig

I make my first steps with Drupal 8. I have a site with a header image. On a specific content type "Blog" I want to replace the standard header image with a node specific header image. So in the ...