All Questions
87,467
questions
153
votes
10
answers
212k
views
What are the recommended directory permissions?
I'm gearing up to deploy a Drupal 7 site and I can't find any documentation. What are the recommended security-conscious permissions for files and directories?
I am specifically interested to the ...
125
votes
14
answers
19k
views
What is the basic concept behind hooks?
I am intermediate in PHP. To polish my skills I start learning Drupal 7. While learning Drupal architecture concepts, the terms hooks and bootstrapping puzzled me a lot. I read the "Pro Drupal ...
111
votes
2
answers
68k
views
Contextual filters taxonomy name
I'm adding a contextual filter to a view for a custom content type that has a taxonomy field. The contextual filter allows me to filter by the taxonomy tag id but not by the taxonomy tag name. Meaning ...
108
votes
1
answer
44k
views
How should I implement hook_menu()?
What are the fundamentals of implementing hook_menu()?
I would like to see the basics covered in a single question, to avoid having to answer the same similar but different questions over and over.
99
votes
10
answers
93k
views
How can I change a user's password from the command line using Drush?
How can I change a user's password from the command line using Drush?
98
votes
7
answers
15k
views
What are the downsides of using PHP Filter code in blocks, nodes, views-args, etc?
I have seen many times people saying not to use custom PHP/PHP filter (from the Drupal UI) in blocks, nodes, views-args, rules, etc. I have searched around a bit and haven't found much, it seems like ...
93
votes
9
answers
8k
views
Do non-enabled modules affect performance?
Does having Drupal modules present, but not enabled have any effect on the performance of a Drupal site?
To put it another way, would removing disabled modules on a Drupal site have a positive affect ...
92
votes
7
answers
46k
views
How to take a site offline using Drush?
How can I take a site offline using Drush?
88
votes
11
answers
190k
views
How do I get the current path alias or path?
How can I get the current alias and/or path in Drupal 8?
In Drupal 7 I did this with drupal_get_path_alias(). What is the equivalent code I should use in Drupal 8?
88
votes
7
answers
18k
views
When is it appropriate to create an entity instead of a new content type?
What is the benefit to creating new entity types over just building a new content type?
It seems a bit overkill to do all of the custom coding that is required to create a new entity when you have ...
81
votes
12
answers
55k
views
Any way to add CSS for a single page/node?
I'm cleaning up my big crazy style sheets (possibly pertinent to a future question) and I'm wondering the best way to add custom CSS to a specific node or page.
In particular, my work site's home page ...
80
votes
11
answers
228k
views
How do I access a field value for an entity (e.g. node) object?
node_load((int) $nid) loads a fully-populated node entity. $node->title->value gets the title, but how do I access field values in Drupal 8?
80
votes
4
answers
84k
views
What does "The provided host name is not valid for this server" mean?
I am running a Drupal 8 website, and when I browse to any page, I get a plain white page with just the following error message on it.
The provided host name is not valid for this server.
What does ...
80
votes
7
answers
9k
views
Suggestions for settings.php - Local dev, Development server, Live server
Basically, one of the greatest questions of all time: What are some ways you're using settings.php in your development/staging workflow?
Right now, I have my settings.php file set up like the ...
78
votes
4
answers
74k
views
How do I load a field collection from a node?
I have a node that has a few field collections on it.
When I look at node_load() output, I see:
[field_rich_text_group] => Array
(
[und] => Array
(
...
75
votes
8
answers
11k
views
How can I obscure what I am using to run my site?
Is there anything I can do to prevent somebody from knowing my site is using Drupal by looking at the source code of the front page? I am referring to people who scan sites using software that detects ...
71
votes
3
answers
12k
views
Given that db_select is much slower than db_query, why would I want to use it?
For the background on this, please see http://drupal.org/node/1067802.
Given all that, what situations exists where I might want to use db_select(), or should I be relying solely on db_query?
70
votes
9
answers
61k
views
How can I import the configuration on a different site?
I have this error when I try to import the config of an another site:
The staged configuration cannot be imported, because it originates
from a different site than this site. You can only ...
69
votes
6
answers
155k
views
How do I get the current node ID?
In Drupal 7, if I wanted to get the node id of the currently displayed node (e.g. node/145) I could get it with the arg() function. In this case, arg(1) would return 145.
How can I achieve the same ...
64
votes
7
answers
72k
views
Print the query which is built using db_select()
I want to print the query which is built using db_select() in a programmatical way. Is there any API function provided by Drupal Abstraction Layer?
It is similar to query output in Views, but I want ...
62
votes
8
answers
81k
views
Rebuild images from image style
I have an image style in Drupal 7. I attached several images to a nodes and display the images based on this style. I then changed the effects on this image style but the existing images are not being ...
60
votes
14
answers
129k
views
How to get the valid URL of a Link field from within a Twig template?
I have a Link field named field_my_link (machine name).
Within a Twig template I can get the link's URL value with this:
{{ node.field_my_link.uri }}
If inside the Link's URL there is an external ...
60
votes
7
answers
101k
views
How to get the base URL of a site
My site is on http://drupal8.local/. How do I get the drupal8.local part of that URL?
Url::fromRoute('<'current'>') or base_path() returns the path parth of the URL; For example, for http://...
59
votes
2
answers
46k
views
Better understanding of Drupal behaviors
I read about Drupal behaviors today, and I tried writing the following code.
(function ($) {
Drupal.behaviors.mymodule = {
attach: function (context, settings) {
$('#mymodule_id', ...
58
votes
6
answers
88k
views
How do I create custom regions in a theme?
I want to add a new area which will be site wide. Describe the process of getting this new region into my theme, if possible generalize it for adding any new, custom region.
57
votes
3
answers
34k
views
How to upgrade only core with drush?
There's a huge security leak in <7.32. So I want to upgrade all my Drupal sites asap without too much worrying about breaking stuff.
But...
$ drush dl drupal-7.32
It's forbidden to download ...
57
votes
2
answers
21k
views
What are Ctools plugin (content type, access, etc), and how does one create them?
What are Ctools plugins, and how does one create them?
57
votes
9
answers
53k
views
How to programmatically create Fields?
How can I approach implementing the following in Drupal 7?
What I need to do is create a module which defines a new fieldable entity, called 'Company'. I have a list of, let's say, 20 fields that ...
55
votes
17
answers
126k
views
Getting the image URL from a field_image on a node
So I have this Node:
object(Drupal\node\Entity\Node)[1862]
protected 'values' =>
array (size=17)
'vid' =>
array (size=1)
'x-default' => string '7' (length=1)
...
55
votes
3
answers
20k
views
Is it possible to replace more than one form element (wrappers) triggered by only one #ajax trigger element?
function ajax_example_simplest($form, &$form_state) {
//This is my ajax trigger element
$form['element_trigger'] = array(
'#type' => 'select',
'#options' => array(
'one' =&...
55
votes
1
answer
33k
views
What are all the directories for?
Drupal 8 re-arranged all the directories and locations of modules/themes etc. Where do things go now?
54
votes
10
answers
72k
views
Manually disable a module
In Drupal 7, I could manually edit the {system} table in the database to disable a stubbon module. In my Drupal 8 site, this table is gone.
How can I manually disable a module in Drupal 8?
54
votes
19
answers
152k
views
Configuring the temporary directory
I have recently moved a site from a localhost to a VPS. I have managed to make the public and private files writable; however, I am not sure where to find the temporary folder and how to change the ...
54
votes
10
answers
14k
views
How do you improve Drupal performance?
Drupal is fast at develop, but the performance is so poor.
It is hard to reach 50 request per second.
And there are so many SQL queries in a simple web page.
If you test the request time of a form ...
53
votes
6
answers
100k
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 ...
53
votes
8
answers
51k
views
"OR" condition in db_select()
I am studying the new database layer, and I am glad it is changed to an OOP layer. I need to implement a query with db_select(). I found I can add a WHERE statement with $query->condition(), but by ...
53
votes
6
answers
37k
views
How can I automatically upload images on file selection rather than pressing the upload button?
I have a custom content type to allow users to upload images. I'm trying to keep the interface as simple as possible.
The content type contains a single image field. This works, but some users don'...
52
votes
9
answers
63k
views
Where is the content of a node's body stored?
In the node table, you'll find everything except the actual body. Where can I find this body text? I'm assuming it's being stored as a blob somewhere.
52
votes
8
answers
4k
views
Real world experience in scaling and tuning performance
The website I'm working is allegedly going to have a massive hit rate soon after launch. The client is talking about the possibility of around 2500 hits per second over a day or so.
Ignoring the ...
52
votes
3
answers
11k
views
What's best practice when working with the language[und]?
I'm starting to use this form to access data in my module. (See comment #1.)
$node->field_test[$node->language][0]['value']
I thought that looked like a pretty good solution, but further down ...
51
votes
10
answers
92k
views
How do I enable developer/debugging mode?
I'm installing Drupal 8 core (using the standard profile). Whenever I get an exception/error, I get a blank page with "The website has encountered an error. Please try again later." (As ...
51
votes
7
answers
64k
views
How to a use a template file to theme a form?
While nodes, comments, blocks and many other things in Drupal are themed using theme template files (like node.tpl.php), forms are a different story. There are no theme template files for forms. How ...
51
votes
6
answers
43k
views
Programmatically create a user and assign a role
I'm programmatically creating a user with the following code.
$newUser = array(
'name' => $mail,
'pass' => 'password', // note: do not md5 the password
'mail' => $mail,
'status' =&...
50
votes
7
answers
45k
views
How to change the length of field settings?
I have set once to a website a lenght limit to a field. And now the client wants to put more characters to that field.
I cannot change the maximum size from Drupal because I get the following error ...
50
votes
5
answers
98k
views
Nginx vs Apache - Are there any actual usage comparisons and statistcs out there?
I have a new server to play with, and I am staring at a blank canvas. I can put anything I want on it. While I am comfortable with Apache, I keep hearing how nginx can handle so much more traffic than ...
50
votes
12
answers
22k
views
How do I hide nodes that shouldn't be directly accessed from users and search engines?
I've found that there are times I have a node that simply contains content that will be displayed somewhere else, but shouldn't be viewed directly. That is, no one should ever go to node/1234, but the ...
50
votes
5
answers
73k
views
How do I get the node ID from the URL?
So far, I came across these 3 functions in Drupal 7, but I am not really sure what the difference between them is, and which is more appropriated to get the node ID in a block preprocess function.
...
50
votes
4
answers
47k
views
How to programmatically send an email?
I'd like to use Drupal's email system to programmatically send an email from my custom module. Is that possible?
49
votes
1
answer
44k
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 ...
49
votes
3
answers
30k
views
How to provide template for particular view mode?
I want to theme the search result view mode with a template.
I had it in my head that naming a template file node--article--search-result.tpl.php would do the trick, but I'm obviously wrong about ...