Skip to content

Instantly share code, notes, and snippets.

View ChezFre's full-sized avatar

Chez Fre ChezFre

View GitHub Profile
@ChezFre
ChezFre / template.php
Created September 2, 2014 11:20
Replace node id with other field from referenced node
function Berghoff2014_form_alter(&$form, &$form_state, $form_id) {
if( $form_id === "webform_client_form_33" ) {
/**
** Replace NID from Agent with actual email **
**/
//$node_id = $form['submitted']['agent']['#value'];
$node_id = arg(1);
@ChezFre
ChezFre / steps
Created August 6, 2014 09:48
Show number of entities referencing this node in a view
Via http://drupal.stackexchange.com/questions/42352/display-number-of-times-content-is-referenced-in-content
This video series helped me an infinite amount: http://vimeo.com/33251051, http://vimeo.com/33252553.
Make sure Child has an entity reference to Parent.
Create a new view
In Filter Criteria, add a new Type (= Parent)
In Advanced>Other, set Aggregation to YES
In Advanced>Relationships, add a new relationship for "A bridge to the Content entity that is referencing Content via field_parent" where field_parent is your entity reference. Call this "Parents"
In Fields, add Content: Title and when prompted set its Aggregation type to Group results together
@ChezFre
ChezFre / node.tpl.php
Created August 4, 2014 08:01
Add flag to node template
// https://www.drupal.org/node/295383
<?php print flag_create_link('flag_machine_name', $node->nid); ?>
@ChezFre
ChezFre / config.js
Created July 21, 2014 18:49
CKeditor add html tags and attributes you don't want removed
// http://docs.ckeditor.com/#!/api/CKEDITOR.config-cfg-extraAllowedContent
// /admin/config/content/ckeditor/edit/Full
config.allowedContent = true;
config.extraAllowedContent = 'span';
config.removeFormatAttributes = 'align,hspace,valign'; // Defaults to: 'class,style,lang,width,height,align,hspace,valign'
@ChezFre
ChezFre / Drupal Views Export
Created July 20, 2014 15:44
Filter entity reference by current logged in user field
$view = new view();
$view->name = 'garages';
$view->description = '';
$view->tag = 'default';
$view->base_table = 'node';
$view->human_name = 'Garages';
$view->core = 7;
$view->api_version = '3.0';
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
@ChezFre
ChezFre / node.tpl.php
Last active August 29, 2015 14:03
Print field value in Drupal template
/*****************
** BAD PRACTICE **
*****************/
<img src="<?php print file_create_url($node->field_image['und'][0]['uri']); ?>" />
/*************
** USE THIS **
*************/
@ChezFre
ChezFre / template.php
Created July 8, 2014 11:28
Change language name to language code in Drupal language block
<?php
function Autostock2014_language_switch_links_alter(&$links, $type, $path) {
foreach ($links as &$language) {
$language['title'] = $language['language']->language;
}
}
@ChezFre
ChezFre / import.bash
Last active August 29, 2015 13:59
Import MySQL Database via CLI
mysql -u username -p database < file.sql
/*******
** OF **
*******/
mysql -u username -pPASSWORD
> source file.sql;
@ChezFre
ChezFre / template.php
Last active August 29, 2015 13:57
Make a webform submit via Ajax instead of going to a seperate page Doesn't work with Webform 4.x, only with 3.x
<?php
function hook_form_alter(&$form, &$form_state, $form_id) {
if($form_id == "webform_client_form_22") {
// get the nid so we can use it in the wrapper value
$nid = $form['#node']->nid;
// add the ajax properties to the submit button
$form['actions']['submit']['#ajax'] = array(
'callback' => 'hook_webform_js_submit', // update function
@ChezFre
ChezFre / template.php
Created March 21, 2014 21:20
Add placeholder to form elements in Drupal
/**
* $vars['#id''] = Form ID, can be found via Krumo
* $vars['field_name'] = Name of the input element you want to access
*/
function theme_form_alter(&$vars) {
//krumo($vars);
if( $vars['#id'] = " ") {