Skip to content

Instantly share code, notes, and snippets.

@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;
@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;
@clrockwell
clrockwell / PromotionAdvanced.php
Created December 6, 2017 21:50
commerce_order_report plugin
<?php
namespace Drupal\scholarrx_reports\Plugin\Commerce\ReportType;
use Drupal\commerce_order\Adjustment;
use Drupal\commerce_order\Entity\OrderInterface;
use Drupal\commerce_order\Entity\OrderItemInterface;
use Drupal\commerce_promotion\Entity\CouponInterface;
use Drupal\commerce_promotion\Entity\Promotion;
use Drupal\commerce_reports\Annotation\CommerceReportType;
@jmolivas
jmolivas / ._README.md
Last active January 2, 2018 15:57
Basic docker configuration for drupal projects

Basic docker configuration for drupal projects

Extra steps

  1. If not using DrupalConsole you will need to add the vlucas/phpdotenv dependency to load the .env file. You can do that using composer:
composer require vlucas/phpdotenv
  1. Add the TRAEFIK_HOST value to /etc/hosts
<?php
/**
* @When I switch to the frame by selector "[title=:arg1]"
*/
public function switchToIFrameFromSelector($iframeSelector) {
$function = <<<JS
(function(){var iframe = document.querySelector("$iframeSelector");iframe.name = "iframeToSwitchTo";})()
JS;
try {
function encryptData($data) {
$plainText = json_encode($data);
$bytesToBeEncrypted = $plainText;
$passwordBytes = utf8_encode("p@SSword");
$passwordBytes = hash('sha256', $passwordBytes, true);
$saltBytes = array(1,2,3,4,5,6,7,8);
$saltBytesstring = "";
<?php
namespace Drupal\projects\Plugin\Block;
use Drupal\Component\Serialization\Json;
use Drupal\Core\Block\Annotation\Block;
use Drupal\Core\Block\BlockBase;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
@crittermike
crittermike / ExampleModuleController.php
Last active June 17, 2021 12:55
Example of overriding a route controller in Drupal 8
<?php
/**
* @file
* Contains \Drupal\example_module\Controller\ExampleModuleController.
*/
// THIS FILE BELONGS AT /example_module/src/Controller/ExampleModuleController.php
namespace Drupal\example_module\Controller;
@ken-muturi
ken-muturi / new_gist_file.php
Created November 17, 2013 07:03
Countries array
<?php
// https://snipt.net/public/tag/php/?page=3
$countries = array(
"AF" => array("country" => "Afghanistan", "continent" => "Asia"),
"AX" => array("country" => "Åland Islands", "continent" => "Europe"),
"AL" => array("country" => "Albania", "continent" => "Europe"),
"DZ" => array("country" => "Algeria", "continent" => "Africa"),
"AS" => array("country" => "American Samoa", "continent" => "Oceania"),
@vistar
vistar / d9-remove-wrong-equal-translations-l10n.md
Last active April 23, 2022 15:54 — forked from JPustkuchen/d8-remove-wrong-equal-translations-l10n.md
Drupal 9 CMS: Delete equal customized translation (source language string = target language string)

Drupal 9 CMS: Delete equal customized translation (source language string = target language string)

If you should encounter the problem that some translations are wrongly translated with the equal source language string (for example in our case there were German translations for "Author" translated with "Author" or "Published" with "Published"), you may use the following snippet to list them.

SELECT s.lid,s.source, t.translation FROM `locales_source` s
INNER JOIN locales_target t
WHERE s.lid=t.lid AND CONVERT(s.source USING utf8) = CONVERT(t.translation USING utf8) 
AND t.customized=1

To finally delete them, you may use something like this, but make a backup before and know what you're doing!