Skip to content

Instantly share code, notes, and snippets.

Avatar
🏕️
Into the woods!

Mark Carver markcarver

🏕️
Into the woods!
View GitHub Profile
@markcarver
markcarver / page.tpl.php
Created Nov 23, 2011
Replaceable Image Theme Settings
View page.tpl.php
<?php
/**************
* IMPORTANT:
* Place these styles in your page.tpl.php file to override the style.css.
* You will need to make sure they match your themes selectors.
**************/
?>
<style type="text/css" media="all">
#page{
background-attachment:<?php print $background_image_attachment; ?>;
@markcarver
markcarver / 1-template.php
Created Nov 5, 2012
Drupal 7 - Converting a Views Unformatted List Into Columns
View 1-template.php
<?php
/**
* Implements hook_preprocess_views_view_unformatted().
*/
function YOUR_THEME_preprocess_views_view_unformatted(&$variables) {
// Determine if this view's content should render in columns.
// @see: _YOUR_THEME_views_columns();
_YOUR_THEME_views_columns($variables, array(
'articles|page' => 2,
@markcarver
markcarver / gist:5249012
Last active Mar 11, 2016
Redirect local sand-boxed Drupal file requests to a development server. This helps avoid having to sync (sometimes, very huge) file structures onto your local machine.
View gist:5249012
### Apache Rewrite
# Request resides in your 'sites/default/files' folder.
RewriteCond %{REQUEST_URI} ^/sites/default/files/(.*)$
# File doesn't exist.
RewriteCond %{REQUEST_FILENAME} !-f
# Directory doesn't exist.
RewriteCond %{REQUEST_FILENAME} !-d
# Redirect request to your development or production server.
RewriteRule ^/sites/default/files/(.*)$ http://dev.example.com/sites/default/files/$1 [L]
@markcarver
markcarver / d8-reset.sh
Created Jul 21, 2013
Deletes settings.php, removes the php config dir, drops and creates the database table.
View d8-reset.sh
#!/bin/bash
sudo rm -rf /sandbox/sites/d8.sandbox/sites/default/settings.php;
sudo rm -rf /sandbox/sites/d8.sandbox/sites/default/files/php/;
mysql -u root -proot -e 'DROP DATABASE `d8.sandbox`; CREATE DATABASE `d8.sandbox`;'
@markcarver
markcarver / perm.sh
Created Jul 21, 2013
Change the ownership settings according to how your www environment is setup.
View perm.sh
#!/bin/bash
echo 'Setting ownership to _www:staff ...';
sudo chown -R _www:staff ./;
echo 'Setting directory permissions to 0755 ...';
sudo find . -type d -exec chmod u=rwx,g=rwx,o=rx '{}' \;
echo 'Setting file permissions to 0644 ...';
sudo find . -type f -exec chmod u=rw,g=rw,o=r '{}' \;
View module.module
<?php
function MODULE_form_alter(&$form, $form_state, $form_id) {
if (!empty($form['#node'] && !empty($form['#node_edit_form'])) {
$node = $form['#node'];
$action = in_array('add', args()) ? t('Create new') : t('Edit existing');
switch ($node->type) {
case 'article': drupal_set_title(t('!action basic article', array('!action' => $action))); break;
case 'blog': drupal_set_title(t('!action blog article', array('!action' => $action))); break;
case 'audio': drupal_set_title(t('!action audio conent', array('!action' => $action))); break;
@markcarver
markcarver / theme.php
Last active Dec 20, 2015
Here's my "vision" on seeing the potential of what the theme system _could_ be.
View theme.php
<?php
// We implment something like hook_element_info() for themes.
// In theory, this identical to hook_theme(), but doesn't require
// a registry.
function system_theme_info() {
$info['foo_bar'] = array(
'variables' => array('title' => NULL, 'content' => NULL),
'context' => array('conditional_switch' => FALSE),
// Blah blah blah, rest of hook code.
@markcarver
markcarver / post-commit
Last active Dec 22, 2015
Drupal project post commit (copies thanks and commit link to pasteboard). Follow instructions at https://coderwall.com/p/jp7d5q
View post-commit
#!/bin/sh
# Ensure repo is hosted on drupal.org.
repoRemote=`git remote -v | grep push | perl -lne 'print $& if /git\.drupal\.org[:\/]project\/[^.]*/'`;
if [ ! -z "${repoRemote}" ]; then
# Extract the project and commit info.
project=`echo "${repoRemote}" | sed -e 's/git\.drupal\.org[:\/]//'`;
commitHash=`git log -n 1 --pretty=format:"%h"`;
commitName=`git log -n 1 --pretty=format:"%cn"`;
commitMessage=`git log -n 1 --pretty=format:"%B"`;
View theme.php
<?php
return array(
'#theme' => 'table__forum_list',
'#theme_wrappers' => array('container__suggestion'),
'#attributes' => array(
'class' => array('extra-class', 'even-more-classes'),
'id' => 'i-am-unique',
'data-toggle' => 'tooltip',
),
View 1-issue.comments.alter.js
/**
* THIS FILE ALTERS ANY ISSUE WITH THE NEW STYLING. IT AUTOMATICALLY INCLUDES THE CSS FILE
* BELOW. JUST COPY AND PASTE THIS IN YOUR INSPECTOR CONSOLE.
**/
(function ($) {
var localStorageSupported = false;
var enableTimeago = false;
// Only enable timago if user's browser has localStorage support (so they can
// double click to enable and disable at will).
if (typeof window.localStorage !== 'undefined') {
You can’t perform that action at this time.