Skip to content

Instantly share code, notes, and snippets.

View renebakx's full-sized avatar

René Bakx renebakx

View GitHub Profile
<?php
// build from drupal_get_query_parameters();
$filterQuery = array('news', 'blog', 'article');
// build query
$query = new EntityFieldQuery();
$query->entityCondition('entity_type', 'node');
$query->propertyCondition('type', 'page');
$query->propertyCondition('status', 1);
$query->fieldCondition('field_page_type', 'value', $filterQuery, 'in');
$query->propertyOrderBy('title', 'ASC');
@renebakx
renebakx / use set instead of macro
Created February 19, 2015 10:29
twig set block
{# If creating a responsive theme, you sometimes need to duplicate content in a template and a macro can be an option but sometimes the overhead is to much #}
{% set loginblock %}
<li><a href="{{ url('login') }}">Log in</a></li>
<li><a href="{{ url('signup') }}">Sign up</a></li>
{% endset %}
... more html...
<ul class="nav nav-secondary">
@renebakx
renebakx / views-view-unformatted.tpl.twig
Created July 10, 2015 14:03
Splitting view rows in upcoming and recent on a date without creating a viewspluging
{% for index,rawdata in view.result %}
{% set row_date = rawdata.field_field_conference_date[0]['raw']['value'] %}
{% set upcoming = false %}
{% set recent = false %}
{% if date(row_date) > date() %}
{% if not upcoming %}
<small>{{ 'Upcoming'|t }}</small>
{% set upcoming = true %}
{% endif %}
{% else %}
@renebakx
renebakx / mongo.sh
Created November 20, 2011 11:24
starting mongo on OSX
#!/bin/bash
#MongoDB startup script with status and proper lockfile removing
#Version 1.0.1 20-nov-2011 Rene Bakx (rene@71media.net)
#Created on OS-X 10.7 but should work on other versions
if [ -z $1 ] ; then
echo "Usage: $0 [start|stop|restart|status] "
exit 1
@renebakx
renebakx / bash_profile
Created February 8, 2016 09:29
PHP 5 and 7 with MAMP
export PHP7=1; // on opening your terminal
// Goes in your ~/.bash_profile
if [ -z "$PHP7" ]; then
export DRUSH_PHP='/Applications/MAMP/bin/php/php7.0.0/bin/php'
export PATH=/Applications/MAMP/Library/bin/:/Applications/MAMP/bin/php/php7.0.0/bin/:~/bin:$JAVA_HOME/bin:$PATH
else
export DRUSH_PHP='/Applications/MAMP/bin/php/php5.5.26/bin/php'
export PATH=/Applications/MAMP/Library/bin/:/Applications/MAMP/bin/php/php5.5.26/bin/:~/bin:$JAVA_HOME/bin:$PATH
fi
@renebakx
renebakx / ajax_response.md
Last active February 18, 2016 09:35
A very basic Drupal 8 AJAX repsonse

router.yml :

simple_twitter.ajax_controller_get_tweets:
  path: '_simple_twitter/tweets/{name}/{number}'
  defaults:
    _controller: '\Drupal\simple_twitter\Controller\AjaxController::getTweetsForUserAction'
    _title: 'getTweetsForUser'
 requirements:
@renebakx
renebakx / cruftless.info.yml
Created October 20, 2016 14:59
cruftless Drupal 8 Theme
name: Cruftless
type: theme
description: Cruftless is Stable without libraries
package: BadIdeas
core: 8.x
base theme: false
regions:
header: Header
content: Content
footer: Footer
@renebakx
renebakx / hideme.twig
Created February 16, 2017 10:10
twig trick to hide content without marking it as a comment {# #}
Sometimes you need to implement HTML from a style guide, but commenting out the whole block with {# #} makes it unreadable.
This little 'trick' let's your editor do proper syntax highlighting without showing the HTML in your output
{% if false == true %}
<div class="form-column">
<label for="upload">Your Resumé</label>
<div class="file-upload-field">
<div class="name-display">
<svg class="icon icon-check"><use xlink:href="#icon-check"></use></svg>
@renebakx
renebakx / macro_split.tpl.twig
Last active May 4, 2017 10:02
Split a string into two colors
{% macro split_title(text) %}
{% set text = render(text) %} {# only when doing twig for drupal 7 #}
{% set chunks = text|split('~') %}
{% for chunk in chunks %}
{{ (loop.index0 is odd)?"<em>"~chunk~"</em>":chunk}}
{% endfor %}
{% endmacro %}
<h3>{{ split_title('This is a ~text~ with some ~colors~') }}</h3>
@renebakx
renebakx / geocoder.module
Created September 20, 2017 08:31
quick geocoder in D8
<?php
function geocoder_entity_presave(Drupal\Core\Entity\EntityInterface $entity) {
if ($entity->getEntityTypeId() == 'node' && $entity->bundle() == 'distributor'){
$street = $entity->get('field_street')->getString();
$city = $entity->get('field_city')->getString();
$country = $entity->get('field_country')->getString();
$adress = sprintf('%s, %s, %s',$street,$city,$country);
$geocode = new Geocode();