Skip to content

Instantly share code, notes, and snippets.

View lkacenja's full-sized avatar

Leo Kacenjar lkacenja

  • Morris Animal Foundation
  • Denver, CO
View GitHub Profile
<script type="<hash>-text/javascript">window.smartlook||(function(d) {var o=smartlook=function(){ o.api.push(arguments)},h=d.getElementsByTagName('head')[0];var c=d.createElement('script');o.api=new Array();c.async=true;c.type='text/javascript';c.charset='utf-8';c.src='//rec.smartlook.com/recorder.js';h.appendChild(c);})(document);smartlook('init', '<key goes here>');</script>
@lkacenja
lkacenja / one-all-lookup.php
Created January 29, 2019 15:43
Look up a user by email and print out their social log in provider name.
<?php
$email = '<email>';
$query = \Drupal::service('database')->select('users_field_data', 'users');
$query->join('oneall_social_login_authmap', 'map', 'users.uid=map.uid');
$query->join('oneall_social_login_identities', 'identity', 'identity.aid=map.aid');
$query->addField('identity', 'provider_name', 'provider_name');
$query->condition('users.mail', $email);
$result = $query->execute()->fetchAll();
array_walk($result, 'print_r');
@lkacenja
lkacenja / update-entity-field.php
Created September 21, 2018 14:21
Update a basefield definition for an existing entity.
<?php
use Drupal\Core\Field\BaseFieldDefinition;
$definition_manager = \Drupal::entityDefinitionUpdateManager();
$field_storage_definition = $definition_manager->getFieldStorageDefinition('alternate_payment', 'spending_request');
// IF THIS IS UPDATING AN EXISTING FIELD
// $definition_manager->uninstallFieldStorageDefinition($field_storage_definition);
$new_field = BaseFieldDefinition::create('integer')
->setLabel(t('Alternate Payment'))
->setDescription(t('Track spending requests that do not have internal payments.'))
->setDisplayOptions('view', [
public function buildVariationForm(array &$form, FormStateInterface $form_state, $product_variation) {
$delta_key = 'section-delta-'. $product_variation->id();
$session_delta = $form_state->get($delta_key);
if (empty($session_delta)) {
$session_delta = 1;
$form_state->set($delta_key, 1);
}
$element = [];
$id = 'wrapper-' . $product_variation->id();
$element['section_container'] = [
$nodes = node_load_multiple(array(), array('type' => 'trail'));
$watermark = 0;
$limit = 1000;
$offset = 0;
foreach($nodes AS $node) {
if ($watermark + $offset < $limit + $offset ) {
$trail = omf_trails_get_trail($node);
omf_trails_save_trail($node, $trail);
}
$watermark ++;
$nodes = node_load_multiple(array(), array('type' => 'trail'));
foreach($nodes AS $node) {
if (empty($node->field_trail_type[LANGUAGE_NONE])) {
$node->field_trail_type[LANGUAGE_NONE][0]['tid']= 135;
node_save($node);
}
}
@lkacenja
lkacenja / toggle.js
Last active December 13, 2017 16:34
Simple flagging snippet.
(function(ajax) {
'use strict';
const ON_TEXT = 'On';
const OFF_TEXT = 'Off';
const LOADING_TEXT = 'loading';
const RESOURCE_URL = '/ze-api';
class Toggle {
constructor(wrapper) {
this.handleToggle = this.handleToggle.bind(this);
this.handleSuccess = this.handleSuccess.bind(this);
@lkacenja
lkacenja / .htaccess
Created August 1, 2017 21:38
Drupal 8 Default
AddType application/x-httpd-php55 .php
#
# Apache/PHP/Drupal settings:
#
# Protect files and directories from prying eyes.
<FilesMatch "\.(engine|inc|install|make|module|profile|po|sh|.*sql|theme|twig|tpl(\.php)?|xtmpl|yml)(~|\.sw[op]|\.bak|\.orig|\.save)?$|^(\.(?!well-known).*|Entries.*|Repository|Root|Tag|Template|composer\.(json|lock))$|^#.*#$|\.php(~|\.sw[op]|\.bak|\.orig|\.save)$">
<IfModule mod_authz_core.c>
Require all denied
</IfModule>
@lkacenja
lkacenja / trails.js
Created June 8, 2017 20:48
Js powering GOK trail map.
(function ($, Drupal, window, document, undefined) {
// Establish namespaces
Drupal.trails = Drupal.trails || {};
Drupal.trails.Views = Drupal.trails.Views || {};
// Establish global pubsub
Backbone.pubSub = Backbone.pubSub || _.extend({}, Backbone.Events);
// Map config specific vars
var styles = [
{
featureType: "poi",
<?php
function foop($class_date_nid, $webform_nid) {
$sub_query = db_select('webform_submitted_data', 'w');
$sub_query->fields('w', array('sid'));
$sub_query->join('webform_component', 'webform_component', 'w.cid=webform_component.cid');
$sub_query->condition('form_key', 'ssl_date_nid', '=');
$sub_query->condition('webform_component.nid', $webform_nid, '=');
$sub_query->condition('data', $class_date_nid, '=');
$query = db_select('webform_submitted_data', 'w');