Skip to content

Instantly share code, notes, and snippets.

View pedrorocha-net's full-sized avatar

Pedro Rocha pedrorocha-net

  • Lisboa, Portugal
View GitHub Profile
@pedrorocha-net
pedrorocha-net / gist:4708132
Created February 4, 2013 17:23
Exemplo de Integração do módulo de Drupal http://drupal.org/project/pagseguro, para integrar ao PagSeguro puramente, sem estar dentro de um ecommerce
pagseguro_library_load();
$PagSeguroAPI = new PagSeguroAPI();
$payment_request = $PagSeguroAPI->createPaymentRequestObject();
$payment_request->setCurrency("BRL");
$payment_request->setReference($order_reference);
$payment_request->setSender($customer_name, $order->mail);
$payment_request->setRedirectUrl("http://example.com/pagseguro/return");
// Shipping rate is handled by Drupal
api = 2
core = 7.x
; Include the definition of how to build Drupal core directly, including patches.
includes[] = "drupal-org-core.make"
; Download the Commons install profile and recursively build all its dependencies.
projects[taz][type] = "profile"
projects[taz][download][type] = "git"
projects[taz][download][url] = "https://github.com/alexweber/Taz.git"
@pedrorocha-net
pedrorocha-net / MyPage.php
Last active August 14, 2016 22:06
Example of page route in Drupal, with the Cool module
<?php
namespace Drupal\my_page\PageControllers;
class MyPage implements \Drupal\cool\Controllers\PageController {
public static function accessCallback() {
return TRUE;
}
@pedrorocha-net
pedrorocha-net / NumberAbbrevFilter.coffee
Created October 29, 2014 18:47
Angular JS Filter for Number Abbreviation
"use strict"
@Application = angular.module("numberAbbrevFilter", [])
@Application.filter "numberAbbrev", ->
(number) ->
if number >= 10000000
return (number / 1000000).toFixed(0) + 'M'
@pedrorocha-net
pedrorocha-net / gulp-drupal-concat-js
Created February 4, 2015 16:14
Gulp task to concatenate all JS files from a Drupal website active modules with Gulp + Coffeescript + Drush
drush = require 'drush-node'
destinations =
js: 'assets/js'
gulp.task 'drupal-minifyjs', ->
drush.init()
.then () ->
drush.exec('php-eval "print realpath(\'.\')"')
.then (realpath) ->
@pedrorocha-net
pedrorocha-net / gist:f7fe05a018b8e1917577
Created March 2, 2015 11:14
Drupal Search module customisation to allow display priority settings for each content type (to allow showing certain types first in the default search module)
function HOOK_ranking() {
$rankings = array();
$types = node_type_get_types();
foreach ($types as $type) {
$rankings[$type->type . '_node_type_boost_search'] = array(
'title' => t('Boost "' . $type->name . '" nodes'),
'arguments' => array(':type' => $type->type),
'score' => ' FIND_IN_SET(n.type, :type)',
);
}
@pedrorocha-net
pedrorocha-net / gist:511d4fc33bc5f0eaee03
Created July 5, 2015 01:43
Fix videos data retrieve for Popcorn Time 0.3.7.2 for Mac
var Q = require('q'),
os = require('os'),
path = require('path'),
_ = require('underscore'),
data_path = require('nw.gui').App.dataPath;
/** Default settings **/
var Settings = {};
// User interface
@pedrorocha-net
pedrorocha-net / baseDefinitionApproach.php
Created August 16, 2015 20:26
Approach extending ContentEntityBase and using BaseFieldDefinition::create
public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
$fields['id'] = BaseFieldDefinition::create('integer')
->setLabel(t('ID'))
->setDescription(t('The ID of the Voting API Vote entity.'))
->setReadOnly(TRUE);
$fields['uuid'] = BaseFieldDefinition::create('uuid')
->setLabel(t('UUID'))
->setDescription(t('The UUID of the Voting API Vote entity.'))
@pedrorocha-net
pedrorocha-net / hook_schema.php
Created August 16, 2015 20:28
Approach using hook_schema (as on Drupal 7)
$schema['votingapi_vote'] = array(
'fields' => array(
'vote_id' => array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE),
'entity_type' => array('type' => 'varchar', 'length' => 64, 'not null' => TRUE, 'default' => 'node'),
'entity_id' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
'value' => array('type' => 'float', 'not null' => TRUE, 'default' => 0),
'value_type' => array('type' => 'varchar', 'length' => 64, 'not null' => TRUE, 'default' => 'percent'),
'tag' => array('type' => 'varchar', 'length' => 64, 'not null' => TRUE, 'default' => 'vote'),
'uid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
'timestamp' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
@pedrorocha-net
pedrorocha-net / mymodule.d7.password.php
Created November 11, 2015 21:49
Code to help migrate Drupal 7 users to Drupal 8
<?php
/**
* @file
* Secure password hashing functions for user authentication.
*
* Based on the Portable PHP password hashing framework.
* @see http://www.openwall.com/phpass/
*
* An alternative or custom version of this password hashing API may be