Skip to content

Instantly share code, notes, and snippets.

View nickopris's full-sized avatar

Nick Opris nickopris

  • London, UK
View GitHub Profile
insurec.services.yml
services:
insurec.event_subscriber:
class: Drupal\insurec\EventSubscriber\InsurecSubscriber
tags:
- { name: 'event_subscriber' }
insurec/src/EventSubscriber/InsurecSubscriber.php
@nickopris
nickopris / Drupal impersonate
Last active August 29, 2015 14:03
Allow to impersonate as an user account based on information from a content type.
/**
* Allow Masquerade role users to impersonate Role1 or Role2 accounts.
* Note that these users will never see their own account for editing or otherwise.
* As soon as they log in they will act on behalf of the account
* that we specify they can masquerade as.
*
* Only administrators should be able to control the list of users
* allowed to masquerade.
*
* @param $edit
@nickopris
nickopris / commerce_new_profile
Created June 6, 2014 10:11
Commerce new profile
$type = 'billing';
$new_profile = commerce_customer_profile_new($type);
$address[] = array(
'country' => 'GB',
'administrative_area' => 'county',
'sub_administrative_area' => '',
'locality' => 'London',
'dependent_locality' => '',
'postal_code' => 'XX 111',
@nickopris
nickopris / add_taxonomy_d7.php
Created May 16, 2014 09:40
Drupal 7 taxonomy vocabulary, terms and fields
<?php
// Create new vocabulary
$vo = new stdClass();
$vo->name = "AAA";
$vo->machine_name = "aaa";
taxonomy_vocabulary_save($vo);
// Create field in db
if(!db_table_exists('field_data_field_id_on_hub')) {
$field = array(
@nickopris
nickopris / db_query_result_to_csv
Created April 7, 2014 10:20
From db_query result to csv in Drupal
// Add Headers
drupal_add_http_header('Content-Type', 'text/csv');
drupal_add_http_header('Content-Disposition', 'attachment;filename=name_your_file.csv');
$fp = fopen('php://output', 'w');
$first = TRUE;
foreach ($results as $line) {
//Gets the line so we can flip it and get the column names
$column_names = get_object_vars($line);