Questions tagged [8]

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

Filter by
Sorted by
Tagged with
18 votes
5 answers
40k views

Check if it's the front page in the template

Im trying to show content when I'm on the front page of my Drupal 8 test website, but the content shows on every page: {% if front_page %} <header role="banner"> {% if logo %} <a ...
Stefan's user avatar
  • 583
18 votes
5 answers
17k views

Get the list of all content types

How do I get a list of all the content types defined in a Drupal 8 site? In Drupal 7 it used to be node_type_get_types(), but it has been deprecated. I tried Entity::loadMultiple() but it doesn't ...
pbonnefoi's user avatar
  • 1,816
18 votes
3 answers
41k views

How can I render plain text as HTML in a template?

I've run into a wall trying to render a SVG image markup code into html from a plain text field. I'm looking to render the SVG code from a plain text field without overriding the plain text field ...
Alari Truuts's user avatar
18 votes
5 answers
7k views

Order of drush commands for automated deployment?

What order should the following drush commands be ran? config-import updatedb entity-updates Also, I see entity-updates fail a lot due to field_delete_data* tables existing. How can I delete them as ...
Paul Canning's user avatar
18 votes
4 answers
14k views

Redirect Anonymous user to login page

I want if user not logged in and visit any page of my website except my REST VIEWS routers I redirect him/her to login page in drupal 8, I found this solutions for drupal 7 but didn't find any ...
David Mcsmith's user avatar
18 votes
2 answers
22k views

How can I upload files with the form element type file?

I want to upload a file and I have to use form element type as 'file'. In submit function I am not able to get any proper data related to the file which I am uploading. SO Can anyone please help me to ...
Suraj's user avatar
  • 884
18 votes
8 answers
22k views

How do you implement a breadcrumb?

I've tried to define a new breadcrumb override, but I'm still getting the site default. I've created a custom module, foo_breadcrumb: - modules/custom/foo_breadcrumb - foo_breadcrumb.info....
njp's user avatar
  • 707
18 votes
8 answers
13k views

How can I make kint() load faster when debugging twig templates?

I've seen quite a bit of discussion about how kint() from the Devel module is difficult to work with because it maxes out PHP memory limits and makes the browser drag. I've heard some thoughts on ...
chrisshattuck's user avatar
18 votes
5 answers
18k views

How can I setup multiple database connections?

Can anyone help me to setup connection with multiple databases connection in Drupal 8? I have database on the same server and I want to access it along with default Drupal 8 database.
Mudassar Ali's user avatar
  • 1,089
18 votes
6 answers
31k views

How do I add a CSS class to a form label?

I want to add a CSS class to a label on a page that is using Drupal 8 Form API. I have been unable to find a reference online on how to apply that. I have used the following workaround, but it ...
Steve D.'s user avatar
  • 181
18 votes
2 answers
14k views

How to get the human readable content type name in a node template

I have created node template for my node, and its working fine. I need to print content type name, which is like "Whitepaper" and has machine name "w1" in my node template. If I use variable {{ node....
Dev's user avatar
  • 731
18 votes
4 answers
31k views

Get the value of a custom user field

I have a custom form that needs to display a default value from a custom user field. The field was created under /admin/config/people/accounts/fields and its machine name is field_r_period_length_sec. ...
user2967539's user avatar
18 votes
3 answers
32k views

How do I show the current node title in page.html.twig OR in node.html.twig?

If I want to show the current node title in page.html.twig (by default it seems to only be available in node.html.twig) I have to create a preprocess function like so: function theme_preprocess_page(&...
Greg's user avatar
  • 832
18 votes
5 answers
18k views

What is the correct way to set cache contexts on custom blocks?

I have run into an issue where a block that should be unique per page isn't for logged-out users. The issue is a custom block plugin I have on a views search page that contains custom filters (sort ...
oknate's user avatar
  • 14.1k
17 votes
8 answers
22k views

Unable to install ... already exist in active configuration

On Drupal 8.1 I keep running in those kind of messages when I try to activate a custom module or a custom feature that makes some modification to the basic page. (add fields). It is really annoying... ...
Guillaume Bois's user avatar
17 votes
3 answers
37k views

How to get formatted date string from a DateTimeItem object

I have a standard Drupal date field 'My date' (field_my_date). I can get its value: $node->field_my_date->value // returns: "2017-12-14T08:00:00" But I want to get a formatted date string, ...
Antonín Slejška's user avatar
17 votes
6 answers
19k views

How to embed drupal content in other sites (remove X-Frame-Options: SAMEORIGIN)?

I tried to make a iframe with a drupal page but I received the following message: Multiple "Refused to display (page adress) in a frame because it set 'X-Frame-Options' to 'SAMEORIGIN'." Then, I ...
Victor Pereira's user avatar
17 votes
5 answers
20k views

How can I re-install a module?

I am creating on Drupal 8 module. I have used a custom table to store the data collected from forms. Somehow during installation, tables are not created due to an issue in the install file. Now I have ...
mohit_rocks's user avatar
  • 3,956
17 votes
2 answers
44k views

How to create a redirection programmatically? [closed]

I try to create a redirection 301 with the redirect module. For example, I want to redirect an URL source to an internal URL through my custom module. I want to create a redirection when I create a ...
Romest's user avatar
  • 193
17 votes
10 answers
28k 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 ...
maidi's user avatar
  • 271
17 votes
2 answers
10k views

How to load an entity using the uuid?

I have created a custom resource which extends the EntityResource class. This way I can use all build in functionality that Drupal core provides on the default entity resource, but I can still add ...
Robin's user avatar
  • 2,021
17 votes
1 answer
15k views

How do I translate a view page title?

Is there a way to translate a view page title in Drupal 8? How can I achieve it, if it is possible?
jeroen's user avatar
  • 864
17 votes
3 answers
9k views

KernelEvents::REQUEST is not fired on cached pages

I need to implement an event subscriber to perform some actions when the page is loaded. The event should be fired whether the requested page exists in the Drupal cache or not. It seems that the ...
17 votes
5 answers
27k views

How do you implement a custom submit handler in hook_form_alter()?

I've been updating one of my Drupal 7 modules to 8 and I'm having an issue with my form alter. I'm adding a validation function and a submit handler. The validation function is getting called just ...
Arbee's user avatar
  • 181
17 votes
1 answer
16k views

\Drupal::request() vs $request_stack->getCurrentRequest()

These seem to return the same thing: \Drupal::request() $request_stack->getCurrentRequest() Which is the preferred way to get the current request and why? Is one of these to be deprecated? Any ...
Delford Chaffin's user avatar
17 votes
5 answers
7k views

What is the correct core update workflow?

I want to use composer to manage Drupal 8 dependencies, but I'm not sure what is the right core update workflow. At the moment I'm using drush to update core to latest beta release, but I also have ...
rreiss's user avatar
  • 969
17 votes
1 answer
4k views

What are the equivalent functions that I should use for HTTP handling?

Looking at the functions listed in the HTTP handling page for Drupal 7, I noticed that the following functions don't exist anymore in Drupal 8. (The links are for the Drupal 7 documentation pages, ...
apaderno's user avatar
  • 97k
17 votes
1 answer
2k views

What is the difference between "Language: Not specified" & "Language: Not applicable"?

What is the difference between Language: Not specified and Language: Not applicable? There was no such distinction before Drupal 8. I haven't found any documentation about this. It would be nice to ...
17 votes
3 answers
1k views

How to install a module which includes a different version of Symfony?

I am a developer and maintainer for the CiviCRM project. We've been trying to make a Drupal 8 version CiviCRM, and have a come a long way. We're beating our heads against our collective keyboards ...
jackrabbithanna's user avatar
16 votes
5 answers
37k views

How can I programmatically render a node's field respecting the view mode settings?

I want to render a node's field inside a block. It works like this: <?php if ($node) { if (isset($node->field_body_secondary) && $field = $node->field_body_secondary->value) { ...
Alex's user avatar
  • 2,493
16 votes
7 answers
42k views

Rendering an image field in page.html.twig with a custom image style

I'm trying to set up a slideshow that's unique to each page. The code for this needs to be in page.html.twig. I've got the slideshow mostly working, but I can only call the full image URL, not a ...
JacobTheDev's user avatar
16 votes
8 answers
12k views

Get the list of available services

Is there a way to get the list of the available services in Drupal 8?
riju.srk's user avatar
  • 387
16 votes
3 answers
48k views

How to load paragraph entity on node object?

I'm using paragraphs in my content type. I've created a paragraph type and added content. Now I want to load the paragraphs in a foreach. But nothing's showing up. $paras is empty: $node = \Drupal\...
Pankaj Yogi's user avatar
16 votes
3 answers
27k views

How do I get a module path?

I'm creating a module in Drupal 8 and I need to define a relative path to mymodule to pass it on a JavaScript file like this. $scope.getPlatformIcon = function (_platform) { var modulePath = "/...
ceaucari's user avatar
  • 163
16 votes
4 answers
13k views

REST GET without caching

Using this tutorial Drupal Console's drupal gprr command, I've created a custom REST resource in Drupal 8. I'm able to use this resource to retrieve a simple JSON object that says hello to the current ...
tyler.frankenstein's user avatar
16 votes
5 answers
25k views

How do I disable Twig and block cache for a specific module?

I'm working on a module in Drupal 8 which retrieves time sensitive data from an external REST api. The data is processed and forwarded to a Block. The final data is sent to a Twig template like so: .....
estrar's user avatar
  • 415
16 votes
3 answers
15k views

How to make custom fieldset collapsed by default in Drupal 8

In Drupal 7 there was option to have fieldset collapsible or not, and to restrict default state of this form element (collapsed, or uncollapsed). Example: $form['contact_data'] = array( '#...
Juraj Nemec's user avatar
16 votes
5 answers
22k 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?
user353253's user avatar
16 votes
3 answers
17k views

How can I add items to the Admin Toolbar?

In Drupal 8, I want to add a menu item to the Admin Toolbar with a submenu, with different links. How can I do it?
jmzea's user avatar
  • 952
16 votes
2 answers
27k views

How do I create table in custom module

In Drupal 7 we used to use hook_schema() in the .install file to create a table. I believe that, in Drupal 8, you can do that as well, but I was under the impression that you should create .yml files ...
albertski's user avatar
  • 3,447
16 votes
1 answer
10k views

How do clean_class and clean_id work?

I am new to Drupal 8 and Twig syntax. I am not able to understand how the clean_class filter works in region|clean_class. What is clean_class? I have added the following code in the page.html.twig ...
Reshma's user avatar
  • 706
16 votes
1 answer
7k 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 ...
Kevin Nowaczyk's user avatar
16 votes
2 answers
8k views

"Drupal calls should be avoided in classes, use dependency injection instead"

In my module using below code for getting url alias of given url: $alias = \Drupal::service('path.alias_manager')->getPathByAlias($_POST['url']); But one I run Automated Review(http://pareview.sh/...
Cool's user avatar
  • 1,822
16 votes
1 answer
6k 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 ...
Philipp Michael's user avatar
16 votes
3 answers
11k views

What is the purpose of drush entity-updates?

After updating Drupal 8 modules, I have been warned on the Drupal 8 status page that: Entity/field definitions: The following changes were detected in the entity type and field definitions. ...
njp's user avatar
  • 707
16 votes
0 answers
11k views

How do I perform a redirect to a custom URL after login? [duplicate]

I am trying to redirect users to a custom URL after they logged in, but my code doesn't work. How do I redirect users after they logged in?
Gaurav's user avatar
  • 305
15 votes
1 answer
8k 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 ...
Ahmad's user avatar
  • 2,835
15 votes
4 answers
14k views

Retrieve translated taxonomy term in current language programatically

How do I retrieve a specified taxonomy term translated (if translation exists for this term) from the current language context programmatically with D8?
David DIVERRES's user avatar
15 votes
1 answer
7k views

How do I get Views content items in "my language" but fall back to "default" if the content isn't translated?

This is probably very easy but endless searching has proved fruitless - there's lots of UI changes between the D7 and D8 versions of these modules it seems. What I want to do is create a blog in two ...
NikLP's user avatar
  • 1,013
15 votes
1 answer
8k views

How to get an array of referenced entity ids from an entity reference field

I have a entity_reference field with BaseFieldDefinition::CARDINALITY_UNLIMITED cardinality. I want a list of referenced entity ids. I know that I can get all the referenced entities by calling $x->...
Rainer Feike's user avatar
  • 2,556