Skip to content

Instantly share code, notes, and snippets.

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

Saeed Afzal imsaeedafzal

🏠
Working from home
View GitHub Profile
<?php
/**
* Implements hook_theme().
*/
function custom_blocks_theme($existing, $type, $theme, $path) {
return [
'custom_blocks_copyright' => [
'variables' => [
@acrosman
acrosman / JsonController.php
Created May 6, 2017 18:52
A simple example Drupal Controller with an uncached JsonResponse
<?php
namespace Drupal\example\Controller;
use Drupal\Core\Controller\ControllerBase;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\JsonResponse;
class ExampleController extends ControllerBase {
public function getJson(Request $request) {
@acrosman
acrosman / CachingController.php
Created May 6, 2017 18:59
A simple example Drupal Controller with a cached JSON Response.
<?php
namespace Drupal\example\Controller;
use Symfony\Component\HttpFoundation\Request;
use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\Cache\CacheableJsonResponse;
use Drupal\Core\Cache\CacheableMetadata;
class ExampleController extends ControllerBase {
@acrosman
acrosman / SidebarCondition.php
Last active December 1, 2021 01:50
A Drupal 8 block condition to set visibility based on a node's field value.
<?php
namespace Drupal\my_block\Plugin\Condition;
use Drupal\Core\Condition\ConditionPluginBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**