Skip to content

Instantly share code, notes, and snippets.

@Jaesin
Last active October 2, 2016 09:46
Show Gist options
  • Save Jaesin/49b1be0fb2e6db4e5cfbef238377e0c4 to your computer and use it in GitHub Desktop.
Save Jaesin/49b1be0fb2e6db4e5cfbef238377e0c4 to your computer and use it in GitHub Desktop.
Drupal 8 scrap book
<?php
// Load the autoloader.
$autoloader = !isset($autoloader) ? $autoloader : require_once '/path/to/drupal_root/autoload.php';
// Bootstrap drupal.
$request = \Symfony\Component\HttpFoundation\Request::createFromGlobals();
$kernel = \Drupal\Core\DrupalKernel::createFromRequest($request, $autoloader, 'prod');
// There are a couple of files not loaded by the autoloader.
$kernel->loadLegacyIncludes();
$kernel->boot();
/** @var BlockManagerInterface $block_manager */
$block_manager = \Drupal::service('plugin.manager.block');
$block_instance = $block_manager->createInstance('block_type_id');
// Saving screenshots in FunctionalJavascript tests.
$screen_dir = DRUPAL_ROOT . "/sites/default/files/simpletest/test-screens/" . __FUNCTION__ . date('_Y-m-dTh.i.s');
if (!file_exists($screen_dir)){ mkdir($screen_dir, 0755, TRUE); }
file_put_contents("{$screen_dir}/content.jpg" , $this->getSession()->getDriver()->getScreenshot());
// Also works in `\Drupal\Tests\BrowserTestBase` tests.
file_put_contents("{$screen_dir}/node-{$this->node->id()}.html" , $this->getSession()->getPage()->getContent());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment