Skip to content

Instantly share code, notes, and snippets.

View ButtonBlock.php
<?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;
View SOLVED.module
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 = "";
View FeatureContext.php
<?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 {
@signalpoint
signalpoint / example.php
Last active Jul 30, 2021
Drupal 8 Set Message Example
View example.php
<?php
// The drupal_set_message() function is being deprecated!
// @see https://api.drupal.org/api/drupal/core%21includes%21bootstrap.inc/function/drupal_set_message/8.5.x
// > Deprecated in Drupal 8.5.0 and will be removed before Drupal 9.0.0.
// > Use \Drupal\Core\Messenger\MessengerInterface::addMessage() instead.
// In some custom code.
\Drupal::messenger()->addMessage('Say something else');
@clrockwell79
clrockwell79 / PromotionAdvanced.php
Created Dec 6, 2017
commerce_order_report plugin
View PromotionAdvanced.php
<?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 Jan 2, 2018
Basic docker configuration for drupal projects
View ._README.md

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
@luksak
luksak / CartEventSubscriber.php
Last active Oct 19, 2017
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.
View CartEventSubscriber.php
<?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 Oct 8, 2017
Commerce shippping pane that automatically chooses a shipping method without providing a UI for the cutomer
View CustomShippingInformation.php
<?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;
@mikecrittenden
mikecrittenden / ExampleModuleController.php
Last active Jun 17, 2021
Example of overriding a route controller in Drupal 8
View ExampleModuleController.php
<?php
/**
* @file
* Contains \Drupal\example_module\Controller\ExampleModuleController.
*/
// THIS FILE BELONGS AT /example_module/src/Controller/ExampleModuleController.php
namespace Drupal\example_module\Controller;
View new_gist_file.php
<?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"),