drupal

Using Node.js modules in your Drupal Themes

As my frontend development workflow gets more and more dependent on Grunt and node.js there are are issues coming up when Drupal tries to parse .info files from theme directories. I've had a hard time working around this by putting Gruntfile.js and package.json in a hidden subdirectory of my theme, but this resulted in a lot of broken Grunt tasks (and it's basically yet another hack because it simply relies on the fact that Drupal doesn't scan directories starting with a dot).

So I went the easy yet dirty way and hacked the Drupal core. Yes, yes, it's bad, but I didn't see another way without wasting yet even more hours just to be able to employ a modern frontend workflow.

All I had to do was changing the nomask value in line 2109 of includes/file.inc to 'nomask' => '/(\.\.?|CVS|node_modules)$/',

This makes sure Drupal won't parse the .info files from any node_modules folder, et voilà, all Grunt tasks and Drupal work peacefully side by side!

Drupal: Keep EXIF orientation and allow manual cropping of images

Wow, this is more troublesome than expected.

Goal: Let users upload images straight from a camera and manually select an area of the image that should be cropped.

Issue: nearly all modern cameras use EXIF information to tell an images orientation. Drupal image actions ignore this information and all images in landscape format resulting in flipped portrait images. Imagecache Actions module provides an action to rotate images based on EXIF data. But: this doesn't work if the image was resized to the maximum dimensions straight after the upload. And: it doesn't play nice with most image cropping modules.

I've been fighting this issue for some hours now and have something that seems to work for me. It's not extensively tested yet, though. Here's what I came up with:

Modules:

Tags: 

Drupal Base Theme Mothership breaks Contextual Links

Simple CSS solution. Set the trigger to display: block;:

// Contextual links
.contextual-links-region:hover a.contextual-links-trigger {
  display: block;
 }

Instead of patching mothership as it's suggested in the source link, I'd recommend doing this in your own subtheme. As soon as mothership-7.x-3.0 gets a stable release it shouldn't be needed anymore as it has been committed to dev already.

Source: https://www.drupal.org/node/1677374

Drupal Custom View Modes & Templates per View Mode

Just a quick reminder how to programmatically create your own Drupal 7 View Modes. Replace superdrop_helpers with the name of your own module and listing with the desired name of your Drupal View Mode.

<?php 
/**
* Implements hook_entity_info_alter().
* Creates a new view mode called <listing>
*/
function superdrop_helpers_entity_info_alter(&$entity_info) {
  $entity_info['node']['view modes']['listing'] = array(
    'label' => t('Auflistung'),
    'custom settings' => TRUE,
  );
}

/**
* Implements hook_preprocess_node().
* Template file suggestion for the previously generated view mode
* e.g.: node--article--listing.tpl.php
*/
function superdrop_helpers_preprocess_node(&$vars) {
  if($vars['view_mode'] == 'listing') {
    $vars['theme_hook_suggestions'][] = 'node__' . $vars['type'] . '__listing';
  }
} 

Thanks to wunderkraut for their article on this topic, check it out if you need more explanation than just the snippet:
http://www.wunderkraut.com/blog/drupal-7-custom-node-view-modes/2010-12-20

Tags: 

Drupal Module Comparison: Publish Button vs Safe Draft

To publish and unpublish content in Drupal you ususually have to tick or untick the Published checkbox before hitting the Save button. Sparing your users a click is alway a good idea, so why not considering a module that simplifies the action of publishing and unpublishing content.

Please welcome Publish Button and Safe Draft.

Both modules will simply add button actions to your nodes to publish/unpublish content instead of ticking that clumsy checkbox.

Here's why I opted for Publish Button over Safe Draft:

  • Publish Button is actively maintained, Safe Drafts was last updated in 2011
  • Publish Button can be enabled per-content type whereas Safe Drafts is always enabled globally
  • Publish Button features per-content type permissions
  • Publish Button hides empty vertical tabs opposed to Safe Draft, which shows the Publishing options tab even when it's completely empty
Tags: 

Drupal User Registration and Login with Email instead of Username

Drupal's default registration process is more complicated than it should be. To simplify the process I like my users to sign up and log in with only their email address and password.

There are various ways to deal with that issue, with Login Toboggan being one of the most popular ones. However, I rarely need all the other stuff that comes with this module and I prefer small modules that focus on a single task. Besides, Login Toboggan only allows to login with an email address as an alternative to the username, it doesn't remove the need to create a username in the first place.

So what I found best for my needs is a combination of the Email Registration module and a tiny custom module.

Output a Field Collection's Item ID and build a Jump Navigation

It just took me a while to figure this out, as I needed the Field Collection's ID to build anchors for a (views built) jump navigation. Here's how I'm wrapping each Field Collection item with a section tag that has a CSS ID with each Field Collection item's unique identifier.

<section id="section-<?php print $elements['#entity']->item_id; ?>">
  <?php print render($content); ?>
</section>

For future reference here's also the (simple) View that builds the jump navigation from Field Collection titles. It takes the node ID as an contextual filter from the URL. So you just get a jump navigation for the Field Collection items from the host node that's currently being displayed. Note that this View expects a field named field_section_title to use for the menu item.

Pages