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.

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 ...
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'...
13
votes
3answers
15k views

How can I implement AJAX form submission?

My task is to submit contact form via AJAX and then to show "Thank you for submission!" message, loaded in place where the form was. So I need to ajaxify existing contact form. I found some examples ...
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 ...
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']); ?...
13
votes
3answers
22k views

Add a custom submission handler to a form

How can I add a custom form submission handler? I tried adding $form['#submit'][] = 'mymodule_form_submit'; or $form['actions']['submit']['#submit'][] = 'mymodule_form_submit'; to hook_form_alter(). ...
11
votes
7answers
17k views

User login REST format

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....
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-...
8
votes
5answers
6k 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 ...
10
votes
1answer
5k views

drush/drush dev-master requires codegyre/robo ~1.0.0-beta1

I'm transitioning a Drupal 6 site to Drupal 8.1 so following the official instructions, I set up a new install in its own directory. Since this is only one site, I followed the instructions to put my ...
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 ...
13
votes
5answers
5k views

What is the correct composer based 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 ...
15
votes
2answers
6k views

How to create a empty module? [closed]

What is the most basic valid module one can create in Drupal? It would be useful to have a simple blueprint available, for anyone just getting started with Drupal.
4
votes
2answers
3k views

Change a normal submit 'input' type to 'button' type with button tag

Is it possible in Drupal 8 to change a regular form submit button from Drupal into a button tag? This is the output I need to achieve: <button type="button" class="search-box__button"> <...
13
votes
3answers
9k views

How do I alter the route defined by another module?

In other words, what is the Drupl 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 ...
4
votes
6answers
4k views

How to print paragraphs in twig template

I have a content type, basic, where i have added a Paragraph field (field_pr) that has two fields: field_text, field_color. I have a twig template node--basic--full.html.twig where i want to print the ...
3
votes
2answers
1k views

Search results only for the current language

I have a site with 4 languages and am using the builtin search to look for content on the site. How is it possible to restrict the search results only to the currently selected language? I tried ...
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 ...
9
votes
6answers
9k views

How do I programmatically place a block?

From UI you can add a block in a region in that way: Go to Admin -> Structure -> Block layout (/admin/structure/block). Click on "Place block" button besides the region name. I want to do the ...
15
votes
7answers
14k views

How do I correctly setup caching for my custom block showing content depending on the current node?

I have this very basic block which just shows the current node's ID. <?php /** * @file * Contains \Drupal\mymodule\Plugin\Block\ExampleEmptyBlock. */ namespace Drupal\mymodule\Plugin\Block; ...
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 ...
3
votes
3answers
1k views

What is easiest way to debug variables in nodes, views, blocks and page twig templates?

What is easiest way to debug variables in nodes,views,blocks and page template. Earlier we used devel module in drupal 7 ,by using dpm() function it shows very neat and clean structure ,it was so ...
4
votes
2answers
698 views

Selecting taxonomy term in article and showing all articles titles associated with this term

I have a content type article and when editing an article there should be a field where you can select a taxonomy term of a specific vocabulary. When viewing the article it should show a list of ...
9
votes
5answers
11k views

How to override page title by content type

I'm using the pagetitle core module to render a page title. However, for certain content types I want the page main title to be the content type label (e.g. "News") and not the node label (e.g. "...
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 ...
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) ...
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?
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?
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?
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". ...
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 ...
10
votes
1answer
1k views

Multilingual content and single language admin interface

I want my site's content to be multi-lingual. I have a language switcher that can toggle between both the English and Spanish translations of a page. I want the administrative interface to always be ...
9
votes
1answer
10k views

Send a form to twig template

How I can pass a form to twig template in Drupal 8? For example, I get this: a form: mymodule/src/Form/MyForm.php Then on my Controller: public function myController() { ?????? return [ ...
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?
3
votes
3answers
7k views

Implementing CKeditor's plugin

I need to add the Templates plugin into Drupal8 CKeditor. So far it is available on the editor configuration page, but not on a node edit page. The code: namespace Drupal\module_name\Plugin\...
9
votes
1answer
3k views

Managing module library dependencies with composer

I've found Dependencies in a custom module with drupal-composer, How can I include a third party library in my custom module without using Composer Manager and How to manage contrib modules composer ...
7
votes
4answers
3k views

Anonymous user cache control

We have written some custom blocks that render dynamic content; unfortunately, the caching defaults cache the first render of this block (and don't refresh for anonymous users). Cache control seems to ...
6
votes
7answers
6k views

How to replace the search submit button with a Font Awesome character?

I would like to replace the search submit button with a Font Awesome character like the Magnifier (Search Icon) character, and put Search the site inside the search box. How can I achieve something ...
6
votes
8answers
8k views

How do I store the values submitted in a form in the session?

I want to submit a form and store the submitted values in the session. In Drupal 7 I just used $_SESSION['key'] = $value; but how do I correctly implement this in Drupal 8?
8
votes
2answers
15k views

Programatically print blocks in twig [duplicate]

In drupal 8 I want to print the block programatically. For this I have tried the below code but not working. function theme_preprocess_page(&$variables) { $block = \Drupal\block\Entity\Block::...
2
votes
1answer
4k views

AJAX callback on form item generated by AJAX

I'm trying to add AJAX callback to form element that was previously rendered by AJAX but with no luck. Code below. A bit of description. There are three main methods here: buildForm - base form ...
9
votes
4answers
6k views

How to configure an exposed filter in a view using a date picker?

How can I configure an exposed filter so that users can filter my site content by creation date, preferably using a date picker? I tried using Content: Authored on as filter, but it gets me a text ...
2
votes
2answers
5k views

Adding a class to “body”

I'm trying to add a custom CSS class to the <body> tag, How can I modify or pre-process the <body> tag to add the class body, Is it right to style the <body> tag with css file?
1
vote
2answers
1k views

How to force a redirect (override the destination query string in the URL)

I have a custom form submit callback to redirect users to a specific page: function MYMODULE_authfrontpageredirect_callback(array &$form, FormStateInterface &$form_state) { $url = \Drupal::...
1
vote
3answers
11k views

Get current language in template

In drupal 7 Language is global variable we can access it simple with global $language; $language=$language->language; I want to know how we can access current language in twig file in drupal 8(...
0
votes
2answers
747 views

How to render specific form elements from the *.theme file

I am using Drupal 8 and would like to customize how form elements are being displayed. Specifically, I don't like how uneditable, populated textfields are displayed as plain text. I would have it ...
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?
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 ...
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"; ...