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 / EntityConverterField.php
Last active July 2, 2016 16:10
Support upcasting UUIDs into entities (/api/node/article/194e62d0-d3ac-4515-b067-df01cd9096ad for /api/node/article/{node})
<?php
namespace Drupal\jsonapi\ParamConverter;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\ParamConverter\EntityConverter;
use Drupal\Core\TypedData\TranslatableInterface;
use Symfony\Cmf\Component\Routing\RouteObjectInterface;
use Symfony\Component\Routing\Route;
@e0ipso
e0ipso / EntityConverterField.php
Created July 2, 2016 16:06
Support upcasting UUIDs into entities /api/node/article/194e62d0-d3ac-4515-b067-df01cd9096ad
<?php
namespace Drupal\jsonapi\ParamConverter;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\ParamConverter\EntityConverter;
use Drupal\Core\TypedData\TranslatableInterface;
use Symfony\Cmf\Component\Routing\RouteObjectInterface;
use Symfony\Component\Routing\Route;
@e0ipso
e0ipso / service-decorator.php
Created March 31, 2016 10:46
Swap out service for a decorator
<?php
/**
* @file
* Contains Drupal\my_module\MyModuleServiceProvider
*/
namespace Drupal\my_module;
use Drupal\Core\DependencyInjection\ContainerBuilder;
@e0ipso
e0ipso / read-only-property-es6.js
Last active March 16, 2024 21:09
Read only property ES6
/**
* Class that holds a read only property.
*/
class PropertyBag {
/**
* Accessor.
*
* @return {string}
* The value. This annotation can be used for type hinting purposes.
@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 / jsonapi-subrequest-write.md
Last active September 21, 2018 11:54
JSON API sub-request write operations

JSON API sub-request write operations

This extension allows you to alter or create the contents of the relationships of a resource with a single operation. In order to control how the relationships, and their relationships in turn, are affected by the request this extension reserves the keyword subrequest inside of the meta of any relationship. The contents of the subrequest property MUST be a request object.

The request object MUST NOT be present if the relationship item is not being altered or created via POST, PUT or PATCH.

@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 {
@e0ipso
e0ipso / compound-filter-ext.json-api.md
Last active August 29, 2015 15:39
JSON API compound filters extension

Relational filters JSON API extension

This extension provides documentation on how to filter based on relationships.

Given a requested resource (resource from now on) that contains several relationships (rel1, rel2, … from now on), you can apply filters on the resource based on conditions on rel1, rel2, … The default behavior is to filter the elements on resource, unless otherwise is specified.

The following request returns only the resource entities that contain a relationship that meets the filter:

GET /resource?filter[rel1.conditionField][value]=value1
@e0ipso
e0ipso / constants.php
Created February 20, 2015 15:12
About constant overrides and Late Static Binding
<?php
class A {
const C = 'Class A';
public static function constantSelf() {
print self::C . PHP_EOL;
}
@e0ipso
e0ipso / comparison.php
Created February 16, 2015 12:45
isset & array_key_exists
<?php
$array = array(
'foo' => 'bar',
'baz' => NULL,
);
print 'isset: ' . (isset($array['baz']) ? 'True' : 'False') . PHP_EOL;
print 'array_key_exists: ' . (array_key_exists('baz', $array) ? 'True' : 'False') . PHP_EOL;