drupal

Generate UUID in Drupal 8

Drupal 8 is full of UUIDs. Sometimes it's useful to generate one for use ourselves.

Drupal Console: Install a new site

drupal site:install \
  --learning \
  --uri="http://testing.site" \
  --langcode="en"  \
  --db-type="mysql"  \
  --db-host="localhost"  \
  --db-name="drupal8_site"  \
  --db-user="somesiteuser"  \
  --db-pass="really secure password"  \
  --db-prefix="prefix_" \
  --db-port="3306"  \
  --site-name="Drupal 8"  \
  --site-mail="admin@example.com"  \
  --account-name="anything but admin"  \
  --account-mail="admin@example.com"  \
  --account-pass="another really secure password" \
  minimal # the profile name

The --uri= option is needed when dealing with multi-site.

Drupal Console: Create new multi-site with URL

drupal multisite:new testing1 testing.site

Details on params in more ..

Adding a cache table for a module

Drupal Core provides a central caching system. If your module has needs for caching that fall outside the default cache tables, it can have its own cache table (or bin) that uses the same interfaces.

Adding a custom cache table is as simple as adding it to the site's install schema.

Drupal 7

Keep a record of important events on your Drupal site

Quite often a site needs to log important events from custom code. Use the watchdog. I'm getting slightly less descriptive in my introductions.

Set a Drupal module's weight on install using db_update

The weight of a module determines the ordering in which it will be called during callback hooks. eg Given 2 modules which implement hook_menu_alter(), the one with weight 0 will run before the one with weight 10.

If you know the weight that a module needs to be, and you can be very sure that no other module might get in there and change it, it can just be set statically.

Views template override function for a field to pad top of an image to center it

This method is dependent on running the images through an image style to ensure that the width and height tags are added to the img tag, and that the height of the area to be centered is known. This is pretty easy for fixed sized areas fitting images, like in a list or gallery.

Instead of making a views-view-field--featured--field-image-cache-fid.tpl.php file, this function produced the output instead. In this example, I know that the height of the div is of a fixed 155px in height.

Views theme template functions instead of template files

Normally when overriding a views template it's a case of create a file like views-view-unformatted--featured.tpl.php. But this is actually a performance hit when it could be picked up as a theme template function instead.

The above function would be

Manually adding a node to Drupal 7

Sometimes, when the brown stuff has hit the proverbial, there is a need to manually insert a single node back into the database with its original node id.

For Drupal 7 it is quite easy no add one back in and end up with an empty node which can then be edited to add the information via the normal interface, but if you have the comment module installed at all, it will throw errors that you haven't got $comment_count defined even if that content type never had comments attached to it ever!

Drupal 6 themed images with ImageCache and Thickbox or Lightbox

This is mostly because I can't remember how to do this all the time.

The ImageCache preset is 'vpthumb' in this case.

Pages

Subscribe to RSS - drupal