Skip to content

Instantly share code, notes, and snippets.

Aaron Crosman acrosman

Block or report user

Report or block acrosman

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@acrosman
acrosman / CachingController.php
Created May 6, 2017
A simple example Drupal Controller with a cached JSON Response.
View CachingController.php
<?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 / DataLoaderBatchService.php
Created Jul 30, 2019
A Drupal 8 batch job to load large amounts of data into a Pantheon web site. Relies on Batch Services sandbox module: https://www.drupal.org/sandbox/acrosman/3025562
View DataLoaderBatchService.php
<?php
namespace Drupal\example_pantheon_loader;
use Drupal\Core\Database\Connection;
use Drupal\batch_service_interface\AbstractBatchService;
use Drupal\Core\Logger\LoggerChannelFactoryInterface;
use Drupal\Core\StringTranslation\TranslationInterface;
use Drupal\file\Entity\File;
use Drupal\Core\File\FileSystem;
@acrosman
acrosman / FA_Signing.php
Last active Apr 26, 2019
A PHP function to sign dynamic parameters for FormAssembly
View FA_Signing.php
<?php
function prepareFormAssemblyQueryString(array $parameters, $salt, $expire_timeout) {
$parts = [];
$signString = '';
foreach($parameters as $key => $value) {
$signString .= $key . $value;
$parts[] = rawurlencode($key) . '=' . rawurlencode($value);
}
$expireTime = time() + $expire_timeout;
$signString .= 'expire' . (string)$expireTime;
@acrosman
acrosman / SidebarCondition.php
Last active Apr 18, 2019
A Drupal 8 block condition to set visibility based on a node's field value.
View SidebarCondition.php
<?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;
/**
View TaskPluginManager.php
<?php
namespace Drupal\sitemanager\Plugin;
use Drupal\Core\Plugin\DefaultPluginManager;
use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
/**
* Provides the Task plugin plugin manager.
View TaskPlugin.php
<?php
/**
* @file
* Provides TaskPlugin base class.
*/
namespace Drupal\sitemanager\Annotation;
use Drupal\Component\Annotation\Plugin;
View phpscan.py
#!/usr/bin/python
import sys
from os import listdir
from os.path import isfile, join
from os import walk
test_path = sys.argv[1]
files = []
View TaskPluginInterface.php
<?php
namespace Drupal\sitemanager\Plugin;
use Drupal\Component\Plugin\PluginInspectionInterface;
/**
* Defines an interface for Task plugin plugins.
*/
interface TaskPluginInterface extends PluginInspectionInterface {
View TaskPluginBase.php
<?php
namespace Drupal\sitemanager\Plugin;
use Drupal\Component\Plugin\PluginBase;
use Drupal\Core\Config\ConfigFactory;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\Core\StringTranslation\TranslationInterface;
View RunCron.php
<?php
namespace Drupal\sitemanager\Plugin\TaskPlugin;
use Drupal\sitemanager\Plugin\TaskPluginBase;
/**
* Class RunCron.
*
* @package Drupal\sitemanager\Plugin\TaskPlugin
*
You can’t perform that action at this time.