DoSomething code - DoSomething/legacy-website GitHub Wiki

Naming conventions

  • mobilecommons (not mobile_commons)
  • reportback (not report_back)
  • signup (not sign_up)

Tests

All web tests need to include a $profile variable, in order for SimpleTest to find the modules directory.

Per https://drupal.org/comment/4909532#comment-4909532:

<?php
class DoSomethingModuleTestCase extends DrupalWebTestCase
  // Needed to be able to test the module inside the DoSomething installation profile:
  protected $profile = 'dosomething';
  ...
?>

You will also run into problems with web tests in the dosomething profile if every module's dependency is not explicitly set as a dependency in the dosomething.info file.

Features

Content Types

Each content type should be defined in a separate feature module, with naming convention dosomething_[content_type_machine_name]. The feature should also contain:

  • user permissions of which roles can create, edit, and delete the content type.
  • meta tag settings
  • pathauto pattern variable

All changes made to the content type, e.g. adding, modifying, deleting fields, should have the corresponding changes updated in the feature module.

Views

All views should be defined in a feature. If the view is specific to a content type, it should live in the dosomething_content_type feature.

Libraries

Some of our custom modules depend on PHP libraries which require installation via Composer. Because Composer isn't in the cards for Drupal 7 any time soon, we download the git directories into the relevant libraries subdirectory, and then run composer install in each individual subdirectory to compile the library. The hook_libraries_info can then point to the generated vendor/autoload.php file.

Images

Responsive images are themed calling dosomething_image_get_themed_image sending in

  • Image node id
  • Ratio (portrait, landscape, square)
  • Max dimensions (drupal image styles, named to the SIZE of the crops eg 300x300)
  • Alt text
  • Attributes (class etc)

The max dimensions are an image cached version of the image, these are set up in Image Styles in Drupal. Most of the image styles are scale & crop, but some are processed. An overlay can be added to the image directly in the Image Style. The image tag is then constructed using the styled url. All image tags are cached in a custom cache_dosomething_image table