Skip to content

Instantly share code, notes, and snippets.

@jamesmorrish
jamesmorrish / EntityFieldQuery
Created September 23, 2013 10:56
Example entity field query including language.
$query = new EntityFieldQuery();
$query->entityCondition('entity_type', 'node')
->propertyCondition('type', 'blog')
->propertyCondition('status', 1)
->propertyOrderBy('created', 'DESC')
->fieldCondition('field_journal_carousel_image', 'fid', 0, '!=')
->range(0, 10);
$query->propertyCondition('language', array($GLOBALS['language']->language, LANGUAGE_NONE), 'IN');
@jamesmorrish
jamesmorrish / Change the length of a text field in Drupal
Created September 18, 2013 09:11
Change the length of a text field in Drupal
assuming you have a text field which machine name is field_text of 10 characters you want to grow to 25:
data will be stored in two tables: field_data_field_text and field_revision_field_text
definition is stored in field_config for the storage data, and field_config_instance for each instance of this field (stuff like label).
Now let's do a little heart surgery.
Alter the data tables columns definitions:
ALTER TABLE `field_data_field_text`
CHANGE `field_text_value` `field_text_value` VARCHAR( 25 )
@jamesmorrish
jamesmorrish / Delete all nodes of type
Created August 20, 2013 08:39
Delete all nodes of type
$node_type = 'product';
// Select the nodes that we want to delete.
$result = db_select('node', 'n')
->fields('n', array('nid'))
->condition('type', $node_type, '=')
->range(0,5)
->execute();
$deleted_count = 0;
@jamesmorrish
jamesmorrish / vi no indent
Created August 19, 2013 08:42
vi no indent
:setlocal noautoindent
@jamesmorrish
jamesmorrish / Export changes between GIT revisions
Created July 19, 2013 13:15
Export changes between to revisions in a GIT repository
git diff --name-only SHA1 SHA2 | xargs tar -cvzf myFile.tar.gz
Where SHA1 is first revision and SHA2 is last revision.
@jamesmorrish
jamesmorrish / Field groups missing from Features
Created July 19, 2013 08:51
Field groups not in Features
https://drupal.org/node/1619154#comment-6219918