Users
Change any user’s password
Drush method:
drush @site.env upwd --password="<password>" "<user>"
SQL method:
UPDATE users SET pass = "$S$DZDqpoM1nUF8BAd/Bo6cHehxXA/uD.PLJql/PhIWmyhMvuJLaTEc" WHERE uid = 1;
This sets the user’s password to password
… well you aren’t really concerned about security if you’re doing this now are you?
Views
Get image url from an image field in views (Drupal 8)
Drupal unfortunately doesn’t provide the path to an image as a separate value. Have no fear, we can get the value out of the image using Twig. Inside your field click “Rewrite results” and paste:
Performance
Stop Drupal caching everything
When developing on your local! Place in your settings.php:
Increase your local machine’s memory
If you experience memory issues on your local place in your settings.php:
Optionally in your my.cnf: (MySQL)
innodb_buffer_pool_size = 1GB
query_cache_limit = 1M
query_cache_size = 16M
Syncing
Sync a database
Source on the left, destination on the right.
drush @site.dev sql-dump | drush @site.loc sql-cli
Rsync files using drush aliases
Source on the left, destination on the right.
drush -y -r . rsync --size-only -v --stats --progress --exclude=.DS_Store @site.loc:%files/ @site.dev:%files
Drush
Change Drush version on your local
composer global require drush/drush:8.*
(Drush 8 works with Drupal 7)
Run registry rebuild even if the server doesn’t support it
drush @site.env php-eval "registry_rebuild();" --strict=0
Tokens
There are three styles of placeholders:
!variable
, to insert text with no filter:
$message = t("If you don't want to receive such e-mails, you can change your settings a!url.", array('!url' => l(t('My account'), "user/$account->uid")));
@variable
. Run text through check_plain to escape HTML characters:
$title = t("@name's blog", array('@name' => $account->name));
%variable
. Run text through check_plain and theme_placeholder() to emphasize text:
$message = t('%name-from sent %name-to an e-mail.', array('%name-from' => $user->name, '%name-to' => $account->name));
Entities
Active class for menu item <li> (Drupal 8)
Give li
element of a list an .active
class, not just its child a
:
Load a field’s value (Drupal 8)
Multiple values will return as an array.
Load a user’s fields (Drupal 7)
Fields on the Drupal $user
object aren’t loaded by default. Use the entity wrapper to access fields easily:
List an entity’s properties (Drupal 7)
Load an entityform type (Drupal 7)
Entityforms have no instances so loading them is a little different. You are working on the entityform type directly.
Debugging
Devel Debug Log is much better than a one time dpm()
or kint()
as the debugged variables hang around on a separate admin listing, and it works well when debugging AJAX elements.
Patching
For a patch made relative to the file:
patch -p1 < <filename.patch>