Created
August 29, 2013 12:16
-
-
Save driesd/6377312 to your computer and use it in GitHub Desktop.
Processing fields
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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&source=s_q&hnear=' . $variables["items"][0]["#markup"] . '&z=11&hl=nl&geocode=&q=' . $variables["items"][0]["#markup"] . '&t=v&ie=UTF8&hq=&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&source=s_q&hnear=' . $variables["items"][0]["#markup"] . '&z=14&hl=nl&geocode=&q=' . $variables["items"][0]["#markup"] . '&t=v&ie=UTF8&hq=&output=embed"></iframe>'; | |
return $variables; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment