Stack Exchange Network

Stack Exchange network consists of 175 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.

9
votes
3answers
6k views

If you update a routes file in Drupal 8 how do you clear the cache?

Having worked with Drupal 7 since its launch, I'm learning Drupal 8. At the moment I'm finding that whenever I change anything I have to do drush cache-rebuild to get things working again. On my VPS ...
9
votes
5answers
9k 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')-&...
9
votes
2answers
2k views

How to add a variable to a twig field template?

On a node page I would like to add the node title to the output alongside another another field (the example field). I have created a new field--field-example.html.twig but am unable to access the ...
9
votes
2answers
8k views

RuntimeException: Unable to determine class for field type found in the configuration

My website got this error, while updating from Drupal 8.3.7 to Drupal 8.4.0, and I am unable to solve it. The website encountered an unexpected error. Please try again later. RuntimeException: ...
9
votes
4answers
6k views

How can I programmatically get the theme name?

In Drupal 8, is there a way to figure out what theme you are currently using in a module? I need to get the name programmatically within the code of a module.
9
votes
4answers
12k views

How to trim body text (field_body)?

I've created a view for a node which shows the content as rendered entity. Among others, I output the body field in the twig template: {{ content.field_body }} Now, I'd like to limit the text to 200 ...
9
votes
4answers
10k views

How can I re-install a module?

I am creating on Drupal 8 module. I have used a custom table to store the data collected from forms. Somehow during installation, tables are not created due to an issue in the install file. Now I have ...
9
votes
2answers
9k 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 ...
9
votes
2answers
10k views

What is the equivalent of hook_menu_alter() to change a menu item type?

I want to change the menu type in Drupal 8. In Drupal 7 we can achieve this using hook_menu_alter function module_menu_alter(&$items) { $items['admin/config/people/ip-blocking/default'] = array(...
9
votes
4answers
13k views

How do I get the username from the user ID?

I want to print the username knowing just the user ID. How do I achieve this?
9
votes
1answer
9k views

Use drush to put a site in maintenance mode [duplicate]

drush @mysite cget system.maintenance shows: message: '@mysite is currently under maintenance. We should be back shortly. Thank you for your patience.' langcode: en Drupal 8 uses state ...
9
votes
5answers
16k views

How do I add a CSS class to a form label?

I want to add a CSS class to a label on a page that is using Drupal 8 Form API. I have been unable to find a reference online on how to apply that. I have used the following workaround, but it ...
9
votes
3answers
5k views

Configuration export/import not working for taxonomy terms in Drupal 8

I did a drush config-export staging on a local version of my site then a drush config-import staging on the server. It imported all the taxonomy vocabulary but no terms. I also tried it via the UI (...
9
votes
5answers
2k views

How do I find available public methods?

I'm finding that the biggest problem in working with Drupal 8 is I can't get the data I need. Drupal 8 wants me to use public methods rather than manually drilling down thru an object. The problem ...
9
votes
4answers
2k views

How to display more than 10 items in link widget autocomplete?

This is a question about the Link module. Since with the Link module you can enter external or internal links both, we strongly rely on it. Unfortunately the number of items to be displayed from its ...
9
votes
3answers
6k views

Retrieve translated taxonomy term in current language programatically

How do I retrieve a specified taxonomy term translated (if translation exists for this term) from the current language context programmatically with D8?
9
votes
4answers
11k views

Get the value of a custom user field

I have a custom form that needs to display a default value from a custom user field. The field was created under /admin/config/people/accounts/fields and its machine name is field_r_period_length_sec. ...
9
votes
2answers
16k views

Preprocess variables only for certain blocks

Is it possible preprocess variables only for certain blocks? I have created such function: mytheme_preprocess_block__aggregator(&$vars) but it doesn't works. -- EDIT -- It seems to be fixed in ...
9
votes
3answers
3k views

Get site name in custom template

I want to print the site name in a custom template (page--front.html.twig) {{ site_name }} does not work. If I use {{ page['#title'] }} I only get "Welcome to [site_name]". I'm looking for a way to ...
9
votes
2answers
7k views

How can I add items to the Admin Toolbar?

In Drupal 8, I want to add a menu item to the Admin Toolbar with a submenu, with different links. How can I do it?
9
votes
2answers
1k views

Image and Media Best Practices

I am looking for suggestions on Best Practices for D8 and files / media entities. I originally added this as a answer but kiamlaluno evidently felt that it should be a new question in itself so here ...
9
votes
4answers
1k views

How to rerun hook_post_update_NAME()

Drupal 8 introduced hook_post_update_NAME() which has some benefits over hook_update_n, for updating modules. Each hook_post_update_NAME() should only run once, but sometimes I want to rerun it, like ...
9
votes
3answers
5k views

Bootstrap from external script

I am trying to create Drupal entity instances from an external script that is not part of Drupal or a Drupal module. For Drupal 7 there was drupal_bootstrap to load the required Drupal dependencies. ...
9
votes
2answers
6k views

Disable cache for specific blocks

I would like to let pages continue to benefit from Drupal 8 caching mechanism for anonymous users, except for a specific blocks which should update on every page refresh knowing that they are ...
9
votes
1answer
3k views

Add a class to a Drupal table cell containing ['data']

In Drupal 8, rendering Tables is still a lot like Drupal 7. You build out multi-dimensional arrays of rows and columns in PHP that Drupal transforms into a <tr> and <td>s respectively. ...
9
votes
1answer
552 views

How do I add a column to the table shown in the vocabulary listing page?

I need to add a column to the table shown in the page listing the vocabularies defined for a site. How can I achieve this?
9
votes
2answers
4k views

Print image field with multiple entries from field in twig template

I have a twig template for a custom content type. And it is able to render most fields just fine, but I am unable to print an image field with multiple images. node--mycontenttype.html.twig contains ...
9
votes
2answers
5k views

How do I create and use a custom hook?

I posted a question here, which had one suggestion, but no answer. Does anyone have any advise on how to implement a custom hook in Drupal 8 which will allow other modules to update a table of ...
9
votes
1answer
2k views

What order should configuration import and module updates be run?

Since the schema version of modules is stored in the key-value storage, it is unique to each site and is not synced through configuration management. That makes sense, since updates may need to make ...
9
votes
1answer
6k views

How to use #element_validate and #value_callback in Drupal 8

I have followed the official Form API Documentation, but this code don't work for me on Drupal 8: public function buildForm(array $form, FormStateInterface $form_state) { $form['upload'] = ...
9
votes
1answer
2k views

How do I create custom user tabs?

I am trying to create a new custom tab that appears on all routes that are descendants of entity.{entity_type}.canonical. I have tried extending the DeriverBase class, specifically overriding the ...
9
votes
5answers
6k views

How to perform a redirect to custom page after node save or delete?

What I'm trying to do doesn't work, I still get redirected to /node/{id}: function hook_form_alter(&$form, $form_state, $form_id) { $form['actions']['submit']['#submit'][] = '...
9
votes
1answer
6k views

Trying to add an html head tag in Drupal 8, beta 2

With Drupal 8.0 beta2, drupal_add_html_head() has been deprecated in favor of #attached. So the old way was: function MYTHEME_page_build(&$page) { $viewport = array( '#type' => '...
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 ...
9
votes
5answers
2k views

“Source database does not contain a recognizable Drupal version.”

I have installed two Drupal sites in my local Ubuntu desktop 15.10 Apache2 (2.4.12) environment: One is a fresh install of Drupal 8 and The second is a copy of an existing working site built with ...
9
votes
4answers
5k views

Updating core from 8.2 to 8.3 via composer

I am trying to update Drupal core to 8.3 but am running into difficulties. At the bottom of the page is the composer.json file I am starting with. If i change "drupal/core": "~8.2" => "drupal/core"...
9
votes
1answer
810 views

How can I install composer packages with drush make?

How does one include composer package in a drush make file? The more general answer, the better. There's already a composer drush module allowing drush dl to handle composer packages, but that ...
9
votes
3answers
2k views

Get title of page

When I get the title on some pages, I get an empty title like Home. The code I am using in my subscriber is the following one. class HistorySubscriber implements EventSubscriberInterface { public ...
9
votes
2answers
1k views

Drupal Services OAuth

I have been working on this issue for a couple weeks now, and I can't find a solution for the life of me. The fact that I have found no decent documentation (on Drupal's website, or anywhere else) is ...
9
votes
0answers
7k views

Drush : Missing $settings['hash_salt'] in settings.php [closed]

I just setup a new Drupal environment with Mamp. I can access my website just fine, but whenever I want to run drush cr I get the following error : exception 'RuntimeException' with message 'Missing $...
8
votes
5answers
8k 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 ...
8
votes
2answers
5k views

why are Twig template variables with markup not being rendered?

In my template preprocess function I have a variable: $test = "<p>this is a paragraph</p>"; and I pass it to my template: $variables['test'] = $test; and output it in twig: {{test}} ...
8
votes
2answers
9k views

Programmatically get all names of an entity reference field

Example: I want to get all tag names that are inside field_tags of node 5. I can get the target_id with getValues(); But the problem is, I don't know what entity the target_id value belongs to. ...
8
votes
3answers
10k views

How to find image style URL from within twig template?

I'm implementing a node template that uses an image twice; once in a 'normal' way (i.e. using the image style defined in the field's display configuration for that view mode), and the other is as a ...
8
votes
2answers
8k views

What's hook_node_view alternative in Drupal 8?

I am using Drupal 8 Beta 14 and I want to edit the node object in teaser view mode. As hook_node_view is removed in Drupal 8. What's the alternative hook or some other way that I can use to edit the ...
8
votes
1answer
3k views

Has drupal abandoned drush?

I've been away from drupal for 2-3 years. I just came back around and installed drush via composer (like the drush site recommends) and now every time I try to use drush I get a message telling me ...
8
votes
4answers
4k views

Does Drupal Console aim to replace Drush?

Does Drupal Console (that is available for Drupal 8) aim to totally or partially replace Drush?
8
votes
4answers
8k views

Get an image from an article/entity

How do I easiest get an image (its path) from the article content type included in Drupal 8? What I have is an entity. Using $image = $node->fields['field_image'] gives me a hell of a structure, ...
8
votes
3answers
13k views

How do I make a theme require Jquery (for anonymous users)?

I'm creating a theme for D8 called 'herchel'.I'm trying to get this theme to require jquery on all pages (D8 doesn't load Jquery for anonymous users by default) Looking through the what little ...
8
votes
3answers
13k views

How to use presave hook to save a field value as node title?

I have a custom date field in a node type 'day'. When the node is saved (or edited then saved), I would like to get the field_date value (not the published date) and save it into the title field. I ...