Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

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.

56
votes
4answers
35k 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 ...
51
votes
9answers
93k 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?
51
votes
2answers
27k 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?
41
votes
7answers
65k views

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?
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
14answers
51k 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) ...
40
votes
4answers
51k 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 ...
40
votes
7answers
22k 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 ...
39
votes
10answers
21k 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 ...
35
votes
8answers
33k 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?
29
votes
7answers
32k 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"; ...
29
votes
8answers
33k 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 ...
28
votes
5answers
7k 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 ...
27
votes
3answers
30k 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 ...
27
votes
3answers
24k 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.
26
votes
8answers
36k 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 ...
26
votes
3answers
33k 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']); ?...
26
votes
4answers
809 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, ...
25
votes
5answers
32k 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 ...
25
votes
3answers
16k 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?
25
votes
10answers
48k 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 ...
25
votes
2answers
12k 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 ...
25
votes
10answers
24k 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?
25
votes
9answers
3k views

How to prevent devel module to be installed on production enviroments?

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 ...
24
votes
5answers
16k 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 ...
23
votes
10answers
42k 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 ...
23
votes
3answers
25k 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://...
23
votes
1answer
2k 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 ...
22
votes
4answers
30k 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 ...
21
votes
3answers
13k views

How know if user is visitor or logged member?

How can I determine programatically whether the current user is anonymous or authenticated?
21
votes
1answer
15k 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 ...
21
votes
7answers
5k 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 ...
20
votes
3answers
2k 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
9answers
13k 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 ...
20
votes
4answers
12k 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 ...
20
votes
3answers
21k views

How to turn off drupal registration

Recently I've been receiving a lot spam registrations. My website is quite basic and I do not need for users register. what would the likely url be that the spam bots are finding? is there a way to ...
20
votes
2answers
17k 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 ...
20
votes
3answers
2k 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 ...
19
votes
5answers
28k 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 ...
19
votes
9answers
43k views

Create template file for views block

There is a lot about theming custom blocks, but what about blocks created by views? My views block has id: block-views-posts-listing-block, I try many ways for naming template file, ex: block--block-...
19
votes
5answers
17k 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) {{ ...
19
votes
2answers
33k 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'...
19
votes
1answer
27k 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 ...
18
votes
1answer
21k 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.
18
votes
1answer
3k views

How can I change the active theme programmatically?

How can I change the active Drupal 8 theme programmatically? In Drupal 6, we used the following code. global $custom_theme; $custom_theme = 'garland'; In Drupal 7, we used hook_custom_theme(). In ...
17
votes
6answers
18k 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 ...
17
votes
10answers
28k views

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

It's all in the title: how to add a custom validation to an existing form (or form field) in Drupal 8? I have a form that I haven't created that I want to alter to execute my own validation rules on ...
17
votes
3answers
35k views

get path to image (src) from twig template

i have a question about getting a path to an image in a twig template. The image is not assigned to an field or something. Just an static image which is stored in "template/image/icon/my-icon.png". ...
17
votes
5answers
17k 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\...
17
votes
2answers
8k 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 ...