Skip to content

Instantly share code, notes, and snippets.

View klaasvw's full-sized avatar

Klaas Van Waesberghe klaasvw

View GitHub Profile
@klaasvw
klaasvw / create-node-translation.php
Created November 9, 2012 09:04
Programmatically creating node translations in drupa.
<?php
/**
* @file translates a node programmatically.
* To translate a node programmatically the following properties need to be set:
* - tnid: the nid of node that is being translated.
* - translation_source: the node object that is being translated.
*
* The translation_source property makes sure that the source's tnid will get
* set to its own nid if not done already.
*/
@klaasvw
klaasvw / gist:5704830
Created June 4, 2013 09:46
Install a different version of a gem from a git repository.gem install specific_install
gem install specific_install
gem specific_install git://github.com/Crosscheck/didi.git
@klaasvw
klaasvw / gist:6435358
Created September 4, 2013 10:37
Programmatically change drupal facetapi block titles.
<?php
if (module_exists('facetapi')) {
$searcher = 'search_api@default_node_index';
$realm = 'block';
$titles = array(
'type' => 'Filter on content',
);
// Change the titles of the corresponding blocks.
@klaasvw
klaasvw / migration.inc
Created September 26, 2013 12:58
Importing media files with migrate
<?php
/**
* @file
* Base Migrations for resource nodes.
*/
class ImportResourceNodes extends ImportNodeAdvanced {
public function __construct() {
@klaasvw
klaasvw / your_module.module
Created October 10, 2013 10:28
Fix missing addthis toolbox buttons
<?php
/**
* Implements hook_addthis_markup_alter().
*
* Fix addthis bug where services aren't added.
*/
function your_module_addthis_markup_alter(&$markup) {
if (isset($markup['#display']['type']) && $markup['#display']['type'] == 'addthis_basic_toolbox') {
$addthis_services = array_filter(variable_get('addthis_enabled_services', array()));
@klaasvw
klaasvw / your_module.pages_default.inc
Created October 13, 2013 10:38
Export custom variants for existing page manager pages. This allows you to for example export a custom version of the user_view page.
<?php
/**
* @file
* Default page manager content.
*/
/**
* Implements hook_default_page_manager_handlers().
*/
@klaasvw
klaasvw / download.php
Last active December 6, 2020 08:28
Download file in Drupal using Guzzle
<?php
$external_file = 'https://www.example.com/test.png'
$destination = 'public://file.png';
$response = \Drupal::httpClient()->get($external_file, ['sink' => $destination]);
@klaasvw
klaasvw / stripscheme.php
Created December 6, 2020 08:44
Remove or strip the scheme from a file stream wrapper in Drupal 9
<?php
$uri = 'public://path/to/file.txt';
/** @var \Drupal\Core\StreamWrapper\StreamWrapperManagerInterface $stream_wrapper_manager */
$stream_wrapper_manager = \Drupal::service('stream_wrapper_manager');
$target = $stream_wrapper_manager->getTarget($uri);
// $target = 'path/to/file.txt';
@klaasvw
klaasvw / getscheme.php
Created December 6, 2020 08:46
Get scheme from URI in Drupal 9
<?php
$uri = 'public://path/to/file.txt';
/** @var \Drupal\Core\StreamWrapper\StreamWrapperManagerInterface $stream_wrapper_manager */
$stream_wrapper_manager = \Drupal::service('stream_wrapper_manager');
$scheme = $stream_wrapper_manager->getScheme($uri);
// $scheme = 'public';
@klaasvw
klaasvw / composer.json
Created October 15, 2021 11:45
Use Drupal issue fork in composer
‎‎​