Skip to content

Instantly share code, notes, and snippets.

View colorfield's full-sized avatar

Christophe Jossart colorfield

View GitHub Profile
@colorfield
colorfield / NodeEntityController.php
Last active March 24, 2017 09:41
Drupal 8 EntityController
<?php
namespace Drupal\my_module\Controller;
use Drupal\Core\Controller\ControllerBase;
use Drupal\node\Entity\Node;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Core\Entity\EntityTypeManager;
use Drupal\Core\Entity\Query\QueryFactory;
use Drupal\Core\Render\Renderer;
@colorfield
colorfield / BatchController.php
Last active April 18, 2016 16:21
Drupal 8 batch opertation
<?php
namespace Drupal\my_module\Controller;
use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\Url;
class BatchProcessController extends ControllerBase
{
const OPERATION_CREATE = 0;
@colorfield
colorfield / drupal-image.php
Last active September 10, 2018 08:04
Drupal 7 and 8 theme image
<?php
/**
* Drupal 7
*/
$fid = 1;
$uri = file_load($fid)->uri; // or fetched via the uri property of a field
$image_url = image_style_url('thumbnail', $uri);
$image = theme_image(array(
'path' => $image_url,
@colorfield
colorfield / debug.php
Created February 26, 2016 16:12
Override php.ini for debug on dev environment
<?php
// place this in a global script like settings.php in Drupal
ini_set("display_errors", 1);
ini_set("track_errors", 1);
ini_set("html_errors", 1);
error_reporting(E_ALL);
@colorfield
colorfield / file-operations.sh
Last active February 7, 2018 10:14
Move all files from the current directory
# Move all files from the current directory in the parent directory
mv * .[^.]* ..
# chmod all the files only
find . -type f -exec chmod 655 {} +
# Delete files containing a pattern on the name
find my_dir -name ._\* -delete
# Find and update all occurrences of a file with a file as input
@colorfield
colorfield / drupal8-nginx-dev
Last active November 26, 2017 20:34
Drupal 8 Nginx virtual host
server {
server_name drupal8.dev; # domain name, separate aliases by a space
root /path/to/site/drupal8-dev; # directory of the site (document root)
location = /favicon.ico {
log_not_found off;
access_log off;
}
location = /robots.txt {
@colorfield
colorfield / drupal8-links.php
Last active May 3, 2024 22:47
Drupal 8 links, or where is my l() function
@colorfield
colorfield / drupal-list.php
Last active February 6, 2017 15:18
Drupal 8 and 7 list
<?php
/**
* Drupal 8 list.
* A render array element that lives inside a build() method
* e.g. inside of a class that extends BlockBase.
*/
$items = [];
$items[] = 'one';
$items[] = 'two';