Skip to content

Instantly share code, notes, and snippets.

View Jaesin's full-sized avatar

Jaesin Mulenex Jaesin

View GitHub Profile
@Jaesin
Jaesin / load_and_cache_view
Created April 7, 2014 23:11
Load, cache and use fields in drupal views 7.x-3.x
// Get the view that grabs the data for this tableselect.
$view = views_get_view('view_name');
$view->init();
$view->set_display('default');
$view->set_items_per_page(0);
$view->set_arguments(array('123+1234')); // mass multiple node id's
$view->pre_execute();
$view->execute();
// Render and cache the fields for later use at $view->style_plugin->rendered_fields[$index][$field_name].
@Jaesin
Jaesin / vagrant_ssh-agent
Last active August 29, 2015 14:01
Allow ssh forwarding in Vagrant during provisioning.
# Enable agent forwarding during provisioning.
config.vm.provision :shell do |shell|
shell.inline = "touch $1 && chmod 0440 $1 && echo $2 > $1"
shell.args = %q{/etc/sudoers.d/root_ssh_agent "Defaults env_keep += \"SSH_AUTH_SOCK\""}
end
@Jaesin
Jaesin / node_export.php
Last active August 29, 2015 14:06
Export some nodes to be imported via a hook_update_N. (Drupal)
<?php
// From: http://steindom.com/articles/how-export-and-import-drupal-nodes
// Enter node NIDs to export.
$nids = array(
1991, // path/to/node/1991
2061, // path/to/node/2061
2016, // path/to/node/2016
2021, // path/to/node/2021
2026, // path/to/node/2026
2031, // path/to/node/2031
@Jaesin
Jaesin / drush-it-up.sh
Last active December 31, 2015 00:44
Install drushes
#!/bin/bash
# See: https://packagist.org/packages/drush/drush
# Drush 7 (Global)
composer global require "drush/drush:7.*"
# Drush 6 (Local)
mkdir -p /usr/local/share/drush/6.x
cd /usr/local/share/drush/6.x
composer require "drush/drush:6.*"
@Jaesin
Jaesin / drupal.perm.admin.checkbox.js
Last active August 29, 2015 14:11
Add Select All on the drupal permissions page.
(function ($) {
var columns = $("#permissions tr.even").first().find("input.form-checkbox").length;
var heads = $("#permissions thead th");
for (var i=1; i<columns+1; i++) {
var cbToggler = $("<input type=checkbox>").data('column', i);
cbToggler.click(function(e) {
var checked = this.checked;
var allCheckboxes = $("#permissions tbody input.form-checkbox");
for (var n=$(this).data('column')-1; n<allCheckboxes.length; n+=columns) {
@Jaesin
Jaesin / d7.settings.php
Last active November 13, 2017 22:41
Some settings.php options
<?php
/**
* @file
* Some possible additions to the settings.php file or the settings.local.php file.
*/
$databases = ['default' => ['default' => [
'database' => 'db',
'username' => 'user',
'password' => 'pwd',
@Jaesin
Jaesin / D8-create-snapshot.php
Created February 22, 2015 04:50
Create a new configuration snapshot in Drupal 8.
<?php
\Drupal::service('config.manager')->createSnapshot(\Drupal::service('config.storage'), \Drupal::service('config.storage.snapshot'));
@Jaesin
Jaesin / autocomplete-block-widget.php
Last active August 29, 2015 14:15
Getting an autocomplete field widget for use in block configuration.
<?php
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Field\BaseFieldDefinition;
use Drupal\Core\Field\EntityReferenceFieldItemList;
use Drupal\Core\TypedData\DataDefinition;
use Drupal\Core\TypedData\Plugin\DataType\ItemList;
/**
* Provides a 'FooBlock' block.
*
@Jaesin
Jaesin / type_introspection.php
Last active August 29, 2015 14:17
Let PHPStorm know what gets served from a factory method.
<?php
/** @var \Drupal\Core\Entity\EntityManager $entity_manager */
$entity_manager = \Drupal::service('entity.manager');
@Jaesin
Jaesin / d8-toogle-toolbar.js
Last active August 29, 2015 14:17
Toggle the toolbar orientation on Drupal 8 via hidden button.
jQuery('.toolbar-toggle-orientation button').click();