Hot answers tagged

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. ...
user avatar
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 ...
user avatar
  • 21.7k
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 ...
user avatar
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'][] = '...
user avatar
  • 712
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 ...
user avatar
  • 6,503
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 ...
user avatar
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 ...
user avatar
  • 14.5k
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 ...
user avatar
  • 6,503
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 ...
user avatar
  • 231
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 ...
user avatar
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 ...
user avatar
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 ...
user avatar
  • 2,475
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 = '...
user avatar
  • 301
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 ...
user avatar
  • 13.6k
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 ...
user avatar
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->...
user avatar
  • 2,214
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.
user avatar
  • 2,276
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($...
user avatar
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/...
user avatar
  • 13.6k
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 ...
user avatar
  • 191
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.
user avatar
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'); ...
user avatar
  • 14.5k
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 ...
user avatar
  • 608
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 } ?>
user avatar
18 votes

Revert a Feature Component programmatically

You can revert a single features module with features_revert_module(). features_revert_module('my_feature');
user avatar
  • 5,134
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 ...
user avatar
  • 6,503
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 ...
user avatar
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') { // ... }
user avatar
  • 164k
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 ...
user avatar
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). ...
user avatar

Only top scored, non community-wiki answers of a minimum length are eligible