Skip to main content

Questions tagged [8]

Version tags should be used for questions that apply to a version only, not to merely say what version a site is using.

Filter by
Sorted by
Tagged with
36 votes
5 answers
41k views

Import a single yml configuration file

Is it possible to import one single configuration file by specifying its path, or a group of Yaml files contained in a specific module?
David Riccitelli's user avatar
34 votes
2 answers
31k views

How can I check if a module is enabled?

In Drupal 7, you can use module_exists() to check whether a module is enabled (as well as whether it exists). For example, if (module_exists('devel')) { How can you check whether a module is ...
Patrick Kenny's user avatar
29 votes
3 answers
34k views

How do I pass parameters to the form builder?

I have the following routes in module_name.routing.yml. module_name.usergroup_delete: path: 'module_name/usergroup/delete/{arg1}' defaults: _form: '\Drupal\module_name\Form\DeleteUserGroup' ...
KTM's user avatar
  • 2,362
28 votes
8 answers
25k views

Taxonomy term name as contextual filter for view

In D7 I was able to filter a view according to a taxonomy term name taken from the URL. An example would be this URL http://www.gbyte.co/tags/drupal-planet/rss.xml "drupal-planet" would be converted ...
gbyte's user avatar
  • 787
26 votes
4 answers
44k views

Programmatically updating a node

I can create a node using the following code: $node = \Drupal::entityTypeManager()->getStorage('node')->create($array); But if I have the node ID, how can I edit a node?
BOES's user avatar
  • 1,023
26 votes
10 answers
21k 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 ...
Chris's user avatar
  • 991
24 votes
6 answers
40k 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\...
Kamal Oberoi's user avatar
24 votes
3 answers
20k views

Access user fields?

$account = \Drupal::currentUser() loads the user object into $account, but how do I access custom fields I've created on the user object (via the admin UI)? With dpm($account) I can't see any of my ...
dbj44's user avatar
  • 4,764
23 votes
4 answers
20k views

Non-Clickable Menu Items

In a Drupal 8 site, I want to add menu items with "no link", I was thinking that nolink is allowed but when I entered this, I got error Manually entered paths should start with /, ? or #. Is ...
Mohamed Osama Gbril's user avatar
23 votes
4 answers
1k 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, ...
Jon Freed's user avatar
  • 1,051
23 votes
5 answers
42k views

Verify a field is not empty

What is the best method to check if a field is empty in a node template. In node--example.html.twig we can use "content" variable. I can't use check like checking a block {% if content....
sainf's user avatar
  • 375
22 votes
6 answers
25k views

How to solve the "The following module is missing from the file system" error?

I am getting the following error in a Drupal 8 site. The following module is missing from the file system It looks as if a custom module was installed and deleted without uninstalling it. How ...
Kevin's user avatar
  • 27.9k
22 votes
6 answers
30k views

Site UUID in source storage does not match the target storage

When I run drush cim -y on my staging instance of my site I get the following error: Drupal\Core\Config\ConfigImporterException: There were errors validating the config synchronization. in Drupal\...
albertski's user avatar
  • 3,487
20 votes
1 answer
13k 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 ...
LittleCoding's user avatar
20 votes
1 answer
36k 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 ...
Axel Briche's user avatar
  • 1,981
20 votes
2 answers
32k views

Render a node field inside page.html.twig

I have an image field on my content type (field_hero_image). I don't want it to render in the node.html.twig file. However, I DO want to render it in the page.html.twig file. Specifically, I want to ...
kraftybasterd's user avatar
18 votes
5 answers
19k views

What is the correct way to set cache contexts on custom blocks?

I have run into an issue where a block that should be unique per page isn't for logged-out users. The issue is a custom block plugin I have on a views search page that contains custom filters (sort ...
oknate's user avatar
  • 14.4k
17 votes
10 answers
28k views

Add class to content field (link)

I want to add a class to the <a> tag of a field that consists of a link and text. (It's a field of type Link.) The name of the field is content.field_c_button_link. In the template file, I ...
maidi's user avatar
  • 271
17 votes
4 answers
14k 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 ...
David Mcsmith's user avatar
17 votes
1 answer
16k views

How do I translate a view page title?

Is there a way to translate a view page title in Drupal 8? How can I achieve it, if it is possible?
jeroen's user avatar
  • 864
17 votes
3 answers
50k 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\...
Pankaj Yogi's user avatar
16 votes
5 answers
38k views

How can I programmatically render a node's field respecting the view mode settings?

I want to render a node's field inside a block. It works like this: <?php if ($node) { if (isset($node->field_body_secondary) && $field = $node->field_body_secondary->value) { ...
Alex's user avatar
  • 2,513
15 votes
3 answers
15k 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::...
Jasodeep Chatterjee's user avatar
15 votes
1 answer
9k views

How to get an array of referenced entity ids from an entity reference field

I have a entity_reference field with BaseFieldDefinition::CARDINALITY_UNLIMITED cardinality. I want a list of referenced entity ids. I know that I can get all the referenced entities by calling $x->...
Rainer Feike's user avatar
  • 2,576
15 votes
1 answer
8k views

How to remove mymodule configurations on uninstall [duplicate]

I have created a custom module and created a yml file to create a menu system.menu.custom_menu.yml id: custom_menu label: 'Custom menu' description: 'Custom menu.' langcode: en locked: true ...
Ahmad's user avatar
  • 2,835
14 votes
4 answers
5k 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?
user avatar
14 votes
3 answers
26k views

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

I got this error while updating from Drupal 8.3.7 to Drupal 8.4.0. RuntimeException: Unable to determine class for field type 'webform' found in the 'field.storage.node.webform' configuration in ...
14 votes
2 answers
23k views

Get the public path directory

I want to save file programmatically in public path, and I want to know how can I get Public Directory path in Drupal 8. In Drupal 7, I would use the following code. drupal_realpath(...
Yuseferi's user avatar
  • 22.1k
14 votes
3 answers
56k views

How do I retrieve the query parameters from a path? [duplicate]

How do I retrieve the query parameters from a path. Here's my path: /search?keys=hello Here is what I've tried: $test1 = \Drupal::request()->request->get('name'); $test2 = \Drupal::request()-&...
dbj44's user avatar
  • 4,764
12 votes
1 answer
7k views

Add tab / local task to a node

I've created a module called hotel_reviews. I've created the route node/{node}/reviews using hotel_reviews.routing.yml. hotel_reviews.content: path: '/node/{node}/reviews' defaults: ...
Felix Eve's user avatar
  • 6,473
12 votes
1 answer
35k views

Pass variable to drupalSettings

I'm using Drupal 8. What I'm trying to do is: Access the active node From the node get the value of field_test and assign it to a variable Pass the variable to the drupalSettings function and ...
lane's user avatar
  • 473
12 votes
7 answers
3k views

How can I safely move a module to another folder?

I created a module through Drupal Console, unfortunately it wasn't placed in a folder of its own, rather straight into /modules/custom. Before I noticed where it had gone, I enabled the module. In ...
Clive's user avatar
  • 167k
12 votes
3 answers
28k views

Pass Variable to Custom Block template file

I want to create my custom block with custom content in Drupal 8,in start I create Block with just simple text on it, and work correctly, my Problem is how can I pass my custom variable to it? I saw ...
Yuseferi's user avatar
  • 22.1k
12 votes
1 answer
24k views

How do I render a template?

I am trying to render a template in Drupal 8. In Drupal 7, I would implement hook_theme(), make a templates directory in my module, drop the template file in that directory, and I could display it ...
user1015214's user avatar
  • 1,811
12 votes
2 answers
14k views

How do I use a jQuery version different from the default one used by core?

I need to use a different jQuery version. Currently, Drupal is using jQuery 3.2.1, but I need a previous version. In Drupal 7 you could easily change jQuery version with the jQuery Update module. How ...
dekisha's user avatar
  • 133
11 votes
1 answer
5k views

Dependency injection in a custom class

I have a custom module (my_module); Inside this module I have a custom class (MyClass), where I want to use a Drupal service (file_system). This is my code. src/MyClass.php namespace Drupal\...
CamelCode's user avatar
  • 761
11 votes
2 answers
10k views

Create content programmatically

In Drupal 8, how can I create content programmatically ? From the "Drupal 8" administration, I created a new type "House" (contain a description, an image, a reference field to users ...). How can I ...
spacecodeur's user avatar
  • 1,339
11 votes
1 answer
4k views

What is the difference between \Drupal::request()->getSession() and \Drupal::service('user.private_tempstore')?

As the title suggests, I'm a bit confused about those two methods of creating and accessing a session on Drupal 8. I'm not quite sure when to use the one over the other, could someone point me to the ...
user avatar
11 votes
4 answers
21k views

How to create modal windows (pop-ups)?

I am trying to use Drupal 8's core function to open a page in a modal window. Unfortunately it is very hard to find some official documentation about it, and most of the blogs covering this topic seem ...
user5950's user avatar
  • 2,048
11 votes
4 answers
15k views

How do I change a field type?

I have a content type with a field_maps whose type is Text (plain, long). I needed to change it to Text (plain). So I've done this SQL statement: ALTER TABLE node__field_maps MODIFY field_maps_value ...
Hefi's user avatar
  • 199
11 votes
2 answers
24k views

How do I set a cookie?

I need to save a cookie for anonymous users in Drupal 8 when users visit the site for the first time, which will be used to display a message. I can successfully save one using setcookie("FirstTimer",...
Malabya Tewari's user avatar
11 votes
1 answer
4k views

Can you change the list builder class used by an entity?

There's an entity created by another module and I'd like to change some of the fields used on a listing page. Currently that page is using the entity's list builder class. Is there a way I can define ...
Rob's user avatar
  • 213
10 votes
1 answer
4k views

How can I force a JavaScript library to load in the <head> of a page?

How do I force a JavaScript library to load in the < head > in Drupal 8? Here's my themename.libraries.yml file: zaccordion: version: 1.x js: js/jquery.zaccordion.js: { header: true } ...
Sage's user avatar
  • 2,463
10 votes
4 answers
5k views

Why doesn't "composer update drupal/drupal" work?

I installed a Drupal 8.2.0 site with composer create-project drupal/drupal testsite. Now I would like to upgrade it to Drupal 8.2.1. However, running composer update drupal/drupal doesn't work. It ...
Christoph Burschka's user avatar
9 votes
2 answers
19k views

How do I redirect to an external URL?

Drupal 7 has drupal_goto() that would allow redirecting to an external url. The change record indicated that ControllerBase::redirect is the method to be called in D8. https://www.drupal.org/node/...
Tanay Sai's user avatar
  • 404
9 votes
2 answers
8k views

How do I theme a taxonomy term page?

I am working on Drupal 8, trying to get a page template for each vocabulary. I have tried using hook_theme_suggestions_HOOK_alter() to achieve this, but I was not able to do it. I tried using Devel ...
Deva's user avatar
  • 111
9 votes
3 answers
12k views

How do I create a route with a query string?

I have tried a few things and I cannot manage to make this working. My route is the following. amu_hal.publicationsPerYear: path: '/publications/{year}' defaults: _controller:...
Matoeil's user avatar
  • 3,443
9 votes
3 answers
6k views

How to autoload classes from a 3rd party PHP library

I would like to use a 3rd party PHP library in my module and I wanted to ask what I need to do to autoload the classes? Example: Drupal\my_module\MyClass wants to instantiate ThirdPartyNamespace\...
Roger's user avatar
  • 91
9 votes
2 answers
4k views

How do I rename a field?

With Drupal 7 we had the Field Rename module, but this has not yet been ported to Drupal. So what SQL magic is needed to rename a field in Drupal 8?
MrPaulDriver's user avatar
  • 1,027
9 votes
1 answer
7k views

Restrict content to a user role in a template file

I want to restrict a single node to anonymous users in Drupal 8. I don't want to use any module for it as its useless for single restriction as per me. I know that I can do it with something like ...
Gabbax0r's user avatar
  • 288

1
3 4
5
6 7
42