Skip to content

Instantly share code, notes, and snippets.

View vladdancer's full-sized avatar
🖖

Vlad Moyseenko vladdancer

🖖
View GitHub Profile
@vladdancer
vladdancer / theme_registry_alter
Created July 22, 2013 17:43
Alter theme registry
/**
* Implements hook_theme_registry_alter().
*
* @param $theme_registry
* Drupal theme registry that could be changed.
*/
function azr_catalog_theme_registry_alter(&$theme_registry) {
if (($key = array_search('crumbs_preprocess_page', $theme_registry['page']['preprocess functions'])) !== NULL) {
unset($theme_registry['page']['preprocess functions'][$key]);
}
@vladdancer
vladdancer / gist:6113321
Created July 30, 2013 14:19
Force views filter value
function ft_pm_articles_views_pre_view(&$view){
$display_id = $view->current_display;
if ($display_id == 'related_articles') {
_set_views_options($view, $display_id, 'field_article_category');
}
elseif ($display_id == 'related_news') {
_set_views_options($view, $display_id, 'field_tags');
}
}
@vladdancer
vladdancer / new_gist_file
Created September 3, 2013 08:55
Get csv columns for migrate class
function getCSVheader() {
$index = 1;
$numempty = 0;
$rows = _data_import_read_file($this->importArguments['file'], $this->importArguments['csvOptions']['delimiter']);
$header = array_shift($rows);
foreach($header as $title) {
if (!$this->importArguments['csvOptions']['header_rows']) {
$columns["col_$index"] = t('Column #!column', array('!column' => $index));
@vladdancer
vladdancer / wildcard-example
Created September 13, 2013 10:01
Wildcard Example
<?php
/**
* Wildcard loader for '%master_class'
* Add additional check after node_load() func.
* @param $nid
* @return bool|mixed
*/
function master_class_load($nid) {
$node = node_load($nid);
$condition = $node->type == 'master_class' && $node->status == 1;
@vladdancer
vladdancer / preprocess_html_add_delta_name.php
Created October 22, 2013 09:22
Add css classes to the <body> tag based on delta name.
function yourtheme_alpha_preprocess_html(&$vars) {
$classes = array();
$contexts = context_active_contexts();
// Add delta names as css classes for <body>
foreach ($contexts as $context) {
if (isset($context->reactions['delta']) && ($delta_name = $context->reactions['delta']['delta_template'])) {
$classes[] = drupal_html_class($delta_name);
}
}
function yourtheme_preprocess_page(&$vars) {
$contexts = context_active_contexts();
// Add delta based tpl.
foreach ($contexts as $context) {
if (isset($context->reactions['delta']) && ($delta_name = $context->reactions['delta']['delta_template'])) {
$vars['theme_hook_suggestions'][] = 'page__'. $delta_name;
}
}
}
function entity_property_values_create_entity($entity_type, $values = array()) {
if (entity_type_supports($entity_type, 'create')) {
$info = entity_get_info($entity_type);
// Create the initial entity by passing the values for all 'entity keys'
// to entity_create().
$entity_keys = array_filter($info['entity keys']);
$creation_values = array_intersect_key($values, array_flip($entity_keys));
// In case the bundle key does not match the property that sets it, ensure
// the bundle key is initialized somehow, so entity_extract_ids()
var myApp = angular.module('myApp', []);
var baseService = function () {
this._state = {};
};
baseService.prototype.getState = function () {
return this._state;
};
baseService.prototype.setState = function (state) {
this._state = state;
(function () {
function ParentService(arg1) {
this.arg1 = arg1;
}
function ChildService(arg1, arg2) {
ParentService.call(this, arg1);
this.arg2 = arg2;
}