Skip to content

Instantly share code, notes, and snippets.

@luksak
luksak / graphqlConfig.ts
Last active March 26, 2024 07:04
Integration of nuxt-graphql-middleware with nuxt-multi-cache with full cache tag propagation
export default defineNuxtPlugin((NuxtApp) => {
const state = useGraphqlState()
const event = useRequestEvent()
if (!state) {
return
}
state.fetchOptions = {
onResponse ({ request, response, options }) {
@luksak
luksak / duplicate_views_results.php
Last active September 21, 2018 08:33
Remove duplicate views results
<?php
/*
* Implements hook_preprocess_HOOK().
*/
function hook_preprocess_views_view_unformatted__VIEW_ID(&$variables) {
$entity_ids = [];
foreach ($variables['rows'] as $key => $row) {
$entity = $row['content']['#row']->_entity;
$id = $entity->id();
@luksak
luksak / THEME.theme.php
Last active June 5, 2018 09:47
Fixing links to untranslated nodes
<?php
/*
* Implements hook_preprocess_HOOK().
*/
function THEME_preprocess_node(&$variables) {
$url = Url::fromRoute('entity.node.canonical', array('node' => $variables['node']->id()));
$variables['url'] = $url;
}
@luksak
luksak / base_url_token.module
Created November 7, 2017 13:55
This provides a taken to access the site's base URL. See: https://www.drupal.org/node/1088112
/**
* Implements hook_token_info_alter().
*/
function base_url_token_token_info_alter(&$data) {
if (isset($data['tokens']['site'])) {
$data['tokens']['site']['base-url'] = [
'name' => t("Base URL"),
'description' => t("The site's base URL"),
];
}
@luksak
luksak / CartEventSubscriber.php
Last active October 19, 2017 18:14
Display message if order total is below a certain amount such as to get free shipping after adding products to the cart and when viewing the cart page.
<?php
namespace Drupal\MODULE\EventSubscriber;
use Drupal\commerce_order\Entity\Order;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Drupal\commerce_cart\Event\CartEntityAddEvent;
use Drupal\commerce_cart\Event\CartEvents;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
@luksak
luksak / CustomShippingInformation.php
Created October 8, 2017 13:19
Commerce shippping pane that automatically chooses a shipping method without providing a UI for the cutomer
<?php
namespace Drupal\MODULE\Plugin\Commerce\CheckoutPane;
use Drupal\commerce_shipping\Entity\ShipmentInterface;
use Drupal\commerce_shipping\Entity\ShippingMethod;
use Drupal\commerce_shipping\Plugin\Commerce\CheckoutPane\ShippingInformation;
use Drupal\Core\Entity\Entity\EntityFormDisplay;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;

Keybase proof

I hereby claim:

  • I am luksak on github.
  • I am luksak (https://keybase.io/luksak) on keybase.
  • I have a public key ASCVyVO6w7PLYj5V7NCSUux55vky4dMp5t5JhPf8Qyipiwo

To claim this, I am signing this object:

@luksak
luksak / index.html
Last active May 15, 2017 09:58
Test
<html>
<body>
<h1>hello!</h1>
</body>
</html>