Skip to content

Instantly share code, notes, and snippets.

@ghanbak
Last active May 24, 2017 16:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ghanbak/9942592 to your computer and use it in GitHub Desktop.
Save ghanbak/9942592 to your computer and use it in GitHub Desktop.
A gist for all things I need to know about Drupal.

drupal logo

ALL THINGS DRUPAL

Core Update

run this on / of the project

drush pm-update

Pull in a Node

print render(node_view(node_load(521), 'full', NULL));

Drupal jQuery Codex

(function($) {

  Drupal.behaviors.functionName = {
		attach: function (context, settings) {
			Drupal.behaviors.functionName.watch(context);
		},
		watch: function (context){

			// Your Function Here
			$('.class').hide();
		}
	}

  // Create a new behavior for every new function
	Drupal.behaviors.functionTwo = {
		attach: function (context, settings) {
			Drupal.behaviors.functionTwo.watch(context);
		},
		watch: function (context){
			$('.dropdown-menu').hide();
		}
	}
}(jQuery));

Drupal Patch

curl http://drupal.org/files/module-you-are-patching.patch | ssh username@serveraddress.com patch /path/to/module/file/module.module

Drupal Search Block

<?php
$block = module_invoke('search', 'block_view', 'search');
print render($block);
?>

Custom Bean Blocks

This is just a short example. Create beans then dpm the $content then get creative with layout and display. super swanky

<?php
  if(isset($content['field_info_links']['#items'][0]['title'])) {
    $link_path_one = $content['field_info_links']['#items'][0]['title'];
  }
  if(isset($content['field_info_links']['#items'][0]['url'])) {
    $link_path_one_url = $content['field_info_links']['#items'][0]['url'];
  }
?>
<div class="<?php echo $classes; ?>"<?php echo $attributes; ?>>
  <?php dpm($content); ?> // DPM IS DRUPAL'S DOM INSPECTOR
  <div class="callout-top">
    <ul>
      <li>
        <a href="<?php if(isset($link_path_one_url)) { echo $link_path_one_url; } ?>">
          <?php if(isset($link_path_one)) { echo $link_path_one; } ?>
        </a>
      </li>
    </ul>
  </div>
</div><!--/.div-classes-->

Google Webfont Loader

create a file called CLIENT.fontinfo and place it in the same directory as your theme .info file.

name = 'CLIENT Fonts'
google_families[] = 'Lato:100'
google_families[] = 'Lato:300'
google_families[] = 'Lato:700'
google_families[] = 'Lato'
google_families[] = 'Roboto Slab:100'
google_families[] = 'Roboto Slab:300'
google_families[] = 'Roboto Slab:700'
google_families[] = 'Roboto Slab'
render_css[] = 'CLIENT-fonts.css'

SUBLIME TAB SPACING FOR DRUPAL

"settings":
  {
    "tab_size": 2,
    "translate_tabs_to_spaces": true
  }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment