Skip to content

Instantly share code, notes, and snippets.

@steffenr
steffenr / gist:11401484
Created April 29, 2014 14:09
Programmatically create file-download link (file_entity / Drupal)>
<?php
// Get download uri of actual file.
$uri = file_entity_download_uri($file);
// We need query-params for download-token here.
$dl_link = l(t('Download'), $uri['path'], array('query' => $uri['options']['query']));
print $dl_link;
@steffenr
steffenr / test.json
Last active August 29, 2015 13:58
GeoJSON Test
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@steffenr
steffenr / category_marker.php
Last active January 3, 2016 12:19
Use hook_leaflet_views_alter_points_data_alter to add category based icon to your markers shown with leaflet_views.
<?php
/**
* Implements hook_leaflet_views_alter_points_data_alter().
*/
function fewo_map_leaflet_views_alter_points_data_alter($result, &$points) {
// Get node object of result.
$wrapped_node = entity_metadata_wrapper('node', $result->nid);
// Check if we have a category attached to node.
$category = $wrapped_node->field_sight_category->value();
if (!empty($category)) {
@steffenr
steffenr / gist:6610501
Last active December 23, 2015 08:49
Get number of Organic Group Members. https://drupal.org/project/og
<?php
$query = db_select("og_membership", "ogm");
$query->fields("ogm", array('etid'));
$query->condition("ogm.gid", $og_context['gid']);
$query->condition("ogm.entity_type", 'user');
$result = $query->execute();
$og_member_count = $result->rowCount();
?>
@steffenr
steffenr / media_queries.css
Created September 1, 2013 11:14
Media Queries for Standard Devices
/* Smartphones (portrait and landscape) ----------- */
@media only screen
and (min-device-width : 320px)
and (max-device-width : 480px) {
/* Styles */
}
/* Smartphones (landscape) ----------- */
@media only screen
and (min-width : 321px) {
@steffenr
steffenr / date_popup.js
Created August 31, 2013 13:57
Depending to-date with jQuery datepicker
(function($) {
Drupal.behaviors.date_popup_custom = {};
Drupal.behaviors.date_popup_custom.attach = function(context, settings) {
// Add departure date same as arrival date
$('.form-item-d-departure-date').find('input').click(function() {
var arrival_date = $('.form-item-d-arrival-date').find('input').val();
$('.form-item-d-departure-date').find('input').datepicker( "setDate" , arrival_date );
});
};
@steffenr
steffenr / debug_views.php
Created August 28, 2013 15:22
Debugging views queries
<?php
function mymodule_views_pre_execute(&$view) {
switch ($view->name) {
case 'my_view_name':
dpq($view->build_info['query']);
break;
}
}
?>
// Set zoom for leaflet map on specific pages.
$(document).bind('leaflet.map', function(e, map, lMap) {
// Zoom out map on specific node pages.
if ($('body').hasClass('node-type-YOURNODETYPE')) {
lMap.setZoom(10);
}
});
<?php
/**
* Override variables used in views template for fields.
*
* @see views-view-fields.tpl.php
*/
function theme_preprocess_views_view_fields(&$vars) {
// Until http://drupal.org/node/939462 lands for Drupal 7 we need to specify
// the specific preprocess functions ourself.
$preprocess_names = array();
@steffenr
steffenr / node_export_import.php
Created July 3, 2013 08:52
Use node_export to import exported nodes in drupal
<?php
if (function_exists('node_export_import')) {
$path = '.' . base_path() . drupal_get_path('module', 'my_module');
$my_node = file_get_contents($path . '/my_module_exported.drupal');
node_export_import($my_node);
}
?>