Outside Links collection sticky icon

Sometimes you find just the right resources that fulfill certain need and nothing much should be added to them, in those cases I will just collect them on this page and add short comment why is this so.

How to combine Git and Drush to have perfect workflow for site maintenance, information and examples are here

Setting upt perfect Git + Drush workflow, read here

Contextual filter(views) for date ranges

I was building a view for RestWS to output JSONon data, to have date show for specific date range you need to pass filter range. To do that you need to pass filter as two dates, with separator beeing "--" e.x. 2015-06-24--2015-06-28

Or in full link it would be


Add to cart form, change output - separating attributes from buy button

This one was not easy. Changing product display, which is node is possible in different ways, but then you have a field_product_reference, which outputs buy button and attributes buttons. So you moved around price in your node template, body/description etc, but you want to separate attributes changing widget and buy. You just can't. Even if you change data in template, as it is using Ajax to refresh on clicking of any attributes. So you will lose your changes, made in template, or any other place you maybe found.

Choosing which PHP to run with Drush, changing CLI php

Using drush on mac with mamp gave me some problems with default setup. I didnt set
DRUSH_PHP variable anywhere so default php was used, also with that no php.ini setting was set and in my drush status I got empty "Drush configuration" variable. So to set this up, I needed to add this to either .profile or to .bash_profile (depends of load order, later goes first if you have it)

export DRUSH_PHP=/Applications/MAMP/bin/php/php5.3.29/bin/php

Changing Product attributes in drupal commerce, maintain data with ajax reload

What I needed is to preprocess this whole group of data, that consist add to cart button and attributes fields. "Add to cart form" is basically the one that consists attributes and add to cart button. To do that the only way to make it work with AJAX is with form alter. So change the forms data in

function my_module_form_commerce_cart_add_to_cart_form_alter(&$form, &$form_state) {

and you can probably get what you need. Think this is the only way. Templates get overrun by Ajax calls and only work on first generating of product.

Get address lat and long with google api

This will give you a nice array of all the data.

$request = drupal_http_request('https://maps.googleapis.com/maps/api/geocode/json?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA');
$out = drupal_json_decode($request->data);

Change Views filters, add dynamic date value as range

Using EVA field added to Order entity I needed to use order created date as starting range and ending range for dates.
UI by default doesn't offer this in views, so some preprocessing was done. You could fetch date from argument or as I did directly from
$view->current_entity->created; and add it to filter as you like. Use views_pre_build, add code, Clear Cache and it will work.

function mymodule_views_pre_build(&$view) {

//Override output of Filter

if($view->name == 'commerce_user_orders' && $view->current_display == 'entity_view_6'){

//Set Times

Quickly import DB on server

If you want to quickly import DB on your linux do this combo command, before just create that Database you want to have.

gunzip < data.mysql.gz | mysql -u root -p db_name

Quick out of memory or out of time debugging

ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);
ini_set('memory_limit', ''728M');
ini_set('max_execution_time', 120)

add this to index.php and see what is the output, act on that.

Huge load time, over 700 MB of memory and WSOD when adding/editing node

On a big site with more then 20 000 nodes, when creating particular node I first experienced WSOD, then as I reported errors, max_time_execution passed, then when this was raised memory limit passed. So I raised both to high limits, memory to 1gb and maxe_execution time to forever. Then I run the node/add and what I have to see is

Page execution time was 30257.61 ms. Memory used at: devel_boot()=2.21 MB, devel_shutdown()=707.38 MB, PHP peak=711.75