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.

13
votes
5answers
19k views

How to get each field value in views-views-unformatted--view-machine-name.html.twig?

I have an twig file: views-view-unformatted--view-machine-name.html.twig {# /** * @file * Default theme implementation to display a view of unformatted rows. * * Available variables: * - title: ...
13
votes
3answers
10k views

How do I get users by role programmatically

In Drupal 8 I need to get all users by given role name.
13
votes
3answers
16k views

How do I disable Twig and block cache for a specific module?

I'm working on a module in Drupal 8 which retrieves time sensitive data from an external REST api. The data is processed and forwarded to a Block. The final data is sent to a Twig template like so: .....
13
votes
6answers
13k views

How to embed a view in a specific node?

I try to embed a view in a specific node. I found tutorials for doing this with Drupal 7 and PHP-Templates: <?php print views_embed_view('view_name'); ?> But I look for a way in Drupal 8 with ...
13
votes
6answers
7k views

How can I make kint() load faster when debugging twig templates?

I've seen quite a bit of discussion about how kint() from the Devel module is difficult to work with because it maxes out PHP memory limits and makes the browser drag. I've heard some thoughts on ...
13
votes
4answers
5k views

Redirect Anonymous user to login page

I want if user not logged in and visit any page of my website except my REST VIEWS routers I redirect him/her to login page in drupal 8, I found this solutions for drupal 7 but didn't find any ...
13
votes
3answers
16k 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 ...
13
votes
3answers
3k views

Should I ignore the vendor directory in git for Drupal 8?

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 ...
13
votes
3answers
10k 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 ...
13
votes
3answers
4k views

What versions from the Symfony components are used from core?

Which Symfony version does Drupal use for the Symfony components? Is it a goal to support the latest versions of the components or is this simply not possible?
13
votes
3answers
3k views

What are cloned sites in Drupal 8?

When trying to export my site configurations from one Drupal 8 site to other I keep getting the following error The staged configuration cannot be imported, because it originates from a different ...
12
votes
5answers
36k views

How to get $_POST and $_GET parameters

I ajaxly call a route and pass data to it, In my controller, I want to get $_POST['var'] , $_POST['var2'], it seems because of using HttpFoundation in drupal 8, $_POST and $_GET are not exists in old ...
12
votes
9answers
27k views

Get taxonomy terms

I wanted to retrieve taxonomy terms from a certain vocabulary in Drupal 8. Apparently I can still do it using taxonomy_get_tree but it's deprecated. I now have to use TermStorageInterface::loadTree ...
12
votes
6answers
8k views

How to redirect an anonymous user to the login form after a 403 error?

I want to redirect an anonymous user to the login form if such user encounters a 403 error. I have created event subscriber and this is my code, but I end up on loop on the current page. /** * ...
12
votes
3answers
32k 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 ...
12
votes
5answers
11k 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::...
12
votes
4answers
15k 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', $...
12
votes
3answers
16k views

How to create a redirection programmatically? [closed]

I try to create a redirection 301 with the redirect module. For example, I want to redirect an URL source to an internal URL through my custom module. I want to create a redirection when I create a ...
12
votes
4answers
7k views

Looking for database insert example

According to db_insert manual page this function is deprecated and it is better to use Drupal 8 database connection to perform insert. Deprecated as of Drupal 8.0.x, will be removed in Drupal ...
12
votes
3answers
7k 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 ...
12
votes
2answers
6k views

How to get the human readable content type name in a node template

I have created node template for my node, and its working fine. I need to print content type name, which is like "Whitepaper" and has machine name "w1" in my node template. If I use variable {{ node....
12
votes
1answer
14k views

Set the templatefor the frontpage

How do I change the Drupal 8 frontpage template, so it doesn't use the regular page.html.twig template?
12
votes
3answers
14k views

How do I show the current node title in page.html.twig OR in node.html.twig?

If I want to show the current node title in page.html.twig (by default it seems to only be available in node.html.twig) I have to create a preprocess function like so: function theme_preprocess_page(&...
12
votes
3answers
15k views

Running Drush returns an error

I am running Drush version 6.2.0 and the latest Drupal 8 beta on Dreamhosters. When I run drush cc all within the sites directory, I receive the following error immediately after executing the command:...
12
votes
2answers
8k views

How do I include a custom class file in a module?

In Drupal 7 module development, I could include a custom inc, api, or php class file using the file[]= directive in the module.info file or the drupal_load_included() function. With D8 using PSR, ...
12
votes
3answers
9k views

Will migrating content types be possible?

I have a Drupal 7 site with 40 content types. When Drupal 8 will be released than I would like to migrate these content types. Would this be possible, or would I have to create this content types ...
12
votes
1answer
8k views

Programmatically get a form in Drupal 8

The documentation states: The argument passed to the getForm() method is the name of the class that defines your form and is an implementation of \Drupal\Core\Form\FormBuilderInterface. How do ...
12
votes
1answer
6k 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 ...
12
votes
3answers
10k views

entityQuery with multiple conditions on taxonomy terms returns no result

In my use-case I have an entity which has two fields that reference to unique vocabularies. News: - tag (entity reference) - category (entity reference) If I query on one of those reference I get ...
12
votes
5answers
6k views

Which tables should be emptied when clearing database-stored cache manually?

Prior to D8 to clear cache manually one could truncate all tables beginning with cache_. In Drupal 8 there are still tables starting with cache_, but there's also a cachetags table. Is the advice in ...
12
votes
2answers
7k views

How to rebuild form after AJAX call

I'm attempting to allow the user to dynamically choose a number of fields based on a dropdown box using an ajax call, but I can't seem to get the ajax call to rebuild the form afterwards. <?php ...
11
votes
10answers
15k 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?
11
votes
5answers
10k views

How to get 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 ...
11
votes
5answers
14k 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 ...
11
votes
4answers
10k views

Are there any performance comparisons?

Are there any reliable performance comparisons between vanilla Drupal 8 versus Drupal 7? I have searched the web but only find the post "Drupal 7 vs Drupal 8 Performance Comparison", which is far ...
11
votes
6answers
11k 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 ...
11
votes
3answers
10k views

How to set target=“_blank” for links in CKEditor

I use CKEditor in Drupal 8. I want that every link will open in a new tab of browser. I want that the code look like this <a href="#" target="_blank">my link</a> But if I use the ...
11
votes
3answers
6k views

REST GET without caching

Using this tutorial Drupal Console's drupal gprr command, I've created a custom REST resource in Drupal 8. I'm able to use this resource to retrieve a simple JSON object that says hello to the current ...
11
votes
4answers
9k views

Adding autocomplete for text-field

I tried to implement an autocomplete in text-field for drupal 8 in my custom module all I wanted was to fetch and display the likely title I typed via autocomplete so declared a public function ...
11
votes
2answers
12k views

How to load paragraph entity on node object?

I'm using paragraphs in my content type. I've created a paragraph type and added content. Now I want to load the paragraphs in a foreach. But nothing's showing up. $paras is empty: $node = \Drupal\...
11
votes
2answers
11k views

How do I create menu links programmatically?

I need to add some links to existing menu (or to new) programmatically in Drupal 8.
11
votes
4answers
10k views

How can I get the page title?

drupal_get_title() has been removed from Drupal 8. How I can get the page title in Drupal 8?
11
votes
4answers
8k 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 "...
11
votes
1answer
14k views

How to render a template in Drupal 8

I am trying to render a template in Drupal 8. In Drupal 7, I would create a theme with hook_theme, make a templates directory in my module, drop the template file in and I could display it with theme()...
11
votes
3answers
15k views

Check content type of node in preprocess hook

I have a series of variables I want to make available on twig templates for specific content templates. In MYTHEME.theme I have: function MYTHEME_preprocess_node(&$variables) { if (isset($...
11
votes
2answers
8k views

How do I save uploaded file permanently in file_manged table?

How do I save a uploaded file with status equal to 1 in the file_managed table, in Drupal 8? Whenever I upload a file, it is stored in the file_managed table with status value 0. I have used File::...
11
votes
2answers
7k views

How to make custom fieldset collapsed by default in Drupal 8

In Drupal 7 there was option to have fieldset collapsible or not, and to restrict default state of this form element (collapsed, or uncollapsed). Example: $form['contact_data'] = array( '#...
11
votes
4answers
10k views

How can I setup multiple database connections in Drupal 8?

Can anyone help me to setup connection with multiple databases connection in Drupal 8? I have database on the same server and I want to access it along with default Drupal 8 database.
11
votes
2answers
13k views

How do I create table in custom module

In Drupal 7 we used to use hook_schema() in the .install file to create a table. I believe that, in Drupal 8, you can do that as well, but I was under the impression that you should create .yml files ...
11
votes
1answer
5k views

Drush dl not working with PHP 7 and ubuntu 16.04

When i try to do: drush dl drupal-8 i get the following error: PHP Fatal error: Uncaught Error: Call to undefined function Drush\UpdateService\simplexml_load_file() in /home/alexander/.config/...