Questions tagged [8]

Version tag to tag issues specifically related to Drupal 8.x. Please note that 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
66
votes
5answers
52k views

What does “The provided host name is not valid for this server” mean?

I am running a Drupal 8 website, and when I browse to any page, I get a plain white page with just the following error message on it. The provided host name is not valid for this server. What does ...
63
votes
9answers
131k views

How do I access a field value for an entity (e.g. node) object?

node_load((int) $nid) loads a fully-populated node entity. $node->title->value gets the title, but how do I access field values in Drupal 8?
56
votes
8answers
95k views

How do I get the current path alias or path?

How can I get the current alias and/or path in Drupal 8? In Drupal 7 I did this with drupal_get_path_alias(). What is the equivalent code I should use in Drupal 8?
52
votes
2answers
29k views

What are all the directories for in the new Drupal 8 structure?

Drupal 8 re-arranged all the directories and locations of modules/themes etc. Where do things go now?
51
votes
4answers
74k views

How do I get the current node ID?

In Drupal 7, if I wanted to get to get the node id of the currently displayed node (e.g. node/145) I could get it with the arg() function. In this case, arg(1) would return 145. How can I achieve the ...
50
votes
7answers
34k views

How can I import the configuration on a different site?

I have this error when I try to import the config of an another site: The staged configuration cannot be imported, because it originates from a different site than this site. You can only ...
42
votes
15answers
72k views

Getting the image URL from a field_image on a node

So I have this Node: object(Drupal\node\Entity\Node)[1862] protected 'values' => array (size=17) 'vid' => array (size=1) 'x-default' => string '7' (length=1) ...
42
votes
13answers
29k views

How do I remove a configuration object from the active configuration?

I'm writing a custom module for Drupal 8. It defines a field storage configuration object, in a file called modules/mymod/config/install/field.storage.bloom_stem.bs_twitter_ac.yml. The problem is ...
41
votes
4answers
2k views

What is the suggested workflow for migrating (CMI) configuration from dev -> stage -> production?

We had a drupalcamp a few months back and someone asked about managing deployments with the new config (CMI) system. One possible ideal workflow would involve keeping the config in version control and ...
40
votes
10answers
46k views

Manually disable a module

In Drupal 7, I could manually edit the {system} table in the database to disable a stubbon module. In my Drupal 8 site, this table is gone. How can I manually disable a module in Drupal 8?
36
votes
9answers
47k 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 ...
35
votes
4answers
46k 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 ...
35
votes
4answers
43k 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://...
34
votes
9answers
52k views

How can I programmatically display a block?

I'm developing a site using Drupal 8 beta-14. I've created a view block of different terms and now I want to display it using code. How can I display it programatically? I used to do it in Drupal 7 ...
34
votes
7answers
44k views

Programmatically create nodes

How can I programmatically create nodes with date and image fields? I know I can do it in Drupal 7 with the following code. global $user; $node = new stdClass(); $node->title = "YOUR TITLE"; ...
33
votes
6answers
11k views

How do I update the configuration of a module?

I'm building a custom module in Drupal 8. It includes some YAML config files. As I develop I need to change and add to the config, e.g. to add another field onto my custom entity. At present the ...
32
votes
6answers
21k views

Programmatically create a term?

I'm attempting to add a lot of terms (~200) to a vocabulary, but I can't find any import modules that are updated for Drupal 8, and it seems the functions for doing this in Drupal 7 don't exist in ...
31
votes
3answers
38k views

How do I get the user ID for the currently logged-in user?

I want to get current user object (user information) in Drupal 8. I know in Drupal 7 there was a global $user variable; I want to know how I can get current user object in Drupal 8.
31
votes
6answers
47k views

How do I translate strings in Twig templates?

I am working on a (my first) Drupal 8 project witch is a multilingual site. Drupal 8 really delivers in terms of native support for content translation. However, I have a few strings set directly in ...
30
votes
6answers
51k views

How to get the valid URL of a Link field from within a Twig template?

I have a Link field named field_my_link (machine name). Within a Twig template I can get the link's URL value with this: {{ node.field_my_link.uri }} If inside the Link's URL there is an external ...
30
votes
3answers
18k views

How know if user is visitor or logged member?

How can I determine programatically whether the current user is anonymous or authenticated?
29
votes
11answers
35k views

How do I set the page title?

I know I could change the page title with drupal_set_title(t('Amy page title')), but when I try it in Drupal 8 I get the There is no such function error. How can I change page title in Drupal 8?
28
votes
3answers
40k views

Programatically render a block in a twig template

I need to render a views block in my page.html.twig template. In D7 I would do this: <?php $block = module_invoke('module_name', 'block_view', 'block_delta'); print render($block['content']); ?...
28
votes
1answer
22k views

How to check if field exists in an entity?

In entity node, I want to check if 'abc' field exists or not. If exists, I will get its value by $value->get('abc'). But the content type where this field doesn't exists, gives error: The website ...
27
votes
9answers
53k views

How do I create a link?

Say I am extending The blockBase class to create a custom block, and I am implementing the blockBuild method to create some markup for my block. Something like this: class YourModuleBlock extends ...
27
votes
11answers
57k views

“The website encountered an unexpected error. Please try again later.”

I have this error with Drupal 7 how can I have some more information about this error ? Any report, any log anywhere ? Nothing in php errors. how can I disable that message and have a more useful ...
27
votes
3answers
59k views

How do I get the raw field value in a twig template?

myfield is a plain text field. {{ content.field_myfield }} renders the field with HTML markup and the field label. How do I render the raw value of the field? {{ content.field_myfield.value }} doesn'...
26
votes
3answers
21k views

How do I export/import views?

I know how to do it in Drupal 6/7, but I cannot find where to export/import views in Drupal 8. From which admin page is possible to do it, in Drupal 8?
26
votes
9answers
4k 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 ...
25
votes
2answers
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 ...
24
votes
4answers
19k views

Pass raw html to #markup

I have some html content, it comes from a external library so i can not change it, it has many <span> and <div> tags with attributes like: <span style="color: #0000ff;">, but when i ...
24
votes
1answer
33k views

Get the route name of the current page

The route name of the current page is available in page.html.twig? The page is generated by the default feedback form.
24
votes
1answer
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 ...
24
votes
4answers
907 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, ...
24
votes
8answers
7k views

How do I migrate block content from a dev to a production site?

I've finally started looking at Drupal 8 seriously and I'm particularly interested in the configuration management. I've come across something that could be a little bit problematic and that's ...
23
votes
5answers
29k views

Iterate through multiple value content field in Twig template

I need to take control over the rendering of a field_admin_tags field in a node.html.twig template. This WORKS: {{ content.field_admin_tags }} — Renders everything (label + all field values) {{ ...
23
votes
2answers
27k views

Programmatically update an entity reference field

I know I can update (or set a value for) an entity reference field in Drupal 7 with code similar to the following. $node['field_code_used_by'][LANGUAGE_NONE][0]['target_id'] = $id; I want to ...
22
votes
7answers
35k views

Get path alias from NID (or node object)

I have a node object, and I am trying to use it to get a given path in Drupal 8. There was drupal_lookup_path() in Drupal 7 but I'm not seeing any equivalent or documentation for Drupal 8. What's ...
22
votes
3answers
49k views

Get path to theme assets in Twig template

I have a question about getting a path to an image in a Twig template. The image is not assigned to a field or something. Just a static image which is stored in "MYTHEME/image/icon/my-icon.png". In ...
22
votes
5answers
38k views

Get Image URL in Twig

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 ...
22
votes
4answers
12k views

How do I re-run updates (change module schema version)?

I'm working on a module, and I changed a couple field types in the schema. I didn't take a backup before testing it and messed up the DB (it's just a dev site). Anyway, I reinstalled everything, and ...
22
votes
3answers
18k 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)...
21
votes
7answers
42k views

How do I add a custom validation handler to an existing form/field?

How do I add a custom validation handler to an existing form (or form field) in Drupal 8? I have a form that I haven't created. I want to add my own validation rules on some fields when the form is ...
21
votes
5answers
27k views

Get all nodes of given type

I would like to get all nodes that are of my_custom_type type in Drupal 8. I know I can get all the nodes (of any type) with \Drupal\node\Entity\Node::loadMultiple() and the list of all types by \...
21
votes
10answers
16k 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 ...
21
votes
5answers
19k views

Load term by name

In Drupal 7, we can load the term using name for ex. taxonomy_get_term_by_name($name) Is there any way to load term via given name in Drupal 8?
21
votes
7answers
58k views

How do I clear cache using an SQL query?

After a module update, my site has become unusable, and only shows a php error message. I tried circumventing the problem with drush cc, but that didn't help. Also tried with a custom php script but ...
21
votes
4answers
13k 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 ...
21
votes
3answers
12k views

Import a single yml configuration file

Is it possible to import one single yml configuration file by specifying its path? Or a group of yml files contained in a specific module?
20
votes
3answers
3k 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?