Skip to content

Instantly share code, notes, and snippets.

@h3rj4n
h3rj4n / test.php
Last active November 3, 2016 12:36
<?php
// Include the autoload that includes our packages.
require_once 'vender/autoload.php';
// Test the debugging tool!
r('hallow testing');
// Keep track of count.
$i = 0;
@h3rj4n
h3rj4n / gist:0d419a6428ecae246f04
Last active May 12, 2016 17:05
Drupal jQuery
(function ($) {
Drupal.behaviors.collapsibleTable = {
attach: function(settings, content) {
$('tr.collapsitablesection').toggle(
function() {
$(this).nextUntil('tr.collapsitablesection').hide();
},
function() {
$(this).nextUntil('tr.collapsitablesection').show();
}
<?php
if (isset($data['table']['base']['defaults']['field'])) {
$default_field = $data['table']['base']['defaults']['field'];
}
else {
foreach ($data as $default_field => $field_data) {
if (isset($field_data['field']['id'])) {
break;
}
}
@h3rj4n
h3rj4n / gist:8454212
Created January 16, 2014 12:28
Drupal 8 Routing YAML example
custom.event.view:
path: '/admin/structure/custom/{custom}/manage/{custom_event}'
defaults:
_content: '\Drupal\custom\Controller\CustomEventController::page'
_title_callback: '\Drupal\custom\Controller\CustomEventController::pageTitle'
requirements:
_permission: 'administer custom'
custom.event.edit:
path: '/admin/structure/custom/{custom}/manage/{custom_event}/edit'
defaults:
<?php
// DatabaseStorateController::save()
public function save(EntityInterface $entity) {
$transaction = $this->database->startTransaction();
try {
// Load the stored entity, if any.
if (!$entity->isNew() && !isset($entity->original)) {
$entity->original = entity_load_unchanged($this->entityType, $entity->id());
}