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 / 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 / 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 / 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 / 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 / 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?'),