Skip to content

Instantly share code, notes, and snippets.

@bojanz
bojanz / responsetest.go
Last active Apr 9, 2021
OpenAPI assert helper
View responsetest.go
package responsetest
import (
"context"
"net/http"
"net/http/httptest"
"testing"
"github.com/getkin/kin-openapi/openapi3"
"github.com/getkin/kin-openapi/openapi3filter"
View CustomerProfile.php
<?php
namespace Drupal\commerce_order\Plugin\Commerce\InlineForm;
use Drupal\commerce\EntityHelper;
use Drupal\commerce\Plugin\Commerce\InlineForm\EntityInlineFormBase;
use Drupal\Component\Utility\Html;
use Drupal\Component\Utility\NestedArray;
use Drupal\Core\Entity\Entity\EntityFormDisplay;
use Drupal\Core\Entity\EntityTypeManagerInterface;
@bojanz
bojanz / generate_currencies.php
Last active Jun 27, 2017
Script for regenerating Commerce 1.x currencies based on CLDR
View generate_currencies.php
<?php
/**
* Regenerates the Commerce 1.x currency list from CLDR.
*
* Assumes the existence of commerce/ and intl/ folders.
* The intl/ folder should contain the commerceguys/intl
* library with the CLDR dataset downloaded via
* scripts/fetch_data.sh
*/
@bojanz
bojanz / gist:678f8801d37f8f4be34f90bb05916e74
Last active May 18, 2017
Redirect to checkout on add to cart
View gist:678f8801d37f8f4be34f90bb05916e74
<?php
/**
* Implements hook_form_BASE_FORM_ID_alter().
*/
function mymodule_form_commerce_order_item_add_to_cart_form_alter(array &$form, FormStateInterface $form_state) {
$form['actions']['submit']['#submit'][] = 'mymodule_redirect_to_checkout';
}
/**
View .vimrc
color pt_black
syntax enable
set nowrap
set wildmenu
set lazyredraw
set showmatch
set incsearch
set hlsearch
View keybase.md

Keybase proof

I hereby claim:

  • I am bojanz on github.
  • I am bojanz (https://keybase.io/bojanz) on keybase.
  • I have a public key whose fingerprint is 44A5 A3CC 1569 CD18 1863 8732 6FC5 55AF 7DB3 3E13

To claim this, I am signing this object:

@bojanz
bojanz / extension-patterns.md
Last active Dec 9, 2020
Extension patterns: events, tagged services, plugins
View extension-patterns.md

This documentation is destined for drupal.org. Created first as a gist to make initial comments easier. Rewrites and clarifications welcome. Code samples are simplified for clarity. Perhaps a bit too much?

When talking about extensibility, there are several distinct use cases:

  1. Reacting to an action that has already happened.

The reaction can be anything; outputting a message, sending an email, modifying a related object, etc. Examples:

  • "A node has been saved"
  • "A product has been added to the cart".
@bojanz
bojanz / gist:3295371
Created Aug 8, 2012
Backend agnostic views_handler_field_term_node_tid
View gist:3295371
list($entity_id, $bundle) = entity_extract_ids($entity);
$tids = array();
foreach (field_info_instances($current_entity_type, $bundle) as $field_name => $instance) {
$field = field_info_field($field_name);
// The final code would check the vocabulary here as well, since the handler has options for
// limiting by vocabulary
if ($field['type'] == 'taxonomy_term_reference') {
$items = field_get_items($current_entity_type, $entity, $field_name);
foreach ($items as $item) {
$tids[] = $item['tid'];