Skip to content

Instantly share code, notes, and snippets.

View kabanon's full-sized avatar

kabanon

  • Dijon
View GitHub Profile
@kabanon
kabanon / ajax_example.info.yml
Created March 18, 2018 05:24 — forked from AkshayKalose/ajax_example.info.yml
Drupal 8 - Ajax Example
name: 'Ajax Example'
description: 'Just an Ajax Example'
core: 8.x
type: module
@kabanon
kabanon / Drupal 8 - Get field types
Created February 18, 2018 20:10
Get allowed values for BaseFieldDefinition::create($type)
\Drupal::service('plugin.manager.field.field_type')->getDefinitions();
$form = \Drupal::formBuilder()->getForm('\Drupal\user\Form\UserLoginForm');
kint($form);
@kabanon
kabanon / modulename.services.yml
Created February 6, 2018 11:19 — forked from jorislucius/modulename.services.yml
Yml file needed in Drupal 8 module for defining RedirectAnonymousSubscriber
services:
<yourmodulename>.event_subscriber:
class: Drupal\<yourmodulename>\EventSubscriber\RedirectAnonymousSubscriber
arguments: []
tags:
- {name: event_subscriber}
@kabanon
kabanon / RedirectAnonymousSubscriber.php
Created February 6, 2018 11:17 — forked from jorislucius/RedirectAnonymousSubscriber.php
Drupal 8 | Redirect all anonymous users to login page. With a few needed exceptions like /user/password
<?php
namespace Drupal\<yourmodulename>\EventSubscriber;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\HttpKernel\KernelEvents;
/**
@kabanon
kabanon / d8-responsive-image-programmatically.php
Created October 16, 2016 19:57 — forked from szeidler/d8-responsive-image-programmatically.php
Load and render responsive image from field in Drupal 8
<?php
function _load_header_image($variables) {
if ($node = $variables['node']) {
// Load main_image
$file = $node->field_main_image->entity;
if ($file) {
$variables = array(
'responsive_image_style_id' => 'header_image',
'uri' => $file->getFileUri(),