Skip to content

Instantly share code, notes, and snippets.

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

Venture rafinskipg

🏠
Working from home
  • web3
  • Worldwide
View GitHub Profile
@rafinskipg
rafinskipg / select_node_types_form.php
Created November 1, 2012 16:10
Node types selection for migration modules forms
$types = node_type_get_types();
$option_types = array();
foreach($types as $type){
$option_types[$type->type] = $type->name;
}
$form['migration_type'] = array(
'#type' => 'select',
'#options' => $option_types,
'#title' => t('Select the contet type to be created?'),
@rafinskipg
rafinskipg / query_alter_example.php
Created November 2, 2012 12:33
Views query alter
function mymodule_views_query_alter(&$view, &$query) {
if ($view->name == 'myview' ) {
//Filter taxonomy by language
global $language;
$query->where[] = array(
'conditions' => array(array(
'field' => 'taxonomy_term_data.language',
'value' => array($language->language),
'operator' => 'in',
)),
@rafinskipg
rafinskipg / views_programatically.php
Created November 2, 2012 12:42
Creating views Drupal 7 programatically, with exposed filters and order by
$view = 'my_view_name';
$display = 'my_display';
$alter = array('exposed' => array('title' => 'title I search'), 'node_created_order' => 'ASC');
//Simple results of a view
public function getResults($view, $display, $args = NULL){
return views_get_view_result($view, $display, $args);
}
//View with exposed filters and more things
@rafinskipg
rafinskipg / block_render.php
Created November 2, 2012 12:44
Invoke a block and render it (Drupal 7)
/**
*Render a block
*/
function block_render($module, $block_id) {
$block = block_load($module, $block_id);
if(!isset($block->title)){
$block->title = '';
}
if(!isset($block->region)){
$block->region = '';
@rafinskipg
rafinskipg / query_search_alter.php
Created November 2, 2012 13:23
Drupal 7 Default query search alter
function mymodule_query_alter(QueryAlterableInterface $query){
$is_search = FALSE;
foreach ($query->getTables() as $table) {
if ($table['table'] == 'search_index') {
$is_search = TRUE;
}
}
if ($is_search) {
global $language;
@rafinskipg
rafinskipg / check_filters_views.php
Created November 5, 2012 11:51
Look if a view has exposed filters
$name = 'my_view';
$display = 'page_1';
$exposed = array('title', 'type', 'created');
public function hasExposed($name, $display, $exposed){
$view = views_get_view($name);
$view->set_display($display);
$view->preview=TRUE;
$view->is_cacheable = FALSE;
@rafinskipg
rafinskipg / patch_i_need.php
Created November 6, 2012 00:55
The stupid patch to core entity for drupal 7.15
if(!empty($ids)){
$ids2 = array_filter($ids);
if(!is_null($ids2)){
$ids2 = array_filter($ids2, 'is_string');
}
if(!is_null($ids2)){
$ids2 = array_filter($ids2, 'strlen');
}
}else{
@rafinskipg
rafinskipg / default_images_field_features.php
Created December 10, 2012 15:03
Default images for fields in features
function module_field_default_fields_alter(&$fields) {
$source_dir = drupal_get_path('theme', 'soc') . '/images/default';
$field_default_images = array(
//'user-user-field_user_picture' => 'avatar.png', - This is exported in the feature
//'field_collection_item-field_people-field_people_photo' => 'avatar.png', - example for field collection
'node-event-field_event_image' => 'minificha_eventos.gif',
'node-news-field_image' => 'minificha_noticias.gif',
);
@rafinskipg
rafinskipg / asd.php
Created December 13, 2012 15:24
asd
asd
@rafinskipg
rafinskipg / UtilsSrv.js
Created December 4, 2013 09:29
Angular HTTP console, logs all activity
(function () {
'use strict';
angular.module('myApp')
.factory('UtilsSrv',
[ function () {
//You can disable the loggin of data here, also you can set the level of debug
var debugMode = true;
var logLevel = 3;