Skip to content

Instantly share code, notes, and snippets.

@davidjguru
davidjguru / intro_drupal_truncate_watchdog_table_using_drush.md
Last active August 28, 2024 05:26
Drupal 8 || 9 : Truncate Watchdog table using Drush from a DDEV deploy.
@steffenr
steffenr / file_media_entity.php
Last active February 27, 2023 18:33
[Drupal 8] Create file/ media_entity programmatically
<?php
$filesystem = \Drupal::service('file_system');
// Create file entity.
$image = File::create();
$image->setFileUri($destination);
$image->setOwnerId(\Drupal::currentUser()->id());
$image->setMimeType('image/' . pathinfo($destination, PATHINFO_EXTENSION));
$image->setFileName($filesystem->basename($destination));
$image->setPermanent();
$image->save();
@simesy
simesy / EntityLookup.php
Last active March 27, 2018 03:07
Migrate process plugin: entity_lookup
<?php
/**
* @file
* Contains \Drupal\migrate_entity_lookup\Plugin\migrate\process\EntityLookup.
*/
namespace Drupal\migrate_entity_lookup\Plugin\migrate\process;
use Drupal\migrate\ProcessPluginBase;
@mankyKitty
mankyKitty / ViewsHandlersShakedown.md
Last active October 27, 2021 05:32
This is a cheat sheet for information about extending the capabilities of Views by extending and building your own handlers. It will cover the basic handlers and attempt to cover some of the hooks that you might use when doing so. Including examples, basic documentation and some caveats where necessary.THIS IS NOT A COMPLETE LIST!! Consider the …

#Views Handlers - A Shakedown

This is a cheat sheet for information about extending the capabilities of Views by extending and building your own handlers. It will cover the basic handlers and attempt to cover some of the hooks that you might use when doing so. Including examples, basic documentation and some caveats where necessary. THIS IS NOT A COMPLETE LIST!! Consider the code of the handler your looking to extend to be the ultimate source of documentation. This is merely a convenience and a starting point.

_Ignore the tags in the included snippets, they are a convenience for formatting.

Extending / Including Your Handler

  • Determine which handler you're going to extend. (eg views_handler_field_numeric).
  • Create a PHP .inc file using the class name of your handler: views_handler_field_my_numeric_field.inc.
@danreb
danreb / custompage.php
Created June 20, 2013 00:20
Using EntityFieldQuery() to get node type and display it on custom php page in Drupal 7
<?php
// Get path of Drupal install.
$drupal_path = $_SERVER['DOCUMENT_ROOT'];
// Defines our path to the Drupal install
define('DRUPAL_ROOT', $drupal_path);
// We need to load the bootstrap.inc file so we can have access to the drupal_bootsrap() function
require_once DRUPAL_ROOT . '/includes/bootstrap.inc';
@erin-dot-io
erin-dot-io / pixel-parity-rems.scss
Created March 27, 2013 20:38
Font-size pixel-parity REMs mixin for Sass/SCSS with legacy browser 'px' fallback. Neat!
// the mixin
@mixin font-size($size: 16) {
font-size: ($size) + px;
font-size: ($size / 16) + rem;
}
// example
h6 { @include font-size(11); }
@erin-dot-io
erin-dot-io / css-arrow.scss
Last active December 15, 2015 10:39
A little mixin I built for easily creating css arrows in sass/scss using psuedo-classes. Demo: http://codepen.io/erinautomatic/pen/BLFqe
// The mixin
@mixin css-arrow($box-edge : bottom,
$edge-side : center,
$arrow-size : 10px,
$edge-side-offset : 0,
$fill-color : black,
$border-color : none,
$border-style : border) {
@MattFielding
MattFielding / style.css
Created February 11, 2013 14:14
Responsive images in Drupal. The height and width attributes need removing from the <img> elements and we need to add a little CSS to allow the images to scale correctly
img {
max-width:100%;
height:auto;
}
@robballou
robballou / closures.js
Created December 17, 2012 15:39
Code from my JavaScript Best Practices from AtenCamp 2012
// closures
(function($, Drupal, drupalSettings) {
var snow_base = 10;
Drupal.behaviors.snowman = {
attach: function() {
// can access $, Drupal, drupalSettings
}