Skip to content

Instantly share code, notes, and snippets.

View jessehs's full-sized avatar

Jesse Hofmann-Smith jessehs

  • Phase2 Technology
  • El Prado, New Mexico, USA
View GitHub Profile
@jessehs
jessehs / Blocks.md
Created May 14, 2020 14:39 — forked from bdlangton/Blocks.md
Drupal 8 programmatic solutions

Render custom blocks

$bid = 'myblock';
$block = \Drupal\block_content\Entity\BlockContent::load($bid);
$render = \Drupal::entityTypeManager()->getViewBuilder('block_content')->view($block);

Render plugin blocks

$block_manager = \Drupal::service('plugin.manager.block');
@jessehs
jessehs / preprocess_beans.php
Last active August 29, 2015 14:05
Add arbitrary classes to a Bean block.
<?php
/**
* Implements hook_preprocess_block().
*
* Adds a few helpful theming classes to a bean block:
* The bean's view mode, bundle (bean type), and the value of an arbitrary
* field, 'field_image_size'. Use this for beans placed using core blocks or
* the Context module.
*/
function THEME_preprocess_block(&$variables) {
<!-- Twitter widget embedded in block. -->
<a class="twitter-timeline"data-dnt="true" data-tweet-limit="5" href="https://twitter.com/jessetweet" data-widget-id="479455834242445314">Tweets by @jessetweet</a>
<!--Twitter widget script is attached in the footer.-->
<?php
/**
* Override or insert javascript on the site.
*
* @param (array) $js
* An array of all JavaScript being presented on the page. I can't figure out why it won't show up if I attach it in the footer.
@jessehs
jessehs / makeproject.sh
Created June 10, 2014 21:26
Add this to your .bashrc or .profile file. This is useful you update patches on a contrib module and don't want to rebuild the entire site.
# Use drush make to build only a single project from a make file (without needing to rebuild the whole thing).
drushMakeProject() {
drush make --contrib-destination=. --no-core --projects=$1 -y $2
}
alias makeproject=drushMakeProject
@jessehs
jessehs / gist:11384363
Created April 28, 2014 21:19
Create a fieldable_panels_pane entity in an update hook. (I have not yet tested whether this works.)
<?php
$fpp = fieldable_panels_panes_create(array('bundle' => 'freeform'));
$fpp->admin_title = "Placeholder FPP";
$fpp->category = "Home page blocks";
$fpp->title = "Placeholder FPP";
$fpp->link = 0;
$fpp->field_freeform_html[und][0][value] = '<p>Placeholder</p>';
$fpp->field_freeform_html[und][0][format] = "full_html";
$fpp->description = "Placeholder FPP";
@jessehs
jessehs / gist:9646202
Created March 19, 2014 17:00
Rather than using `drush geocoder-backfill`, I'm running `drush scr /path/to/this/file` on cron to update profiles.
<?php
$range = 50;
$offset = variable_get('my_custom_profiles_update_offset', 0);
$query = db_select('users', 'u')
->fields('u', array('uid'));
$query->join('users_roles', 'ur', 'u.uid = ur.uid');
$or = db_or();
$or->condition('ur.rid', '9', '=');
<?php
/**
* Implements hook_default_message_type().
*/
function mymodule_default_message_type() {
$items = array();
$items['message_comment_on_group_post'] = entity_import('message_type', '{
"name" : "message_comment_on_group_post",
"description" : "Message: Comment on Group Post",
"argument_keys" : [],
<?php
/**
* @file aliases.drushrc.php
*/
$aliases['drupal8'] = array(
'uri' => 'drupalimp.localhost',
'root' => '/path/to/project/drupal8',
);
$('.megamenu-parent-title > a').click(function(e) {
// Don't follow the link.
e.preventDefault();
e.stopPropagation();
// Make top level links open/close the megamenu.
if ($(this).parent('li.megamenu-parent').hasClass('hover')) {
// This menu is already open. Close it.
megamenu_close();
}
else {
/**
* Revert xmlsitemap inclusion settings and regenerate sitemap.
*/
function ase_base_update_7004() {
features_revert(array(
'ase_blog' => array('variable'),
'ase_core' => array('variable'),
'ase_press_release' => array('variable'),
'ase_product' => array('variable'),
'ase_resource' => array('variable'),