Skip to content

Instantly share code, notes, and snippets.

View lhuria94's full-sized avatar
🏠
Working from home

Love Huria lhuria94

🏠
Working from home
View GitHub Profile
@lhuria94
lhuria94 / better_tabledrag.php
Created November 22, 2017 10:59
Drupal table drag example in form An example of using a Drupal tabledrag table without the need of creating a theme function for the complete form. This makes it a lot easier to build a form which contains multiple form elements/fieldsets.
<?php
/**
* @file
* A tabledrag example - without theming the whole form.
*/
/**
* Implements hook_menu().
*/
@lhuria94
lhuria94 / git-restore-file.sh
Created September 22, 2017 06:08 — forked from msankhala/git-restore-file.sh
Find and restore a deleted file in a Git
# Find last commit for the deleted file
git rev-list -n 1 HEAD -- $path
# Checkout the commit before the the delete happened
git checkout $commit^ -- $path
<?php
/**
* Implements hook_element_info_alter().
*
* Sets the text format processor to a custom callback function.
* This code is taken from the Better Formats module.
*/
function module_element_info_alter(&$type) {
if (isset($type['text_format']['#process'])) {
foreach ($type['text_format']['#process'] as &$callback) {
@lhuria94
lhuria94 / entity-metadata-wrapper-isset.php
Created February 17, 2017 06:11 — forked from msankhala/entity-metadata-wrapper-isset.php
entity-metadata-wrapper isset check.
<?php
$field_collection_item = field_collection_item_load($id);
$item_wrapper = entity_metadata_wrapper('field_collection_item', $field_collection_item);
// this results in an error if the field_contrib_headshot field is empty
$headshot = $item_wrapper->field_contributor->field_contrib_headshot->value();
Solution:
// EntityStructureWrapper implements the __isset() function according the principe of Overloading.
$headshot = array();
<?php
$panelizer_nodes = db_select('node', 'n');
$panelizer_nodes->leftjoin('panelizer_entity', 'e', 'e.entity_id = n.nid');
$panelizer_nodes->fields('e', array('entity_id'));
$panelizer_nodes->condition('entity_type', 'node');
$panelizer_nodes->condition('did', 0, '<>');
$panelizer_nodes->condition('n.status ', 1, '=');
$panelizer_nodes->condition('n.type', 'content_type');
$result = $panelizer_nodes->groupBy('e.entity_id')->execute()->fetchCol('entity_id');
@lhuria94
lhuria94 / remove_image_markup.php
Last active February 17, 2017 06:04
Remove image object markup from rendering in Drupal 7 (Helpful for teaser display)
<?php
$body_text_alter_params = array(
'max_length' => 300,
'ellipsis' => FALSE,
'word_boundary' => TRUE,
'html' => FALSE,
);
// Removes unnecessary markup.
$trimmed_body = check_plain(strip_tags($value->body_value, '<p>'));
// Trimming the body text as per the parameters defined in