Skip to content

Instantly share code, notes, and snippets.

@GoZOo
GoZOo / blockadmin_example.admin.inc
Created April 26, 2013 13:48
Example for make blocks easily configurable for webmaster without 'administer blocks' access (and without huge permissive module). This fully use formapi (http://api.drupal.org/node/15320) and custom code.
<?php
function blockadmin_example_admin() {
$text = variable_get('blockadmin_example_page_text', array('format'=> 'filtered_html', 'value'=> ""));
$form['blockadmin_example_page_text'] = array(
'#type' => 'text_format',
'#format' => $text['format'],
'#title' => t('Texte'),
'#default_value' => $text['value'],
@GoZOo
GoZOo / exclude-content-from-search.php
Created June 4, 2013 08:15
Drupal code: Exclude some content types from node search
<?php
/**
* Implements of hook_query_node_access_alter().
* Exclude some content types from node search
* Ne pas prendre en compte certains types de contenu dans la recherche
*/
function mymodule_query_node_access_alter(QueryAlterableInterface $query) {
global $user;
// No exclude for super admin
@GoZOo
GoZOo / settings-fast_404.patch
Last active December 21, 2015 12:38
Patch to add fast_404 extensions configuration for nvosprofile on settings.php
From 645f985760acee829817832a9922929874007f20 Mon Sep 17 00:00:00 2001
From: GoZ <[email protected]>
Date: Thu, 22 Aug 2013 15:13:31 +0200
Subject: [PATCH] Add settings for fast_404
---
sites/default/default.settings.php | 78 ++++++++++++++++++++++++++++++++++++
1 files changed, 78 insertions(+), 0 deletions(-)
diff --git a/sites/default/default.settings.php b/sites/default/default.settings.php
@GoZOo
GoZOo / install-lamp.bash
Last active December 22, 2015 19:39
Installation d'un serveur lamp basique pour drupal
apt-get install apache2 php5 mysql-server phpmyadmin git-core vim curl php5-curl sendmail
# active apache mods
a2enmod rewrite headers expires
# install pear
wget http://pear.php.net/go-pear.phar
php go-pear.phar
# install drush
@GoZOo
GoZOo / media_field_formapi.php
Last active December 22, 2015 20:08
Manage media field with form api forms for Drupal 7 administration pages
<?php
/**
* Manage media field with form api forms for administration pages
* Depends of media module http://dgo.to/media
**/
/**
* Function called by drupal_get_form()
**/
function myform($form, &$form_state) {
@GoZOo
GoZOo / drupal7
Last active August 29, 2015 14:07
Simple Nginx configuration for Drupal
# file templates/drupal7
charset utf-8;
error_page 404 = @drupal;
error_page 405 = @drupal;
index index.html index.php;
location = /favicon.ico {
log_not_found off;
access_log off;
@GoZOo
GoZOo / .gitconfig
Last active March 16, 2017 10:45
Gitconfig
[core]
excludesfile = ~/.gitignore_global
autocrlf = input
[alias]
# Diff
d = diff --patch-with-stat
# Diff staged
ds = diff --staged --patch-with-stat
# Undo a `git push`
undopush = push -f origin HEAD^:master
@GoZOo
GoZOo / Drupal::Url
Created October 3, 2014 07:53
Drupal 8 implements url
in a hook, call Drupal::url() directly;
in a controller or a form or something like that, use the UrlGeneratorTrait (for forms at least it's already there for you),
for services, inject the 'url_generator' in your class by adding it in your service definition
@GoZOo
GoZOo / commerce_get_product_display_bundles.php
Last active August 29, 2015 14:14
Drupal Commerce Get all known product displays
<?php
/**
* Get all known product displays.
*
* We know they are product displays if they are node and have
* commerce_product_reference field type.
*
* @return array
* Array of bundle.
*/
@GoZOo
GoZOo / xdebug_vagrant
Created February 5, 2015 11:46
Configuration xdebug vagrant
zend_extension=xdebug.so
[xdebug]
xdebug.remote_enable=1
xdebug.remote_autostart=1
xdebug.remote_host=33.33.33.1
xdebug.remote_port=9000
xdebug.remote_connect_back=0
xdebug.max_nesting_level=400
xdebug.idekey=vagrant