Skip to content

Instantly share code, notes, and snippets.

View jonathanfranks's full-sized avatar

J F jonathanfranks

  • Breakthrough
  • Evanston, IL
View GitHub Profile
@jonathanfranks
jonathanfranks / gist:ec065382acb1c016329a
Created July 20, 2015 17:57
Manual clear flood table
$results = db_select('flood')->fields(NULL, array('expiration'))->execute()->fetchAll();
$count = count($results);
dpm($count);
db_delete('flood')
->execute();
$results = db_select('flood')->fields(NULL, array('expiration'))->execute()->fetchAll();
$count = count($results);
dpm($count);
@jonathanfranks
jonathanfranks / behat.yml
Created June 24, 2015 18:25
Default formatter set to Progress in Behat 3.0 behat.yml
default:
formatters:
defaultFormat:
name: 'progress'
@jonathanfranks
jonathanfranks / gist:a38829b184eb54ebf83a
Created June 5, 2015 21:07
Drupal Facet API Custom Hierarchy Callback for Entity Reference Fields
/**
* Implements hook_facetapi_facet_info_alter().
*/
function hook_facetapi_facet_info_alter(array &$facet_info, array $searcher_info) {
foreach ($facet_info as $name => $facet) {
$name = 'field_parent';
if ($name == $name) {
$facet_info[$name]['hierarchy callback'] = 'hook_facets_entity_reference_hierarchy';
}
}
@jonathanfranks
jonathanfranks / publish_nodes.php
Created April 20, 2015 23:45
Publish all nodes of a type
public function iPublishAllNodes($content_type) {
$query = new EntityFieldQuery();
$query->entityCondition('entity_type', 'node')
->entityCondition('bundle', $content_type);
$result = $query->execute();
if (isset($result['node'])) {
$nids = array_keys($result['node']);
$nodes = node_load_multiple($nids);
foreach ($nodes as $node) {
$node->status = 1;
@jonathanfranks
jonathanfranks / FailureHtmlDumpContext.php
Created April 9, 2015 00:51
Behat 3 HTML dump on failure
<?php
use Behat\MinkExtension\Context\RawMinkContext,
Behat\Behat\Hook\Scope\AfterScenarioScope;
/**
* Defines application features from the specific context.
*/
class FailureHtmlDumpContext extends RawMinkContext {
/**
@jonathanfranks
jonathanfranks / EFQ
Last active August 29, 2015 14:17
Delete all entities of a type
$entity_type = 'node';
$bundle = 'article';
$query = new EntityFieldQuery();
$query->entityCondition('entity_type', $entity_type)
->entityCondition('bundle', $bundle);
$result = $query->execute();
if (isset($result[$entity_type])) {
$ids = array_keys($result[$entity_type]);
@jonathanfranks
jonathanfranks / FeatureContext.php
Created March 21, 2015 21:34
Writing an html dump on a Behat failure
public function recordFailedEvent($event) {
$fileName = $this->timestamp;
// TODO: Make this a setting in behat.yml?
$html_dump_path = 'failures';
$message = '';
$session = $this->getSession();
$page = $session->getPage();
$driver = $session->getDriver();
$date = date('Y-m-d H:i:s');
@jonathanfranks
jonathanfranks / Form alter
Created March 5, 2015 18:35
Drupal #states or conditions
$form['my_field']['#states'] = array(
'visible' => array(
array(
array(':input[name="field_other[und]"]' => array('value' => 'first')),
'or',
array(':input[name="field_other[und]"]' => array('value' => 'second')),
),
),
);
@jonathanfranks
jonathanfranks / ignore_ds_store.sh
Created February 10, 2015 21:39
Globally ignore all .ds_store files (OSX)
echo .DS_Store > ~/.gitignore_global
git config --global core.excludesfile ~/.gitignore_global
@jonathanfranks
jonathanfranks / drupal_vocab_delete_terms
Last active August 29, 2015 14:14
Delete all terms from a vocabulary
$vocab_name = '';
$vocab_id = taxonomy_vocabulary_machine_name_load($vocab_name)->vid;
dpm($vocab_id);
$tids = array();
foreach (taxonomy_get_tree($vocab_id) as $term) {
taxonomy_term_delete($term->tid);
}