Skip to content

Instantly share code, notes, and snippets.

David davpsh

Block or report user

Report or block davpsh

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
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
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;
morsok / referer.php
Last active Aug 15, 2019
Drupal 8 : Do something based on the referer if it's your website or another.
View referer.php
use Drupal\Core\Url;
use Symfony\Component\HttpFoundation\Request;
function my_function() {
$previousUrl = \Drupal::request()->server->get('HTTP_REFERER');
$fake_request = Request::create($previousUrl);
$url_object = \Drupal::service('path.validator')->getUrlIfValid($fake_request->getRequestUri());
if ($url_object) {
$route_name = $url_object->getRouteName();
// Do something with $route_name;
You can’t perform that action at this time.