You are hereModules
Modules
Setting Sessions and Cookies
Setting a session in Drupal is easy, everything is set from the Drupal boostrap, all you need to do is to set it and get it. Like
$_SESSION['zip'] = $form_state['values']['zip_code'];
and latter you just get value on some page like
$view_filters['field_zip_range']['value'] = $_SESSION['zip'];
and it works. Just be careful of caching and varnish and similar things as they sometimes do not cooparate.
Session is set on server side.
For client side, you use cookies and set it like this
user_cookie_save(array('key'=>'value'));
print $_COOKIE['Drupal_visitor_key'];
View 3, alter filters programmatically
if ($view->name === 'pricing') {
$view_filters = $view->display_handler->get_option('filters');
$view_filters['field_zip_range']['value'] = $_SESSION['zip_code'];
$overrides = array();
$overrides['filters'] = $view_filters;
foreach ($overrides as $option => $definition) {
$view->display_handler->override_option($option, $definition);
}
}
}
Views 3 query altering with hook_views_query_alter
You can alter views, alter queries and much more. Problem with documentation online is that is lacking some crucial information.
First, you should put your alter function in separate file, your_module.views.inc
as it is said here
https://api.drupal.org/api/views/views.api.php/function/hook_views_query...
What you also need to do is implement hook_views_api, it is said above that you don't have to but with lates views 3.0 it won't work if you don't do it, so you add this little line
return array('api' => 3.0);
}
Modal form, CTools automodal and redirect
Currently I am using a https://drupal.org/project/ctools_automodal for my modal forms, that use CTools and its form dialogs for nice overlay forms (well not so nice, they look ugly as hell, but you can theme things :) ).
So there are some good tutorials how to setup modal forms and make you forms in overlay
http://deeson-online.co.uk/labs/insert-form-pop-modal-ctools-and-drupal-7
http://drupion.com/blog/10-steps-creating-ctools-modal-window-drupal-7
WSOD or white screen of death and error reporting
Sometimes you will have a WSOD and nothing to show for. One simple solution to get what is a problem is to insert the following lines into the Drupal's index.php, that should set PHP to report all errors.
error_reporting(E_ALL);
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);
?>
and you will probably see that some module is making a problem, so you can fix it or disable it.
Converting Form API date field to timestamp
If you are not using a date module and just want to use date field from form api, you will want to insert it into DB, probably as timestamp. So to convert that value to timestamp you need to use some precoding for that. In this example we also use a simple textfield to enter time value and add it to timestamp. Also take a note we are using timezone value.
$dateFrom = $form_state['values']['schedule_container']['date_container']['from']['date'];
Database API, several ways to retrieve data from query
$uid = 1;
$result = db_query('SELECT n.nid, n.title, n.created
FROM {node} n WHERE n.uid = :uid', array(':uid' => $uid));
Fetch next row as a stdClass object.
$record = $result->fetchObject();
Fetch next row as an associative array.
$record = $result->fetchAssoc();
Fetch data from specific column from next row.Defaults to first column if not specified as argument
$data = $result->fetchColumn(1);
Grabs the title from the next row. Retrieve all records into an indexed array of stdClass objects.
$result->fetchAll();
Search API, Apache Solr, Facets, Location and Open Layers
This 2 videos cover most of what you need to know about the Search API, Facets API, Apache Solr Search and Open Layers.
http://www.phase2technology.com/blog/maps-geocoding-search-talk-at-dug-i...
https://prague2013.drupal.org/session/building-amazing-searches-search-api
Sorting array of objects by value
Drupal uses many multidimensional arrays and usually you won't need to do this, or will do it in some theme layer or with views. But I did have a case where I needed to sort out array of entities by score value so I did it this way.
I used uasort or you can also use usort, both should work and properly order arrays, if you want to be sure, maybe use uasort as it is said that it "maintains index association", not sure if this would be needed here.
Getting host node and node id of field collection
I was killing myself to get host node and node.id of field_collection I am using so I can do some preprocessing before this node is saved. I was trying with field_collection_item_get_host_entity but just couldn't make it work. So I asked google and found out I can do it with regular host function like
$node = $collection->hostEntity();
echo $node->nid;