All Questions

Filter by
Sorted by
Tagged with
46
votes
11answers
68k views

Check if a user has a role

How can I check if a user has a certain role? I found this but it is for Drupal 6.
45
votes
5answers
946 views

For someone who is not a programmer or is starting how can he/she contribute to Drupal.org?

I have been talking to people who are starting in the university about Drupal. But they are beginners in programming. so they told me how they can contribute to Drupal or being more involved. What ...
44
votes
11answers
36k views

Views - Add a wrapper DIV around a Group

In Drupal 7, I have created a View that lists several fields. The fields are grouped by another field (the term ID of the field). The mark up looks like this: <h3>[Term 1]</h3> <div ...
43
votes
6answers
70k views

How to get instance of referenced entity?

I have a node object with image field named field_image. When I do $node ->get('field_image') ->first() ->getValue() I get array with some properties instead of entity object. The ...
43
votes
14answers
36k 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 ...
43
votes
7answers
43k views

How do I programmatically log in a user?

I am looking for the API that will let me login a user by passing it the username and password. Does anyone have experience with this? To clarify, I am trying to make an AJAX login box that appears as ...
42
votes
9answers
67k views

How do I enable developer/debug mode?

Installing drupal 8 core (using standard profile). whenever I get exception/error, I get blank page with "The website has encountered an error. Please try again later." (as below image) text and no ...
42
votes
3answers
49k views

how to send variable from .php file to .js file?

I hope someone is able to help me. The problem is the following one: 1)I have module in which a assign the variable in order to send to the template file php.tpl <?php ... $testvar="Hello from ...
41
votes
12answers
13k views

How can I block an abusive person who endlessly tries to register more accounts?

I have a free site with open registration; anyone can register and I am not able to change that. However, accounts must be approved by an administrator after completing a profile, so I have access to ...
41
votes
11answers
28k views

Which tables are safe to clear?

I have inherited a client site that has an extremely large database for no reason. There is a moderate amount of content and very little enabled modules. However, the database is too large for moving ...
41
votes
1answer
32k views

How to check if field exists in an entity?

In entity node, I want to check if 'abc' field exists or not. If exists, I will get its value by $value->get('abc'). But the content type where this field doesn't exists, gives error: The website ...
41
votes
1answer
1k views

I need to bring a site to version control, and set up the continuous Integration environment

I am an entrepreneur with a Drupal 6x project that started small enough to not need version control (per developers), but now I am convinced there is no way without it. There's extensive documentation ...
40
votes
7answers
58k views

How can I programmatically create a node?

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 ...
40
votes
9answers
45k views

How do I change a theme based on the URL?

I have a Drupal instance running on example.org. Which has a theme X installed and activated. Now for a limited period an event is supposed to be held on the site for which a special section has been "...
40
votes
7answers
14k views

Drupal SA-CORE-2014-005 - How to tell if my server / sites were compromised?

I just updated all my sites using the patch method of resolving the Drupal SA-CORE-2014-005 exploit. I just read reports that just yesterday there is someone from a Russian IP infiltrating drupal ...
40
votes
1answer
6k views

Why is hook_form_alter() so messy?

Here's an example I just ran into. I'm trying to put some HTML in the label of my field. $form['field_feedback']['und']['#title'] <- has the title $form['field_feedback']['und'][0]['#title'] <- ...
40
votes
3answers
54k views

How do I customize the search result page?

I have customized the teaser view of my content types and the page view. Now I need to use the teaser view for the search results page. By default, Drupal displays a full text jumbled mess for each ...
40
votes
4answers
2k views

What is the suggested workflow for migrating (CMI) configuration from dev -> stage -> production?

We had a drupalcamp a few months back and someone asked about managing deployments with the new config (CMI) system. One possible ideal workflow would involve keeping the config in version control and ...
40
votes
3answers
7k views

How do I merge changes from a development copy of the site to the live site without losing new content?

What is the best procedure for merging work done on a development copy of a site to the live production copy? Often times there has been a lot of new content added to the site since development ...
39
votes
9answers
75k 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 ...
39
votes
9answers
31k views

Count of nodes by type [closed]

I am looking for a snippet that lets me display the total count for a specific node type, e.g. "Pages = 167" or "Products = 10630." What code should I use to achieve this?
39
votes
3answers
60k views

Adding CSS and JS to form with attachments

I need to add some external and local CSS and JavaScript files to a form, but I can't seem to find the right way to do this. Do I simply add the paths and URLs for the JS and CSS files? I assume $...
39
votes
11answers
29k views

How to display a field before node title?

I'm looking to render a certain field before the node's title when displaying a teaser in D7. Effectively I want to go from this to this. I have looked into updating the node.tpl.php but I notice ...
39
votes
7answers
17k views

How do I update the configuration of a module?

I'm building a custom module in Drupal 8. It includes some YAML config files. As I develop I need to change and add to the config, e.g. to add another field onto my custom entity. At present the only ...
39
votes
2answers
30k views

How to get a node by its url alias?

I know I can load a node by its title with the node_load() function. Is it possible to load a node by its URL alias?
39
votes
1answer
19k views

Managed file: the file used in the field may not be referenced

I am having some issues with the managed_file type. Whenever I try to edit and save a form that has a managed_file element in it an error occurs: The file used in the Picture field may not be ...
39
votes
4answers
15k views

What is the difference between the Workbench and Workflow modules?

I use the Revisioning module to manage revisions of nodes on my Drupal 7 site. I had been updating the site by myself, so Revisioning was sufficient; now, however, I will be adding some content ...
38
votes
6answers
29k views

Programmatically create a term?

I'm attempting to add a lot of terms (~200) to a vocabulary, but I can't find any import modules that are updated for Drupal 8, and it seems the functions for doing this in Drupal 7 don't exist in ...
38
votes
5answers
26k views

Using IN clause in db_query

I can't figure out how to add an IN clause in my query, using placeholders. I'd want it to be something like: $nids = array(1, 2, 3); $result = db_query('SELECT * FROM {node} WHERE nid IN :nids', ...
38
votes
7answers
9k views

Is there a good way to inspect objects whose type is derived from the EntityDrupalWrapper class?

I'm sure this question applies to other complex object types, but EntityDrupalWrapper is the one I'm currently working with. This is the type of object returned by entity_metadata_wrapper() (and ...
37
votes
8answers
56k views

Get path alias from NID (or node object)

I have a node object, and I am trying to use it to get a given path in Drupal 8. There was drupal_lookup_path() in Drupal 7 but I'm not seeing any equivalent or documentation for Drupal 8. What's ...
37
votes
5answers
28k views

Is there a Drupal API function to get the list of nodes by type?

Is there a Drupal API function like node_load() that will return a list of nodes by a given type? I've tried $nodes = node_load(array("type" => 'student_vote')), but it only returns one node. I ...
37
votes
16answers
16k views

Performance Problem: Delay on first request

I put together a D7 site with a Minelli subtheme. Along the way I experimented a lot with different themes, different modules. Somewhere along the way I developed an odd performance issue, and now I ...
37
votes
4answers
22k views

What is the template suggestion for node 'teaser' view mode?

node--[type|nodeid].tpl.php targets to node's default view mode. However I want to override the template for teaser view mode. What is the template suggestion (.tpl.php file) for 'teaser' view mode?
37
votes
4answers
26k views

What's the proper way to use EntityFieldQuery?

In Drupal 7, the API documentation for node_load_multiple() specifies that using the $conditions parameter has been deprecated in favor of using EntityFieldQuery. In which way should EntityFieldQuery ...
36
votes
16answers
39k views

How to delete all nodes of a given content type?

I have several thousand nodes of a particular content type. Using the web interface (example.com/admin/content), I can only delete about 50 at a time. How can I quickly delete them?
36
votes
7answers
67k 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 ...
36
votes
6answers
13k views

How do I avoid checking for updates for a specific module?

In a current project I have had to patch the life out of a few modules (node hierarchy, workbench access and a few more). These modules are now absolutely perfect for the project's needs and are very ...
36
votes
6answers
95k 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'...
36
votes
6answers
51k views

How to check Drush version?

How can I identify what version of Drush is installed on a given system?
36
votes
2answers
25k views

Difference between Minimum cache lifetime and Expiration of cached pages

On Drupal Performance Page, under the fieldset Cache you have two options. One is Minimum Cache Lifetime and the other is Expiration of cached pages. What is the difference between these two.
36
votes
9answers
5k views

What's a good balance between reusing fields versus creating new ones in the context of fields scalability?

I've read the following phrase on a website: Instead of adding new fields to a content type, adding existing fields is a better option to reduce the system’s complexity and to improve scalability. ...
36
votes
4answers
7k views

How do I debug permissions?

How do I debug permissions in Drupal 7? I use core reporting, error logs, devel module error logs, backtrace and node access permission block but sometimes it is not enough. What else should I check ...
36
votes
9answers
14k views

How to create a union of two views?

I'm trying to get a union of a user's nodes and comments sorted by "post date". This post links to sandbox projects for D6 but there is nothing for 7. This post has an example of using ...
35
votes
12answers
91k views

“The website encountered an unexpected error. Please try again later.”

I get this error with Drupal 7. The website encountered an unexpected error. Please try again later. How can I get more information about this error? Is there any report or log to understand what ...
35
votes
12answers
37k views

Get all users with specific roles using EntityFieldQuery

I thought this was an easy task, yet there does not seem to be a Drupal-method for this. I came as far as knowing I have to use EntityFieldQuery for this - because the API said conditions for ...
35
votes
2answers
25k views

Drush command to show aliases?

Is there a drush command to show existing aliases? Some Googling didn't turn up anything.
34
votes
5answers
75k views

How to get taxonomy term name from tid?

A lot of our stuff has uris formatted like site/taxonomy/XX, where XX is an integer. I found a lot of questions like "how to get the TID from the name?", but I'd like to get the name from the TID. I'...
34
votes
6answers
34k views

How to load a node based on its title?

I only know the title of a node, and I want to load the node using node_load(). How do I do that?
34
votes
6answers
69k views

How do I translate strings in Twig templates?

I am working on a (my first) Drupal 8 project witch is a multilingual site. Drupal 8 really delivers in terms of native support for content translation. However, I have a few strings set directly in ...

15 30 50 per page