Skip to content

Instantly share code, notes, and snippets.

@opi
opi / gist:5144388
Created March 12, 2013 16:29
Implements hook_language_switch_links_alter() - Alter language switch links.
<?php
/**
* Implements hook_language_switch_links_alter().
*/
function mymodule_language_switch_links_alter(array &$links, $type, $path) {
global $language;
if ($type == LANGUAGE_TYPE_INTERFACE && isset($links[$language->language])) {
foreach ($links as $langcode => &$link) {
// If no translation exists, redirect to frontpage
@opi
opi / gist:5162579
Created March 14, 2013 15:59
Drupal: Navigation 404
<?php
/**
* Implements hook_menu().
*/
function mymodule_menu() {
$items = array();
// PUBLIC PAGES
@opi
opi / gist:5335785
Last active April 28, 2020 18:27
Drupal 7 : Add translation programmatically
<?php
$report = array(
'skips'=>0,
'updates'=>0,
'deletes'=>0,
'additions'=>0
); // ??
$source = "Sometime drupal sucks";
$translation = "Drupal C DLA BALLE";
@opi
opi / gist:5434701
Last active December 16, 2015 12:28
Mimic drupal rabbithole module
<?php
function mymodule_node_view($node, $view_mode, $langcode) {
// Mimic rabbit-hole module
if (node_is_page($node)) {
// Access denied:
drupal_access_denied();
drupal_exit();
// Page not found:
@opi
opi / .gitignore
Last active December 16, 2015 19:40 — forked from jbudziak/.gitignore
# Ignore configuration files that may contain sensitive information.
sites/*/*settings*.php
# Ignore paths that contain generated content.
cache/
files/
sites/*/files
sites/*/private
# Server configuration files
@opi
opi / gist:5501735
Created May 2, 2013 11:55
Debug Drupal EntityFieldQuery
<?php
/**
* Implements hook_query_alter().
*
* Adds a tag management named "query_debug" that permits to retrieve
* the concerned request implementing this tag.
* Only for development use. Custom requests SHOULDN'T implement this tag in a
* production website.
*/
@opi
opi / gist:5635657
Created May 23, 2013 12:18
Quick'n'dirty solve for media pdf bug
<?php
/**
* Implements hook_preprocess_media_views_view_media_browser()
*/
function mymodule_preprocess_media_views_view_media_browser(&$vars) {
foreach ($vars['rows'] as $delta => $row) {
if ($row->filemime == 'application/pdf') {
// See http://drupal.org/node/1743040
$vars['rows'][$delta]->preview = l(
@opi
opi / field--no_markup.tpl.php
Created June 5, 2013 08:03
Reduce div soup in drupal theme. (like fences or field_wrappers modules)
<?php
/**
* @file field.tpl.php
* See http://api.drupal.org/api/drupal/modules!field!theme!field.tpl.php/7
*
* Theme suggestions:
* - field.tpl.php
* - field--TYPE.tpl.php
* - field--NAME.tpl.php
* - field--CONTENT_TYPE.tpl.php
@opi
opi / gist:5856896
Created June 25, 2013 08:28
Drupal: Add Google Analytics event to a form
<?php
function your_module_form($form, &$form_state) {
// Your form definition
// Google Analytics event
$form['#attached'] = array(
'js' => array(
'(function($){
@opi
opi / gist:6018369
Created July 17, 2013 07:22
Alter jQuery UI css in drupal
<?php
/**
* Implements hook_css_alter().
*/
function yourtheme_css_alter(&$css) {
// Do not use jQuery UI defaults
$yourtheme = drupal_get_path('theme', 'yourtheme');
foreach(array('theme', 'tabs', 'accordion') as $file) {
if (isset($css['misc/ui/jquery.ui.'.$file.'.css'])) {