Skip to content

Instantly share code, notes, and snippets.

View jonathanfranks's full-sized avatar

J F jonathanfranks

  • Breakthrough
  • Evanston, IL
View GitHub Profile
@jonathanfranks
jonathanfranks / gist:10544cd4e1e6afe0afb9f1656c642d9b
Created April 22, 2021 15:31
Run migrate import with update option
$migration_id = 'xxx';
/** @var \Drupal\migrate\Plugin\MigrationInterface $migration */
$migration = \Drupal::service('plugin.manager.migration')
->createInstance($migration_id);
$migration->getIdMap()->prepareUpdate();
$executable = new MigrateExecutable($migration, new MigrateMessage());
$executable->import();
@jonathanfranks
jonathanfranks / test.php
Created March 1, 2019 20:07
Mocking service container in D8 unit test
$fakeService = $this->createMock('Drupal\fake\Services\Fake');
$fakeService->method('serviceMethod')
->withAnyParameters()
->willReturn(0);
$container = new ContainerBuilder();
$container->set('fake.service_name', $fakeService);
\Drupal::setContainer($container);
@jonathanfranks
jonathanfranks / delete_field_instances.php
Created September 24, 2018 23:51
D8 - Delete all instances of a field in an entity type
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\field\Entity\FieldConfig;
$entity_type = 'node';
$bundles = entity_get_bundles('node');
$fields = ['field_phone', 'field_fax'];
foreach ($bundles as $bundle) {
foreach ($fields as $field_name) {
$field = FieldConfig::loadByName($entity_type, $bundle, $field_name);
composer create-project drupal-composer/drupal-project:8.x-dev projectname --stability dev --no-interaction
$uuid_service = \Drupal::service('uuid');
$uuid = $uuid_service->generate();
$migration_id = 'ncsbn_migrate_import_menu_items';
$migration = \Drupal::service('plugin.manager.migration')->createInstance($migration_id);
$executable = new \Drupal\migrate\MigrateExecutable($migration, new \Drupal\migrate\MigrateMessage());
$executable->import();
@jonathanfranks
jonathanfranks / gist:cd1344e5213aa42c6cc425201e6c0442
Created May 8, 2017 16:37
Drupal 8 Repository for Composer
composer config repositories.drupal composer https://packages.drupal.org/8
@jonathanfranks
jonathanfranks / script.php
Created April 19, 2017 15:55
D8 refresh module config
$config_installer = \Drupal::service('config.installer');
$config_installer->installDefaultConfig('module', 'mymodule_name');
@jonathanfranks
jonathanfranks / deletecookie.js
Created September 1, 2015 21:51
Delete Cookie by Name (JS)
var delete_cookie = function(name) {
document.cookie = name + '=;expires=Thu, 01 Jan 1970 00:00:01 GMT;';
};
delete_cookie('roundcube_sessauth');
@jonathanfranks
jonathanfranks / FormContext.php
Created August 12, 2015 15:05
Behat CKEditor
/**
* @Then /^I fill in wysiwyg field "([^"]*)" with "([^"]*)"$/
*/
public function iFillInWysiwygOnFieldWith($locator, $value) {
$el = $this->getSession()->getPage()->findField($locator);
$fieldId = $el->getAttribute('id');
if (empty($fieldId)) {
throw new Exception('Could not find an id for field with locator: ' . $locator);
}