Skip to content

Instantly share code, notes, and snippets.

View samuelsolis's full-sized avatar

Samuel samuelsolis

View GitHub Profile
@samuelsolis
samuelsolis / drupalphpheader.module
Last active December 26, 2016 12:01
Add custom php header to a drupal 7 view
function MYMODULE_views_pre_view(&$view, &$display_id, &$args){
if ($view->name == 'VIEWNAME' && $display_id == 'DISPLAYNAME'){
$header = 'MYCODE';
$options = array(
'empty' => 1,
'content' => $header,
'label' => NULL,
);
$view->add_item('DISPLAYNAME', 'header', 'views','area_text_custom', $options);
}
@samuelsolis
samuelsolis / default.aliases.drushrc.php
Last active August 29, 2015 13:57
Drupal drushrc example file
$aliases['pro'] = array (
'uri' => 'SITEURL',
'root' => 'Folder in the server',
'remote-host' => 'remote host',
'remote-user' => 'remote user',
'command-specific' => array(
'sql-sync' => array(
'no-cache' => TRUE,
),
'rsync' => array (
@samuelsolis
samuelsolis / mymodule.module
Created April 8, 2014 09:22
Preprocess field in Display Suite module, Drupal 7 example.
/*
* Before this, you have to create a "Preproces field" with name like "mycustomfield".
* In this example we render an user image (a image field, not the user picture).
*
*/
function MYMODULE_preprocess_comment(&$vars){
$author= user_load($vars['user']->uid);
$settings= array('settings' => array('image_style' => 'thumbnail'),'label' => 'hidden' );
$vars['mycustomfield'] = render(field_view_field('user', $author, 'field_user_main_image', $settings));
}
export GIT_PS1_SHOWDIRTYSTATE=true
export GIT_PS1_SHOWUNTRACKEDFILES=true
export GIT_PS1_SHOWSTASHSTATE=true
export PS1='\[\033[1;34m\]\u\[\033[0;30m\]@\[\033[0;32m\]\w\[\033[0;30m\]$(__git_ps1 " [\[\e[31;1m\]%s\[\e[0m\]]")\$ '
@samuelsolis
samuelsolis / mail_customization.module
Last active August 29, 2015 14:13
Add param to drupal mail links for tracking with Google Analytics
<?php
function mail_customization_mail_alter(&$message){
$preg = '/((https?:\/\/)([\da-z\.-]+)\.?([a-z\.]{2,6})?([\/\w \.-]*)*\/?(\?([A-Za-z0-9=&])*)?)/';
foreach($message['body'] as $key=>$body){
preg_match($preg , $body, $matches);
if (!empty($matches[0])){
$url = $matches[0];
@samuelsolis
samuelsolis / git alias
Last active August 4, 2017 11:50
Git alias
git config --global alias.st status
git config --global alias.logf 'log --pretty=format:"%C(yellow)%h%Cred%d\\ %Creset%s%Cblue\\ [%cn]" --decorate --numstat'
git config --global alias.ld 'log --pretty=format:"%C(yellow)%h\\ %ad%Cred%d\\ %Creset%s%Cblue\\ [%cn]" --decorate --date=relative'
git config --global alias.logv 'log --graph --full-history --all --color --pretty=format:"%x1b[31m%h%x09%x1b[32m%d%x1b[0m%x20%s"'
git config --global alias.logb 'log --graph --full-history --color --pretty=format:"%x1b[31m%h%x09%x1b[32m%d%x1b[0m%x20%s"'
@samuelsolis
samuelsolis / tinymc.pluggins.js
Created February 3, 2016 12:50
Custom tinyMCE buttons
(function() {
tinymce.PluginManager.add('stylebuttons', function(editor, url) {
/**
* Uppercase & bold button.
*/
editor.addButton('stylebuttons', {
text: 'Resalt',
tooltip: 'Uppercase and bold at time.',
icon: true,
image: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAABiklEQVQ4T52TvUoDQRDHZ/ZEtMgpvoBYaBvyAOKRSuGyJkV6QUgULARbg4g+gKDGECx8A3NLIFqo5wsoYuFHIT6B6KXJmWRH9rg7jnhJxG2WnZn/b3ZmZxF6Fuc8RaQVESktpZxWbsbgHQCvpWSVev38ISrB4JDP58ddt30IAKu90MiZiLDabE5s2vZZS9k9gC++BID5AeKIS946ztSigngAzrOnQzLHcKkihLWOqmYAdtcnc8m378URpMQUZjK5CiIVYwJKQtT2/RtuA8AvCCKUkfPsKwDM9gBCcWDnPBsDoWc0Te4yxkYjgF3H+fQy27bdUbthGCNq1/VJBdmJxLpxgNAvRC1oMvXpkaua+ALA5uIChgGIuk/I+fIJAK79BwAAR2iauSRjdB8MVRQ05AaESEmvxgFPOWiqj4WwNjyAYayM6frHBQBb+MsoE+FNp9NaajQabviZFCSR+DpApEJcOT6YAKjcbn9vKXH4maJZVU80jQpElAbAGeUj6r4haleIVLUs6zEa/wMGdqGMo9K2vQAAAABJRU5ErkJggg==',
@samuelsolis
samuelsolis / remove_duplicate_menu_links.sql
Created March 28, 2016 14:03
Remove duplicate item menu links in Drupal.
@samuelsolis
samuelsolis / Form.php
Last active October 26, 2022 18:52
Change Field value in drupal 8 form with Ajax
<?php
/**
* Form controller for the bb_report entity edit forms.
*
* @ingroup report
*/
class FeeForm extends ContentEntityForm {
/**
* {@inheritdoc}
@samuelsolis
samuelsolis / example.php
Created February 7, 2018 08:15
Drupal 8 custom entity without bundle
<?php
/**
* @file
* Contains \Drupal\example\Entity\Example.
*/
namespace Drupal\example\Entity;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Field\BaseFieldDefinition;