Skip to content

Instantly share code, notes, and snippets.

@jackfoust
jackfoust / Drupal Entity Field Export
Last active August 29, 2015 14:08
#drupal Entity export. Useful in hook_install() and hook_uninstall(). Drupal 7
<?php
/**
* @file
* Export serialized data containing fields attached to an Entity. Example used when Features not installed.
*/
function MODULE_NAME_install() {
drupal_install_schema(SCHEMA_NAME);
MODULE_NAME_add_entity_fields();
@jackfoust
jackfoust / Feeds Importer Plugin
Last active August 29, 2015 14:08
#drupal Sample plugin for Feeds Importer module.Drupal 7
<?php
/**
* @file
* Creates a plugin that in this example was used in the Feeds Importer module. Plugin can execute PHP against values passed to it.
*/
$plugin = array(
'form' => 'MODULE_NAME_PLUGIN_NAME_form',
// Optional validation callback.
'validate' => 'MODULE_NAME_PLUGIN_NAME__validate',
@jackfoust
jackfoust / Form and Block Render Example
Last active August 29, 2015 14:08
#drupal Form and Block Render to display site alert message. Drupal 7
<?php
/**
* @file
* Create form for alert message entry and render a block with message if message is not empty. Blocked place in header in this example with custom CSS.
*/
/**
* Implements hook_menu().
*/
@jackfoust
jackfoust / Custom Token
Last active August 29, 2015 14:08
#drupal Custom Token. Drupal 7
<?php
/**
* @file
* Creates a custom token. In this case this token was sent to Google Analytics.
*/
function example_token_info() {
$info['tokens']['site']['active_alert'] = array(
'name' => t('Active Alert'),
@jackfoust
jackfoust / Drupal Blocks with Mobile Detect
Created October 30, 2014 02:27
#drupal Experimental Block Rendering by Device. Drupal 7
<?php
/**
* @file
* A test case for adding visibility settings of Desktop, Tablet and Mobile to Drupal block rendering. Dropped instead for Context + Mobile Detect Library
*/
define('MOBILE_DETECT_LIBRARY_PATH', '/sites/all/libraries/Mobile_Detect');
/**
* Implements hook_form_alter().
@jackfoust
jackfoust / Drupal Form API + WYSIWYG
Created January 23, 2015 23:21
WYSIWYG with Drupal Form API
<?php
$defaults = array(
'value' => '',
'format' => filter_default_format(),
);
$example = variable_get('example_variable', $defaults);
$form_['example'] = array(
'#title' => t(''),
'#type' => 'text_format',
@jackfoust
jackfoust / iwlist
Created July 19, 2015 13:53
find channels local wifi utilizing
sudo iwlist wlan0 scan | grep \(Channel
@jackfoust
jackfoust / .htaccess
Last active November 4, 2015 14:20
Drupal 7.40 .htaccess change
# ADD TO END OF FILE
# Add headers to all responses.
<IfModule mod_headers.c>
# Disable content sniffing, since it's an attack vector.
Header always set X-Content-Type-Options nosniff
</IfModule>
@jackfoust
jackfoust / settings.php
Last active November 4, 2015 14:20
Drupal 7.40 settings.php changes.
# DIFF REPLACE
-$conf['404_fast_paths_exclude'] = '/\/(?:styles)\//';
+$conf['404_fast_paths_exclude'] = '/\/(?:styles)|(?:system\/files)\//';
# ADD TO END OF FILE
/**
* Theme debugging:
*
* When debugging is enabled:
@jackfoust
jackfoust / Sanitize_Target_Blank.htm
Created August 30, 2017 19:45 — forked from JamoCA/Sanitize_Target_Blank.htm
Use jQuery to automatically add noopener, noreferrer and nofollow to links w/target="_blank".
<cfcontent type="text/html; charset=UTF-8">
<!doctype html>
<html lang="en">
<head>
<title>Sanitize target="_blank"</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.slim.min.js" type="text/javascript"></script>
<script type="text/javascript">
/* 3/24/2017 Sanitize_Target_Blank.htm https://gist.github.com/JamoCA/80f65eb07f054b1326221bd4f15868d6 */
function sanitizeTargetBlank(){
$('#linkDiv a[rel~=external]').prop('target', '_blank');