Skip to content

Instantly share code, notes, and snippets.

@driesd
Created August 29, 2013 12:16
Show Gist options
  • Save driesd/6377312 to your computer and use it in GitHub Desktop.
Save driesd/6377312 to your computer and use it in GitHub Desktop.
Processing fields
<?php
//NEEDED TO MAKE FIELD PROCESSING POSSIBLE PER FIELD
function mytheme_process_field(&$variables) {
$function = 'mytheme_process_field__'. $variables['element']['#field_name'];
if(function_exists($function)) {
$variables = $function($variables);
}
}
//EXAMPLE 1: WRAP A GOOGLE MAPS AROUND A CITY FIELD
function mytheme_process_field__field_city (&$variables) {
//IFRAME WITH ZOOM AND PAN CONTROLS
// $variables["items"][0]["#markup"] = '<iframe style="background-color: #f6f6f6;" width="425" height="350" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="https://maps.google.be/maps?f=q&amp;source=s_q&amp;hnear=' . $variables["items"][0]["#markup"] . '&amp;z=11&amp;hl=nl&amp;geocode=&amp;q=' . $variables["items"][0]["#markup"] . '&amp;t=v&amp;ie=UTF8&amp;hq=&amp;output=embed"></iframe>';
//STATIC MAP WITHOUT CONTROLS -> IMG
$variables["items"][0]["#markup"] = '<img src="http://maps.googleapis.com/maps/api/staticmap?center=' . $variables["items"][0]["#markup"] . '&zoom=11&format=png&sensor=false&size=640x320&maptype=roadmap" />';
return $variables;
}
//EXAMPLE 2: WRAP A YOUTUBE IFRAME PLAYER AROUND A YOUTUBE URL FIELD
function mytheme_process_field__field_youtube (&$variables) {
if($variables["items"][0]["#markup"]){
$variables["items"][0]["#markup"] = '<iframe width="560" height="315" src="http://www.youtube.com/embed/' . $variables["items"][0]["#markup"] . '" frameborder="0" allowfullscreen></iframe>';
}
return $variables;
}
//EXAMPLE 3: WRAP A GOOGLE MAPS AROUND AN ADDRESS FIELD
function mytheme_process_field__field_address (&$variables) {
$variables["items"][0]["#markup"] = '<iframe style="background-color: #f6f6f6;" width="425" height="350" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="https://maps.google.be/maps?f=q&amp;source=s_q&amp;hnear=' . $variables["items"][0]["#markup"] . '&amp;z=14&amp;hl=nl&amp;geocode=&amp;q=' . $variables["items"][0]["#markup"] . '&amp;t=v&amp;ie=UTF8&amp;hq=&amp;output=embed"></iframe>';
return $variables;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment