Skip to content

Instantly share code, notes, and snippets.

View ChezFre's full-sized avatar

Chez Fre ChezFre

View GitHub Profile
@ChezFre
ChezFre / template.php
Created January 20, 2016 16:16
Generate dropdown instead of textinput for number exposed filter in view
function THEME_form_alter(&$form, $form_state, $form_id) {
if( $form['#id'] == 'views-exposed-form-projects-page' ) {
krumo($form['type']);
$form['field_start_price_value']['#type'] = 'select';
$items = array();
for( $i = 50000; $i <= 1000000; $i += 10000 ) {
if( $i > 200000 && $i < 700000) {
$i += 15000;
@ChezFre
ChezFre / template.php
Created January 19, 2016 07:42
Make a category with a color that can be selected by the site administrator (color picker)
<?php
/*
1. Add Entity Reference or Taxonomy Reference field to Entity of choice
2. Install jQuery Spectrum Color Plugin support (see link at #3)
3. Add Color field to Taxonomy (https://www.drupal.org/project/color_field) and for Widget Type select the Spectrum picker
4. Enable the input field by checking the box at field settings
5. Add the following code to your template.php
*/
@ChezFre
ChezFre / settings.php
Created June 24, 2015 15:30
Show template suggestions in Drupal source
// via https://www.drupal.org/node/223440
$conf['theme_debug'] = TRUE;
@ChezFre
ChezFre / .htaccess
Created May 20, 2015 08:01
Allow cross domain references with multidomain sites (is probably only necessary when using advagg because this module uses the domain in its urls instead of simply linking via /sites/...)
<IfModule mod_headers.c>
SetEnvIf Origin "^http(s)?://(.+\.)?(domain\.ext|domain2\.ext|domain3\.ext)$" origin_is=$0
Header always set Access-Control-Allow-Origin %{origin_is}e env=origin_is
Header set Access-Control-Allow-Origin "*"
</IfModule>
@ChezFre
ChezFre / bash.mysql
Created May 18, 2015 08:54
Drop all tables mysql cli
SELECT concat('DROP TABLE IF EXISTS ', table_name, ';')
FROM information_schema.tables
WHERE table_schema = 'MyDatabaseName';
@ChezFre
ChezFre / template.php
Created February 11, 2015 15:48
Add placeholder to Drupal search form
function theme_form_alter(&$form, &$form_state, $form_id) {
$form['#attributes']['class'][] = 'clearfix';
if( $form['#form_id'] === "search_block_form" ) {
$form['search_block_form']['#attributes']['placeholder'] = t('Zoeken') . "…";
}
}
@ChezFre
ChezFre / field--your-collected-field--your-field-collection.tpl.php
Created November 27, 2014 19:17
Style individual items in a field collection
field--your-collected-field--your-field-collection.tpl.php
@ChezFre
ChezFre / template.php
Created November 26, 2014 08:27
Prefill a webform based on a given id or value in the URL
<?php
function hook_form_alter(&$form, &$form_state, $form_id) {
if( $form_id === "webform_client_form_nn" ) { // Update with actual form id
$node_id = $form['submitted']['wagen']['#value']; // Define a field in webform that takes a get value as default
$node = node_load( $node_id );
// If a node has been specificied via its nid (cid in url), we prefill the request field with the name and url of the car
@ChezFre
ChezFre / node.tpl.php
Last active August 29, 2015 14:07
Add attributes to rendered element in Drupal Template
<?php
$content['field_name'][0]['#item']['attributes']['attribute_name'] = 'value';
?>
@ChezFre
ChezFre / template.php
Created October 2, 2014 07:43
Unset all Drupal css and javascript files in your theme
function THEME_NAME_css_alter(&$css)
{
unset($css[drupal_get_path('module', 'system').'/system.theme.css']);
unset($css[drupal_get_path('module','system').'/system.base.css']);
unset($css[drupal_get_path('module', 'system').'/system.messages.css']);
unset($css[drupal_get_path('module', 'comment').'/comment.css']);
unset($css[drupal_get_path('module', 'field').'/theme/field.css']);
unset($css[drupal_get_path('module', 'mollom').'/mollom.css']);
unset($css[drupal_get_path('module', 'node').'/node.css']);
unset($css[drupal_get_path('module', 'search').'/search.css']);