“Still,” he says, “certain things compel people. Pearls, for example, and sinistral shells, shells with a left-handed opening. Even the best scientists feel the urge now and then to put something in a pocket. That something so small could be so beautiful. Worth so much. Only the strongest people can turn away from feelings like that.”
– Dr. Geffard, All the Light We Cannot See, page 52
When the wind’s blowing at gale force
When the wind’s blowing at gale force, there’s no point in sailing against it.
– Frank Underwood, House of Cards, Season 3, Episode 2
Kung hindi ka marunong magmahal
Hindi ka maaaring hindi magmahal kahit mapasaiyo pa ang lahat. Maaari kang maging pinakamayamang tao sa mundo, pinakamatalino, pinakamakapangyarihan, at walang pangarap na hindi kayang kunin o abutin pero kung hindi ka marunong magmahal, sino ka?
– Amelia, SI, Chapter 56, page 36
But men are better than gates
But men are better than gates, and no gate will endure against our Enemy if men desert it.
– Aragorn, Chapter 9: The Last Debate, Return of the King
Drupal Workbench: Assigning revision owner when moderating backwards with Workbench
<?php
/**
* Implements hook_node_update().
*/
function mymodule_node_update($node) {
db_update('node_revision')
->fields(array('uid' => $node->uid))
->condition('nid', $node->nid)
->condition('vid', $node->vid)
->execute();
}
/**
* Implements hook_workbench_moderation_transition().
*/
function mymodule_workbench_moderation_transition($node, $previous_state, $new_state) {
if (isset($node->nid) && isset($node->vid) && isset($node->uid)) {
mymodule_node_update($node);
}
}
Source: http://goo.gl/VT0qS9
Drupal: Allow HTML in node title
<?php
/*
* This function generates the variables that are available in your node.tpl,
* you should already have this in your template.php, but if not, create it.
*/
function mytheme_preprocess_node(&$vars) {
// It's important to run some kind of filter on the title so users can't
// use fx script tags to inject js or do nasty things.
$vars['title'] = filter_xss($vars['node']->title);
}
Source: http://goo.gl/mUBcPj
Drupal: Make regions available from node.tpl.php
<?php
/**
* Then render any region like
* <?php print render($region['sidebar_first']); ?>
*/
function mytheme_preprocess_node(&$variables) {
// Get a list of all the regions for this theme
foreach (system_region_list($GLOBALS['theme']) as $region_key => $region_name) {
// Get the content for each region and add it to the $region variable
if ($blocks = block_get_blocks_by_region($region_key)) {
$variables['region'][$region_key] = $blocks;
}
else {
$variables['region'][$region_key] = array();
}
}
}
Source: http://goo.gl/ZCdXwK
Drupal – Reverting Feature modules
<?php
/**
* Revert specified features.
*
* @TODO Check that it really is Forced features revert. Currently an exact
* copy of the function initially placed in feature_projects.install.
*
* Code mostly taken from drush.
*
* Source: Reverting features in update hooks requires a helper function
* (http://goo.gl/MKSd11)
*/
function _features_revert($modules) {
module_load_include('inc', 'features', 'features.export');
features_include();
foreach ($modules as $module) {
$components = array();
if (($feature = feature_load($module, TRUE)) && module_exists($module)) {
// Forcefully revert all components of a feature.
foreach (array_keys($feature->info['features']) as $component) {
if (features_hook($component, 'features_revert')) {
$components[] = $component;
}
}
}
foreach ($components as $component) {
features_revert(array($module => array($component)));
}
}
}
Drupal – Redirect after form submission
function mymodule_form_alter(&$form, &$form_state, $form_id) {
if ($form_id == 'my_form') {
$form['#submit'][] = 'my_submit_handler';
}
}
function my_submit_handler(&$form, &$form_state) {
$form_state['redirect'] = 'home';
}
Source: http://goo.gl/it93ym
Drupal – Skipping require fields errors
function hook_form_validate($form, &$form_state) {
$errors = form_get_errors();
if ($errors) {
// Clear errors.
form_clear_error();
// Clear error messages.
$error_messages = drupal_get_messages('error');
// Initialize an array where removed error messages are stored.
$removed_messages = array();
// Remove all errors originated by the 'foo][bar' element.
foreach ($errors as $name => $error_message) {
if ($name == 'body][und][0][value') {
$removed_messages[] = $error_message;
unset($errors[$name]);
}
}
// Reinstate remaining errors.
foreach ($errors as $name => $error) {
form_set_error($name, $error);
// form_set_error() calls drupal_set_message(), so we have to filter out
// these from the error messages as well.
$removed_messages[] = $error;
}
// Reinstate remaining error messages (which, at this point, are messages that
// were originated outside of the validation process).
foreach (array_diff($error_messages['error'], $removed_messages) as $message) {
drupal_set_message($message, 'error');
}
}
}
Source: http://goo.gl/nI55mb

