Skip to content

Instantly share code, notes, and snippets.

@bmunslow
bmunslow / commerce-quantity-select-add-to-cart-form.php
Last active July 11, 2020 16:03
Drupal 8 - Commerce 2.x - Transform quantity field in add to cart form into select list
<?php
/**
* hook_form_alter()
*
* Switch quantity field from input text to select in add_to_cart forms
* Supports both standard add_to_cart, as shipped in commerce framework
* as well as ajax add_to_cart forms implemented by dc_ajax_add_cart module
*
* It also supports quantity fields as they appear in view cart form, both with
@bmunslow
bmunslow / process_csv.php
Last active August 22, 2016 07:43
Drupal: Programmatically read and process CSV file using Feeds CSV parser
<?php
/**
* Quick CSV parsing in Drupal 7, using CSV parser library in the Feeds module.
* Default encoding expected to be UTF8.
*
*/
// Custom variables, adjust to your needs
$file_name = 'public://custom_path_to_my_file.csv'
$delimiter = ';';
@bmunslow
bmunslow / entityqueue-add-items.php
Last active July 18, 2024 08:31
Drupal 7 - Programatically add items to EntityQueue
<?php
/**
* This snippet adds all nodes belonging to a specific node type to all
* entityqueues found in the system, defined by Entityqueue module
* Customize to your own needs by modifying relevant parts of the code.
* @see https://www.drupal.org/project/entityqueue
*/
// Get all available entityqueue queues
$all_queue_names = variable_get('entityqueue_queue_names', array());
foreach ($all_queue_names as $queue_name) {
@bmunslow
bmunslow / .htaccess
Last active March 28, 2017 07:06
Custom .htaccess maintenance mode
<IfModule mod_rewrite.c>
RewriteEngine on
# Customize specific IP address which should have access to the live site
RewriteCond %{REMOTE_ADDR} !^11\.22\.33\.44
# Customize name of your maintenance mode template file
RewriteCond %{REQUEST_URI} !/maintenance.html$ [NC]
# Only images and CSS files are allowed. Customize to allow Javascript or other image extensions
RewriteCond %{REQUEST_URI} !\.(jpe?g?|png|gif|css) [NC]