Skip to content

Instantly share code, notes, and snippets.

View e0ipso's full-sized avatar
🏠
Working from home

Mateu Aguiló Bosch e0ipso

🏠
Working from home
View GitHub Profile
@e0ipso
e0ipso / efq-is-null.php
Last active December 2, 2015 19:18
EntityFieldQuery IS NULL
<?php
$bundle = 'article';
$entity_type = 'node';
$field = 'body';
$column = 'value';
print init_query($entity_type, $bundle)
->count()
->execute() . ' entities.' . PHP_EOL;
@e0ipso
e0ipso / gist:6256142
Last active December 21, 2015 05:19
Use FBAutopost wrapper class to publish to the user's timeline (requires Facebook App approval).
<?php
try {
$fb = facebook_autopost();
$fb
->setDestination('me')
->publish(array(
'type' => 'status',
'params' => array('message' => t('Hello world.')),
));
}
@e0ipso
e0ipso / magic.php
Created September 13, 2013 09:33
Brief introduction to some OOP features present in PHP5.
<?php
/**
* A base class with getters and setters incorporated.
*/
class ObjectBase {
/**
* Setter function for a generic attribute.
*
* @param string $property_name
@e0ipso
e0ipso / drupal-reinstall.sh
Last active December 24, 2015 13:29
Shell alias to reinstall the current D8 site. Carefull! This will delete all your content and configuration and it's for core development purposes only. This alias is meant to be called from the Drupal root. This is a variation on http://alias.sh/drupal-install
# Add this to your .bash_profile / .bashrc / …
# Call this to reinstall a D8 development site.
function drupal-reinstall() {
pass=$(grep "'password' =>" sites/default/settings.php | grep -v '[\*#]'|sort|uniq|cut -f4 -d\');
username=$(grep "'username' =>" sites/default/settings.php | grep -v '[\*#]'|sort|uniq|cut -f4 -d\');
dbname=$(grep "'database' =>" sites/default/settings.php | grep -v '[\*#]'|sort|uniq|cut -f4 -d\');
sudo rm -rf sites/default;
sudo git checkout -- sites/default;
sudo chmod -R 777 sites/default;
@e0ipso
e0ipso / videos-aed-vimeo.md
Last active December 24, 2015 13:48
Lista de videos de Vimeo a incluir en el listado de la AED. Para una petición nueva se puede poner un comentario en este gist y actualizaré el contenido y la lista de la AED lo antes posible.
@e0ipso
e0ipso / field-contents.php
Last active December 27, 2015 16:58
Fetch field contents without loading whole entity.
<?php
/**
* Get the content of a field for a given array of entity ids. If the field
* contains multiple values for a given entity id, then only the latest is
* preserved.
*
* @param string $field_name
* The name of the field you need to retrieve.
* @param array $entity_ids
* An array containing the entity ids to look for.
@e0ipso
e0ipso / operations.drush.inc
Created November 29, 2013 09:01
Drush command to update your local environment syncing down the DB from a remote environment, running updates and reverting all features.
<?php
/**
* Implementation of hook_drush_command().
*/
function operations_drush_command() {
$items = array();
$items['local-update'] = array(
'description' => 'Downloads a dump of the remote database, suffixes that file with the current date and stores it in the selected location. After importing the database, it will run update hooks, revert all features, and clear cache.',
-- Select all media galleries and find all images in there that follow the path structure: public://images/%/%/%/%
SELECT n.nid, fmi.field_media_items_fid, file.uri
FROM
node n
INNER JOIN
field_data_field_media_items fmi ON fmi.entity_id = n.nid
INNER JOIN
file_managed file ON file.fid = fmi.field_media_items_fid
WHERE
n.type = 'media_gallery'
@e0ipso
e0ipso / gist:6256131
Last active January 14, 2016 08:36
Use FBAutopost wrapper class to publish to a fan page.
<?php
try {
$fb = facebook_autopost();
$fb
->setDestination($facebook_page_id)
->publish(array(
'type' => 'status',
'params' => array('message' => t('Hello world.')),
));
}
@e0ipso
e0ipso / PersistableCache.php
Last active June 16, 2016 09:13
Persistable cache
<?php
/**
* @file
* Contains \Drupal\restful\Util\PersistableCache.
*/
namespace Drupal\restful\Util;
class PersistableCache implements PersistableCacheInterface {