Skip to main content

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
28 votes
10 answers
8k views

How to prevent Devel module to be installed on production environments

Using the new Drupal 8 Configuration manager, how can I prevent it from installing the Devel module on certain environments? As far as I know, installing it on my local means the next time I export ...
cambraca's user avatar
  • 745
26 votes
5 answers
41k views

How can I prevent a particular page being cached?

I have activated the cache on my Drupal 8 site, and of course all pages are cached as expected. However, I'd like to have a specific page bypass that cache. In my controller I built the page as ...
rpayanm's user avatar
  • 3,611
26 votes
5 answers
55k views

How do I programmatically render a view with contextual filters?

How do I programmatically render a view with contextual filters in Drupal 8? In Drupal 7, I generally use the following code. $view = views_get_view('test_view'); //test_view is the view machine ...
Sanjay's user avatar
  • 650
26 votes
10 answers
21k 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 ...
Chris's user avatar
  • 991
26 votes
4 answers
44k views

Programmatically updating a node

I can create a node using the following code: $node = \Drupal::entityTypeManager()->getStorage('node')->create($array); But if I have the node ID, how can I edit a node?
BOES's user avatar
  • 1,023
25 votes
8 answers
34k views

How do I get the route name of a view page?

In my custom submit handler I want to redirect to a view page Url, let's suppose my view name is team and its path is /admin/team, I find out I should use $from_state->setRedirect('route'); but ...
David Mcsmith's user avatar
25 votes
5 answers
27k views

How can I get the node ID from a path alias?

I want to be able to get the nid but the only information I have is http://example.com/this-is-the-alias. Is there a way to get either the internal path of /node/* for that alias if I am not on the ...
BrandenB171's user avatar
  • 1,112
25 votes
2 answers
13k views

Downloading core via command-line

I usually download the latest Drupal 7 using drush dl drupal --select, but but Drupal 8 doesn't get listed. What are some nice and quick ways of download the latest version of Drupal 8, even though ...
Patoshi パトシ's user avatar
24 votes
6 answers
33k views

How to get bundle label from entity

How do I get the human-readable label of a bundle from a loaded entity. Lets say I want to get the label of a node of bundle my_article which is "My awesome article" // Load a node $node = Drupal::...
Linus's user avatar
  • 1,307
24 votes
7 answers
59k views

Get the image URL

I want to render an image as a background image via an inline style in twig. I created a field called bg_image and attached it to the standard plain page. After fiddling around for hours I was able ...
Jannis Hell's user avatar
24 votes
3 answers
20k 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 ...
dbj44's user avatar
  • 4,764
24 votes
6 answers
41k views

How do I render a form?

What is the alternative to drupal_get_form('user_login'). in Drupal 8? I am using the following code in theme_name.theme, but it doesn't work. // Include namespace for userLoginForm. use \Drupal\...
Kamal Oberoi's user avatar
24 votes
1 answer
3k views

Why are routing files filled with underscores?

What is the deal with all the parameters with, and without, a prefixed underscore character? Where does Drupal decide how to process these parameters? Was this concept introduced from Symfony, or is ...
Daniel's user avatar
  • 1,652
23 votes
3 answers
29k views

Get all fields defined in a bundle

In Drupal 7, to get all fields used in a content type, I use the following code. $fields = field_info_instances('node', 'article'); What is the equivalent for Drupal 8?
Pravin Ajaaz's user avatar
  • 3,552
23 votes
5 answers
42k views

Verify a field is not empty

What is the best method to check if a field is empty in a node template. In node--example.html.twig we can use "content" variable. I can't use check like checking a block {% if content....
sainf's user avatar
  • 375
23 votes
4 answers
20k views

Non-Clickable Menu Items

In a Drupal 8 site, I want to add menu items with "no link", I was thinking that nolink is allowed but when I entered this, I got error Manually entered paths should start with /, ? or #. Is ...
Mohamed Osama Gbril's user avatar
23 votes
2 answers
37k views

Get the real path of a file

I am creating an Excel reading module in Drupal 8. I want to get the real path of a file for reading it from a path like public://2016-03/Places.xls. What function should I call for getting the real ...
Nisam's user avatar
  • 725
23 votes
4 answers
49k views

Perform a query with an entity field condition with multiple values

I have a content type that has a entity reference field that allows users to add multiple taxonomy terms in that field. I'm attempting to perform queries that grab nodes that have a specific set of ...
Amy's user avatar
  • 5,738
23 votes
4 answers
1k 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, ...
Jon Freed's user avatar
  • 1,051
22 votes
7 answers
33k views

Include a partial template

I'm trying to use Drupal 8, with a custom theme, due big structure differences for my requirements I have a page--front.twig.html and a page.twig.html, I would like to create template parts as used in ...
felipep's user avatar
  • 332
22 votes
6 answers
25k views

How to solve the "The following module is missing from the file system" error?

I am getting the following error in a Drupal 8 site. The following module is missing from the file system It looks as if a custom module was installed and deleted without uninstalling it. How ...
Kevin's user avatar
  • 27.9k
22 votes
8 answers
48k views

How to print custom date format in Twig?

How can I print a custom date format in Twig? First of all my I am trying to edit the field.html.twig of the field called field_publication_date, in that file I find this variable {{ item.content }} ...
Ricardo Castañeda's user avatar
22 votes
6 answers
14k views

Release cron lock

I ran cron and aborted the execution. Now I get this message: Attempting to re-run cron while it is already running. In Drupal 7, I could delete the cron_semaphore variable. What's the way to ...
Cesar Moore's user avatar
  • 1,538
22 votes
6 answers
30k views

Site UUID in source storage does not match the target storage

When I run drush cim -y on my staging instance of my site I get the following error: Drupal\Core\Config\ConfigImporterException: There were errors validating the config synchronization. in Drupal\...
albertski's user avatar
  • 3,487
22 votes
2 answers
5k views

Why is it not recommended to change the default language?

I have a fresh installation of Drupal 8.2.5 and want to use it for mostly Spanish content, but keeping the admin interface in English. /admin/config/regional/language says, It is not recommended to ...
Pedro's user avatar
  • 321
21 votes
4 answers
21k views

Programmatically redirect users to the default "access restricted"

I would like to programmatically redirect my users to the default "access restricted" page. I know that I need a "RedirectResponse" object for a simple redirect, but how do I specify the default "...
jepster's user avatar
  • 953
21 votes
5 answers
37k views

How do I set up CORS?

Drupal 8 has RESTful web service in-built in core and since 8.2 we don't need cors module. Now to use services we just enable and configure default.service.yml file as specified in here However, I ...
sarathkm's user avatar
  • 558
21 votes
7 answers
42k views

How to show a date in the correct timezone?

I have a Datetime Range field (field_date) in a content type. Once I create my content type I set the Start Date as: 2017-02-27 19:30:01 Now I want to get the value and show the date in other format,...
Adrian Cid Almaguer's user avatar
21 votes
7 answers
54k views

Redirect after form submission

I created a custom form in Drupal 8. I remember we can redirect to custom path in Drupal 7 with $form_state['redirect'] = 'mycustompath'; in a submission handler. How can I achieve the same in Drupal ...
Yuseferi's user avatar
  • 22.1k
21 votes
3 answers
15k views

How to disable aggregation from either drush or PHPmyadmin?

I've been searching for this and ALL I found deals with Drupal 7. Old drush command drush vset preprocess_js 0 doesn't work for Drupal 8 and the "variable" table in DB doesn't exist in 8... Yet, I ...
21 votes
6 answers
34k views

Check if the user is logged-in in a theme

In Drupal 7 we can simply check if the current user is logged-in in a theme by checking $GLOBAL['user']->uid or using user_is_logged_in(). How can I check if a user is logged-in in a page ...
Yuseferi's user avatar
  • 22.1k
21 votes
3 answers
72k views

Programmatically update a field's value

I want to update a node field's value when a node is updated. Tried using the code mentioned here Programmatically updating a node Drupal 8 use Drupal\node\Entity\Node; function ...
No Sssweat's user avatar
  • 31.4k
21 votes
3 answers
23k views

How do I alter the route defined by another module?

In other words, what is the Drupal 8 equivalent of hook_menu_alter()? Drupal 8 still uses hook_menu(), but for what I can see, the information returned by the hook is different from what the hook ...
avpaderno's user avatar
  • 97.6k
21 votes
6 answers
28k views

How to filter a View by Date Range (start, end)?

In Drupal 7 with Views an Date module enabled, it was pretty easy to filter a view by Date: The UI just gave you the option to do so. In Drupal 8, however, the date field and views are part of core, ...
user5950's user avatar
  • 2,048
20 votes
9 answers
47k 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?
Anu Mathew's user avatar
20 votes
3 answers
4k views

Which contributed modules are being moved into Drupal 8 core?

There were a significant number of D6 modules (or versions of) that were pulled into D7 core. I am wondering if there are any for D8?
20 votes
6 answers
25k 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', $...
Kevin's user avatar
  • 2,566
20 votes
5 answers
8k 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
20 votes
6 answers
18k views

How can I control block visibility with code?

In Drupal 6, I could control block visibility using PHP code in the block UI configuration like: <?php return MYMODULE_abc() || MYMODULE_def() ; ?> These functions looked up the current node, ...
Nic's user avatar
  • 1,215
20 votes
2 answers
32k 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 ...
kraftybasterd's user avatar
20 votes
1 answer
14k views

Load a file entity by URI

Is there a way to load a file by URI in Drupal 8? In Drupal 7, it is possible using the following code. $uri = 'public://file.xyz'; // Take a look at: file.inc::file_load_multiple $files = ...
voleger's user avatar
  • 960
20 votes
4 answers
6k views

Should I ignore the "vendor" directory?

I'm finally trying to get on board with using Drupal 8 and want to know if I should ignore the vendor directory in git with .gitignore. I would assume not, but I've seen a few example .gitignore files ...
Christia's user avatar
  • 1,667
20 votes
2 answers
42k views

How do I change the base URL?

In Drupal 7, we can quickly change the base URL of the website. How can I do this, in Drupal 8?
spacecodeur's user avatar
  • 1,339
20 votes
1 answer
36k 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 ...
Axel Briche's user avatar
  • 1,991
20 votes
1 answer
14k views

Implementing Custom Cache Tags

I would like to use the new Cache Tagging in D8 to help keep related content of different types (entities, nodes, blocks, etc) in sync. But from reading the currently available documentation of this ...
LittleCoding's user avatar
19 votes
19 answers
35k views

Redirect after user login

I would like to redirect users after they log in. Is it possible to use hook_user_login() to make the redirection? How do I add the parameter for the redirection?
johnchan's user avatar
  • 371
19 votes
5 answers
18k 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,844
19 votes
5 answers
28k views

How do I get the node type label from a node object?

I'm trying to get the bundle label (node type label) of the node from a node object in Drupal 8. This works, but seems long-winded: $node_type = \Drupal::entityManager()->getStorage('node_type')-&...
oknate's user avatar
  • 14.4k
19 votes
7 answers
45k views

How do I programmatically log in a user with a POST request?

Do anyone have a working REST Login on Drupal 8? This is what I tried. POST /user/login HTTP/1.1 Host: 8.d8.local Content-Type: application/x-www-form-urlencoded Accept-Encoding: http://nikhilmohan.in ...
niksmac's user avatar
  • 7,692
19 votes
9 answers
25k views

How do I set the theme logo?

How can I set the logo in my custom theme in Drupal 8? I can see that Drupal looks for the logo.svg file. I have a PNG logo.png file that I used in Drupal 7 and I would like to re-use it. I cannot ...
batigolix's user avatar
  • 2,614