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.

Filter by
Sorted by
Tagged with
14
votes
3answers
8k 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 ...
14
votes
2answers
7k 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....
14
votes
3answers
11k 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 ...
14
votes
4answers
3k views

Delete a node after X weeks it was created

How can I delete a node after, for example, 2 weeks it has been created?
14
votes
1answer
4k views

How to make a theme hook suggestion for blocks according to region?

Since Drupal 8 it is not possible with template naming conventions to load a specific block template according to the region it is placed in ("Per-region block markup and per-region block templating ...
14
votes
1answer
3k views

How do I use dependency injection on \Drupal::moduleHandler() to a Controller?

I am using the following line in a controller class. \Drupal::moduleHandler()->alter('mymodule_myfunction', $plugin_items); Pareview.sh is giving me this error message. \Drupal calls ...
14
votes
2answers
7k views

What is the purpose of drush entity-updates?

After updating Drupal 8 modules, I have been warned on the Drupal 8 status page that: Entity/field definitions: The following changes were detected in the entity type and field definitions. ...
14
votes
1answer
3k 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 ...
14
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 ...
13
votes
5answers
15k 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 ...
13
votes
5answers
11k 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 ...
13
votes
7answers
23k 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....
13
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::...
13
votes
3answers
34k 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 ...
13
votes
3answers
11k 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
18k 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 ...
13
votes
5answers
8k views

Unable to install … already exist in active configuration

On Drupal 8.1 I keep running in those kind of messages when I try to activate a custom module or a custom feature that makes some modification to the basic page. (add fields). It is really annoying.....
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
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
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
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 ...
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
6answers
9k 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
4answers
16k 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
4answers
4k views

How to delete a content type, programmatically?

I programmatically created a content type during a module installation (using field storage configuration). I want to delete that content type while uninstalling the module. Is there any way to do ...
12
votes
3answers
12k views

How do I create menu links programmatically?

I need to add some links to existing menu (or to new) programmatically in Drupal 8.
12
votes
3answers
14k 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\...
12
votes
3answers
6k 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 ...
12
votes
3answers
22k views

Perform a query with an entity field condition with multiple values

I have a content type that has a entity reference field that allows users to add multiple taxonomy terms in that field. I'm attempting to perform queries that grab nodes that have a specific set of ...
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
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
3answers
7k views

Getting the node object in hook_form_FORM_ID_alter

Follow up to this question but I don't have enough reputation to ask clarification in a comment. I am porting a contributed module to Drupal 8. The sugested code on the above mentioned CR and post ...
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
2answers
3k views

Sub folders and how to namespace classes

In Drupal 7 I can have a module inside another module. Is this still the case in Drupal 8 and how would I namespace classes inside the sub module? Another thing I can do in Drupal 7 is to create sub ...
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
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
7answers
19k views

Alter an existing form

We just starting out with Drupal 8 and very quickly we ran into our first problem. How should I alter an existing form in Drupal 8? We need to alter the save method for the node form to do a ...
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
5answers
39k 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 ...
11
votes
10answers
16k 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
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
3answers
16k views

How do I remove page title/header?

In Drupal 8, is there an easy way to configure a page so that its page header/title is not displayed on the page? I have created a Basic Page, with /home as path alias, and Home as title. I set it as ...
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
11k 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
5answers
13k 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. "...
11
votes
3answers
7k 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
10k 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 ...