Skip to content

Instantly share code, notes, and snippets.

View jasonglisson's full-sized avatar

Jason Glisson jasonglisson

View GitHub Profile
@jasonglisson
jasonglisson / entity_reference
Last active September 14, 2017 12:39
Drupal 7 - Directions for Entity Reference Field for Views
What you could do is create an entity reference list from a view and populate your widget with the view.
Create a new view Untick Create a block and Create a page Then click continue and edit. That should get you to the master view.
Click Add to add a new display and choose entity reference. Give your display a easily recognisable name. Add your fields/ filters etc and order them as required. I usually change the items to display under pager to display all items, but I'm not sure how required this is.
Under the Format heading beside Format, click settings and set your field(s) that are to be searched when auto-completing. Under the Format heading beside Show, click settings and set your fields to be inline. Save your view.
Now head over to edit your entity reference field. Assuming you already have your field pretty much set up the only bit you might need to change is under: Entity selection mode Choose: "Views: Filter by an entity reference view" Assuming your field reference target type and view list ma
<meta name="viewport" content="width=device-width, initial-scale=1">
@jasonglisson
jasonglisson / html_module_text
Last active September 14, 2017 12:39
Drupal 7: Module text html field
$levels_value = variable_get('levels_text', array('value' => '', 'format' => NULL));
$form['levels']['levels_text'] = array(
'#type' => 'text_format',
'#title' => t('Levels Text'),
'#size' => 30,
'#required' => FALSE,
'#default_value' => $levels_value['value'],
@jasonglisson
jasonglisson / node_type_page.php
Last active September 14, 2017 12:39
Drupal 7: Page template hook for content type
<?php
/**
* Variables preprocess function for the "page" theming hook.
*/
function THEME_NAME_preprocess_page(&$vars) {
// Do we have a node?
if (isset($vars['node'])) {
// Ref suggestions cuz it's stupid long.
@jasonglisson
jasonglisson / date_convert.php
Last active September 14, 2017 12:39
Convert date into new format
$originalDate = "2010-03-21";
$newDate = date("d-m-Y", strtotime($originalDate));
@jasonglisson
jasonglisson / uri_file_path.php
Last active September 14, 2017 12:39
Drupal 7 - Turn uri file path into url
<img src="<?php
$url = file_create_url($node->field_newsletter_cover['und'][0]['uri']);
$url = parse_url($url);
$path = $url['path'];
print $path; ?>">
@jasonglisson
jasonglisson / json_api.php
Last active September 14, 2017 12:39
This is an example of json api connection with PHP
<?php
$apikey = 'insert_your_api_key_here';
$q = urlencode('Toy Story'); // make sure to url encode an query parameters
// construct the query with our apikey and the query we want to make
$endpoint = 'http://api.rottentomatoes.com/api/public/v1.0/movies.json?apikey=' . $apikey . '&q=' . $q;
// setup curl to make a call to the endpoint
$session = curl_init($endpoint);
@jasonglisson
jasonglisson / modal_window.php
Last active September 14, 2017 12:39
Video Modal WIndow
<div class="featured-video-wrap" style="display:none;">
<div class="close-video">Close</div>
<?php if (strpos($video_url, 'vimeo') !== FALSE) {
$id = substr($video_url, strrpos($video_url, '/') + 1);?>
<iframe src="https://player.vimeo.com/video/<?php print $id; ?>" width="560" height="315" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>
<?php } elseif(strpos($video_url, 'watch') !== FALSE) {
$id = substr($video_url, strrpos($video_url, '=') + 1);?>
<iframe width="560" height="315" src="https://www.youtube.com/embed/<?php print $id; ?>" frameborder="0" allowfullscreen></iframe>
<?php } elseif(strpos($video_url, 'youtu.be') !== FALSE) {
$id = substr($video_url, strrpos($video_url, '/') + 1);?>
@jasonglisson
jasonglisson / target_text.js
Last active September 14, 2017 12:39
Target text without container
$('.mailchimp-signup-subscribe-form div:first-of-type').contents().filter(function() {
return this.nodeType === 3;
}).wrap('<p class="description"></p>').end().filter( "br" ).remove();
@jasonglisson
jasonglisson / theme_path.php
Last active September 14, 2017 12:39
Drupal theme path - Drupal add JS
drupal_add_js(drupal_get_path('theme', 'YOUR-THEME-NAME-HERE') .'/library/js/mailchimp.js')