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.

Filter by
Sorted by
Tagged with
5
votes
1answer
1k views

How to migrate multilingual image alt fields from CSV?

I'm migrating multilingual content to Drupal 8 from a group of CSV files, and I'm about 95% of the way there. I have an image field attached to an article content type that shares the image among all ...
4
votes
2answers
2k views

Passing current node ID to the block template

I have a module with a custom block MyCustomBlock.php that get the nid of the current page and pass the value to the block template: $node = \Drupal::routeMatch()->getParameter('node'); $nid = $...
5
votes
2answers
3k views

How do I load a form with a specific form display (form mode)?

On a custom page I'm trying to load an user edit form with a specific form display. I'm able to load the form however I can't figure out how to load the form with the specific display. This is what I ...
2
votes
3answers
3k views

How to create a node out of a webform submission?

I'd like to be able to create a node out of a webform submission in Drupal 8. It can happen either on successful submission or as an additional task after the webform has been submitted. I've seen ...
2
votes
4answers
6k views

Inserting the value from Datetime field form

I have a form where the user can input datetime and then I want to store it in the database. Here's my schema : 'start' => array( 'type' => 'varchar', 'mysql_type' => 'datetime', ...
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(&$...
7
votes
3answers
6k views

How to test for a boolean field in a twig template?

field_boolean is a boolean field. {% if content.field_boolean == true %} or {% if content.field_boolean == 1 %} or {% if content.field_boolean == 'true' %} or {% if content.field_boolean == '1' %} ...
6
votes
1answer
5k 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
1k views

Selecting taxonomy term in article and showing all articles titles associated with this term

I have a content type article and when editing an article there should be a field where you can select a taxonomy term of a specific vocabulary. When viewing the article it should show a list of ...
2
votes
3answers
1k 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
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 ...
2
votes
1answer
4k 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 ...
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
724 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
541 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 ...
24
votes
4answers
885 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 ...
14
votes
1answer
3k 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 ...
21
votes
10answers
15k 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
15k 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
9k 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. /** * ...
32
votes
4answers
39k 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://...
14
votes
4answers
3k views

Delete a node after X weeks it was created

How can I delete a node after, for example, 2 weeks it has been created?
19
votes
1answer
30k 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
3k 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 ...
12
votes
4answers
16k 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
11k 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?
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 ...
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 ...
8
votes
6answers
17k 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?
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 ...
6
votes
2answers
9k 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. ...
4
votes
1answer
8k 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( '...
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
6k 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....
17
votes
4answers
13k 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 ...
11
votes
1answer
7k 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 ...
8
votes
3answers
7k 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 ...
8
votes
4answers
4k views

How to Reduce/Increase module's weight on the module install process?

I'm developing one custom module and I want to increase my module weight when the module is installed. How can I achieve this? Otherwise, does anyone know in which table the module's weight is stored?...
6
votes
4answers
6k views

How do I make a block that pulls the current node content?

Ok, so I know blocks in Drupal 8 have these things called "contexts" which allow Core to clear cache on a fine-grained basis. I can't find any decent explanation of how they work, or how to get page ...
6
votes
1answer
2k views

Cache controller with json response

I want cached a controller that returns a json.. I try this: $build = array( '#cache' => array( 'contexts' => ['ip'], ), ); return (new CacheableJsonResponse(['test'], 200))->...
5
votes
2answers
384 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 ...
5
votes
1answer
2k 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 ...
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 ...