Skip to content

Instantly share code, notes, and snippets.

View jhedstrom's full-sized avatar

Jonathan Hedstrom jhedstrom

  • Phase2
  • Portland, OR
View GitHub Profile
@jhedstrom
jhedstrom / ExternalRedirect.php
Created April 22, 2022 15:38
Redirect canonical node page
<?php
namespace Drupal\mymodule\EventSubscriber;
use Drupal\mymodule\ExternalRedirectHelper;
use Drupal\Core\Routing\TrustedRedirectResponse;
use Drupal\node\NodeInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Event\RequestEvent;
<?php
namespace Drupal\my_module\Form;
use Drupal\Core\Datetime\Element\Datetime;
use Drupal\Core\Form\FormStateInterface;
/**
* Utility functions and static callbacks for MY MODULE module.
*/
@jhedstrom
jhedstrom / content_moderation.install
Last active March 23, 2021 08:07
Custom content moderation update hooks from 8.2.x to 8.3.x
<?php
/**
* @file
* Install file for content_moderation.
*/
use Drupal\content_moderation\Entity\ContentModerationState;
use Drupal\Core\Field\BaseFieldDefinition;
use Drupal\Core\Database\Database;
> drush php
Psy Shell v0.8.2 (PHP 7.0.13 — cli) by Justin Hileman
>>> $one = Drupal\views\Render\ViewsRenderPipelineMarkup::create(1);
=> Drupal\views\Render\ViewsRenderPipelineMarkup {#8821}
>>> $two = Drupal\Core\Render\Markup::create(2);
=> Drupal\Core\Render\Markup {#8818}
>>> $two > $one;
=> false
>>> $two == $one;
=> false
@jhedstrom
jhedstrom / notes.md
Created November 1, 2016 20:34
PHPUnit based tests in Drupal 8

Local setup

  • Environment variables:

    export SIMPLETEST_DB=mysql://user:pass@localhost/db_name
    export SIMPLETEST_BASE_URL=http://d8.dev
    
  • or copy core/phpunit.xml.dist to core/phpunit.xml and edit accordingly

Keybase proof

I hereby claim:

  • I am jhedstrom on github.
  • I am jhedstrom (https://keybase.io/jhedstrom) on keybase.
  • I have a public key whose fingerprint is EDCF B052 5C7D 0FD2 5491 12DB 846B C2BE 8B13 F40F

To claim this, I am signing this object:

@jhedstrom
jhedstrom / FeatureContext.php
Created December 8, 2015 17:38
Behat Selenium driver screenshot
<?php
/**
* @AfterStep
*/
public function takeScreenShotAfterFailedStep(AfterStepScope $scope) {
if (99 === $scope->getTestResult()->getResultCode()) {
$driver = $this->getSession()->getDriver();
if (!($driver instanceof Selenium2Driver)) {
return;
@jhedstrom
jhedstrom / FeatureContext.php
Created July 30, 2015 20:01
Organic Groups Behat step-definition examples
<?php
/**
* @Given /^I am logged in as a user in the "(?P<group>[^"]*)" group$/
*/
public function iAmLoggedInAsAUserInTheGroup($group) {
// Create user.
$account = (object) array(
'pass' => $this->getDrupal()->random->name(),
'name' => $this->getDrupal()->random->name(),
);
<?php
/**
* Provide actual overridden view config.
*/
protected function getOverriddenView() {
$view = array(
'display' => array(
'default' => array(
'display_options' => array(
@jhedstrom
jhedstrom / gist:33e26b2400989fa6416e
Created January 28, 2015 19:43
Drupal with composer
$> drush use @existing-d7-site
$> drush dl composer_generate
$> mkdir /tmp/new-site
$> drush composer-generate > /tmp/new-site/composer.json
$> cd /tmp/new-site
$> composer install
$> composer require drupal/views