35
votes
Accepted
How to add Clear button for views exposed filter?
Go to you view and Exposed form style settings. (You can find it right side Advanced settings of the view)
and check the 'Include reset button' option . You can also change the Reset button label. ...
32
votes
How do I get the full URL of the current page?
Here's how to get the absolute URL for the current page, using the Drupal API:
$current_url = url(current_path(), array('absolute' => TRUE));
If you need the extra (non-q) querystring parameters ...
29
votes
Drupal SA-CORE-2014-005 - How to tell if my server / sites were compromised?
If you're reading this article and hoping to check a Drupal 7 site more than a month after the exploit landed, your site quite likely already got hacked. Your best bet is to restore a backup from ...
29
votes
How to completely turn off caching?
You can replace the default cache backend to one which does not actually do anything.
Simply add this to your settings.php file:
if (!class_exists('DrupalFakeCache')) {
$conf['cache_backends'][] = '...
26
votes
Accepted
How Do I improve the performance of my Drupal7 Site?
These are notes from my experiences and might vary from what others experience. I predominantly use LAMP stack and have considered the same in my suggestions.
Thumb rules for caching that I generally ...
25
votes
hook_node_access not working
I used hook_node_access() and had the same issue: It wasn't firing and driving me nuts.
What worked for me was NOT to be logged in as an admin. I went in as a different role and all worked as ...
24
votes
Drupal SA-CORE-2014-005 - How to tell if my server / sites were compromised?
Some checks for common attacks are (this is not an exhaustive list, but are some of the attacks seen in the wild so far):
Check your user 1 account to make sure its user name, email address or ...
23
votes
How do you improve Drupal performance?
These are notes from my experiences and might vary from what others experience. I predominantly use LAMP stack and have considered the same in my suggestions.
Thumb rules for caching that I generally ...
23
votes
Views options in UI not working
I just had a similar issue (June 2014) with Views UI. The ajax interactions on the 'style settings' simply stopped working so click on 'customize field HTML' and nothing happened. Hence finding this ...
21
votes
Accepted
What is the difference between the Workbench and Workflow modules?
Workbench gives you an intuitive and friendly user interface to control content (nodes)transitions on a previously defined states on a role based access control means that every transition to the node ...
21
votes
Show node IDs along with titles in Entity reference Autocomplete list
Install the Views and Entity Reference modules, create a new View and Add a Entity Reference Display:
Then Add in the fields the content title and the nid, click in the nid and check Exclude from ...
21
votes
How to assign permissions to roles programmatically?
I'd like to add a code example that is closer to the original question on how to assign permissions to existing roles programmatically.
You can look up the roles with their name, retrieve the role ID ...
20
votes
reseting the hook_update_n status of a module
FYI, in Drupal 8, the system table has been removed, and this information is now stored in the key_value table.
UPDATE key_value SET value='i:8000;' WHERE collection = 'system.schema' AND name = '...
20
votes
Is it possible to force your module's update hook to run?
There are few ways of forcing module update.
Calling the update function directly.
$sandbox = [];
module_load_include('install', 'FOO');
FOO_update_7001($sandbox);
Resetting the schema version to ...
20
votes
Accepted
Send attachments with drupal_mail
There might be other ways, but I have found that mailsystem and mimemail modules have to be installed to send email with attachment. So install these two modules first.
Then implement hook_mail to ...
20
votes
Print the query which is built using db_select()
Another option is:
global $theme_key;
$query = db_select('block')
->condition('theme', $theme_key)
->condition('status', 1)
->fields('block');
print strtr((string) $query, $query->...
20
votes
Accepted
Sublimetext 2 does not recognize .module file as php file
When you have the .module file open, go to:
View -> Syntax -> Open all with current extension as
and select PHP. This will then default all .module files to use PHP syntax.
20
votes
How to set value of file field with entity_metadata_wrapper
Well I just found out a simpler and less ugly looking way to set image.
$image_file = A FILE OBJECT; //Lot of choices here : new stdClass(), file_load, etc
$wrapper->FIELD_NAME->file->set($...
20
votes
How do I silence PHP errors?
As suggested, in Administration » Configuration » Development (at /admin/config/development/logging) you can find the setting to disable displaying of error messages, but it won't disable error/...
19
votes
How do I turn on theme_debug?
Drush commands to control theme debugging:
Drupal 7
To turn it on: drush variable-set theme_debug 1
To turn it off: drush variable-set theme_debug 0
Drupal 8 & Drupal 9
To turn it on: drush ...
19
votes
How can I run PHP code without writing a module?
Yes, there is, but given your description I wonder if it will help you:
Install module Devel
Go to http://yoursite/devel/php
Enter your code and execute it.
19
votes
Accepted
Is is possible to call a function inside a .inc file of a module via drush eval?
You could add module_load_include() to your eval code like you would anywhere else.
Like this:
drush eval "module_load_include('inc', 'my_module', 'INCLUDE_FILE_NAME_WITHOUT_EXTENSION'); ...
19
votes
Accepted
Field Type: Text vs. Long text
The differences are laid out in text.module.
text fields are stored as varchar with a maxlength of 255 characters, and their default widget is a simple text input.
long text fields are stored as ...
19
votes
Accepted
Check if the page is the front page in a template
You should not declare a function in a Drupal template. Instead, you should just refer to that function:
<?php
if (drupal_is_front_page()) {
?><h1>Test</h1><?php
}
?>
18
votes
Revert a Feature Component programmatically
You can revert a single features module with features_revert_module().
features_revert_module('my_feature');
18
votes
Accepted
Why is session.cookie_lifetime set to 23 days?
ini_set('session.gc_maxlifetime', 200000);
This value is for the server.
It is a settings for Session Garbage Collection.
If the users last visit happened before 200000s then this session is ...
17
votes
Accepted
Field Collection vs. Paragraphs
In many respects the Paragraphs module appears to be a fork of Field Collection. Functionally, the difference between the modules lies in how their respective field widgets operate. The Field ...
17
votes
Accepted
Get display name from hook_preprocess_views_view
You can get the display ID through the current_display property of the View object, e.g.
$view = $vars['view'];
if ($view->name == 'foo' && $view->current_display == 'bar') {
// ...
}
17
votes
Hide errors from users but show to admin?
Preface: This answer was first posted as an answer to "How do I suppress a warning or error message for site users?".
Disable Messages module
You could use the Disable Messages module for this. Here ...
17
votes
Accepted
Render custom block by block name
D7:
<?php
$block = module_invoke('module_name', 'block_view', 'block_delta');
print $block['content'];
?>
'module_name' = The machine name of the module (i.e. the module's folder name). ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
7 × 26483views × 4471
theming × 2746
entities × 2668
nodes × 2383
users × 2156
forms × 2092
taxonomy-terms × 1117
database × 1022
javascript × 972
rules × 927
commerce × 922
hooks × 880
media × 861
ajax × 831
blocks × 808
files × 797
routes × 711
webforms × 617
i18n-l10n × 554
search × 543
emails × 465
datetime × 403
navigation × 402
panels × 373