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
27 votes
8 answers
24k views

Taxonomy term name as contextual filter for view

In D7 I was able to filter a view according to a taxonomy term name taken from the URL. An example would be this URL http://www.gbyte.co/tags/drupal-planet/rss.xml "drupal-planet" would be converted ...
gbyte's user avatar
  • 777
26 votes
5 answers
53k 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
43k 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
5 answers
39k 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,581
25 votes
8 answers
32k 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
4 answers
25k 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
7 answers
58k 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,734
24 votes
6 answers
39k 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
28k 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,532
23 votes
6 answers
31k 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,297
23 votes
5 answers
41k 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
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
6 answers
32k 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
8 answers
46k 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
13k 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,528
22 votes
4 answers
47k 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,632
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
6 answers
23k 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.7k
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
  • 943
21 votes
2 answers
34k 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
  • 695
21 votes
7 answers
40k 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
6 answers
33k 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
  • 21.8k
21 votes
3 answers
69k 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.1k
21 votes
3 answers
22k 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 ...
apaderno's user avatar
  • 97k
21 votes
6 answers
27k 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,018
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,558
20 votes
7 answers
51k 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
  • 21.8k
20 votes
4 answers
8k views

When should I use Backdrop CMS rather than Drupal 8? [closed]

From what I've heard, Backdrop is basically an alternative to Drupal 8. Is deciding which one to use simply a matter of preference and ideology, or are there specific use cases for each? If I'm ...
20 votes
2 answers
31k 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
13k 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
  • 950
20 votes
6 answers
28k 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,447
20 votes
2 answers
41k 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,329
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,961
20 votes
1 answer
13k 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
9 answers
45k 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
19 votes
7 answers
44k 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,682
19 votes
5 answers
26k 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.1k
19 votes
5 answers
34k 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
  • 538
19 votes
9 answers
24k 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,584
19 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,205
19 votes
3 answers
14k 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 ...
19 votes
3 answers
12k views

What is the command that replaces 'drush variable-set'?

In Drupal 8 the Drush command drush variable-set no longer works. From reading (here) it appears that Drupal 8 has a new "configuration" system that replaces the old (Drupal <=7) "variables". But ...
Jeremy Davis's user avatar
19 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,637
18 votes
18 answers
33k 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
  • 361