Skip to content

Instantly share code, notes, and snippets.

View MatthieuScarset's full-sized avatar
🤷‍♂️
Probably me

MattGyver MatthieuScarset

🤷‍♂️
Probably me
View GitHub Profile
@klaasvw
klaasvw / translation.migrate.php
Created October 17, 2012 08:52
Migrating translations using drupal migrate.
<?php
/**
* Migration class for migrating the source translations.
*/
class MySourceTranslationMigration extends Migration {
// Nothing special here. Just set up a node migration, migrating to nodes
// that will serve as translation sources.
// ...
@MatthieuScarset
MatthieuScarset / fixpermissions
Created July 19, 2018 02:36
Fix permissions on Docker-based env with Drupal
//Files should be `644` I think
find . -type f -exec chmod u=rw,g=r,o=r {} \;
// Folders should be `executable
find . -type d -exec chmod u=rwx,g=rx,o=rx {} \;
@jerbob92
jerbob92 / ImageRenderExampleBlockResponsive.php
Created October 28, 2015 13:22
Render responsive image into a block Drupal 8 Example
<?php
/**
* @file
* Contains Drupal\mymodule\Plugin\Block\ImageRenderExampleBlockResponsive.
*/
namespace Drupal\mymodule\Plugin\Block;
use Drupal\Core\Block\BlockBase;
@swichers
swichers / d7-add-entity-view-mode.md
Last active October 18, 2019 21:13
Drupal 7 - Programmatically add view mode to entity

In a module file:

This will enable an additional view mode for use on the specified entity type(s). Many examples will show the custom settings here being set to TRUE. If TRUE is used then that view mode is added to all entities of the specified type regardless of if it should be on the bundle or not.

/**
 * Implements hook_entity_info_alter().
 */
function HOOK_entity_info_alter(&$entity_info) {
@skwashd
skwashd / README.md
Last active May 27, 2020 07:24
Drupal git pre-commit hook

This pre-commit hook is designed to be used for Drupal 7 and 8 sites.

Download the pre-commit file. Save it as .git/hook/pre-commit in your git repo. You need to ensure that the file is executable.

If you want this to be added to all new projects automatically, add it to your git init templates.

To install and PHP CodeSniffer for Drupal, please read the official documentation.

To see this working checking out this short YouTube video.

@chrisjlee
chrisjlee / fix-permissions.sh
Created May 17, 2012 16:15
Permissions script for drupal - fixes the permissions of any drupal install automatically!
#!/bin/bash
# From: http://drupal.org/node/244924
path=${1%/}
user=${2}
group="www-data"
help="\nHelp: This script is used to fix permissions of a drupal installation\nyou need to provide the following arguments:\n\t 1) Path to your drupal installation\n\t 2) Username of the user that you want to give files/directories ownership\nNote: \"www-data\" (apache default) is assumed as the group the server is belonging to, if this is different you need to modify it manually by editing this script\n\nUsage: (sudo) bash ${0##*/} drupal_path user_name\n"
if [ -z "${path}" ] || [ ! -d "${path}/sites" ] || [ ! -f "${path}/modules/system/system.module" ]; then
echo "Please provide a valid drupal path"
echo -e $help
@MatthieuScarset
MatthieuScarset / reorder-form-actions.php
Created July 14, 2020 14:17
Drupal - Order array by another array
<?php
// Reorder actions.
$order = [
'previous',
'reset',
'submit',
'preview_next',
];
// Get element offset from top of page
function getOffset(el) {
el = el.getBoundingClientRect();
return {
left: el.left + window.scrollX,
top: el.top + window.scrollY
};
};
@DavidWittman
DavidWittman / merge-s3-parts.sh
Created December 23, 2015 16:47
Script to merge .part files from Amazon S3
#!/usr/bin/env bash
if [[ $# -ne 1 ]]; then
echo "Merge matching *.part files in a directory"
echo
echo "usage: $0 <directory>"
exit 1
fi
DIRECTORY="$1"
@MatthieuScarset
MatthieuScarset / entity_autocomplete_views.php
Created July 19, 2021 11:13
Drupal selection handlers views
$args = [];
$form['user_in_charge'] += [
'#title' => t('Entity autocomplete'),
'#type' => 'entity_autocomplete',
'#selection_handler' => 'views',
'#selection_settings' => [
'view' => [
'view_name' => 'view_machine_name',
'display_name' => 'entity_reference',