Skip to content

Instantly share code, notes, and snippets.

View bfodeke's full-sized avatar

Bayo Fodeke bfodeke

  • Red Hat
  • United States
View GitHub Profile
@bfodeke
bfodeke / launch.json
Last active March 13, 2018 16:21
Visual Studio Code custom settings
{
"version": "0.2.0",
"configurations": [
{
"name": "Listen for XDebug",
"type": "php",
"request": "launch",
"port": 9000,
"pathMappings": {
"/home/vagrant/docroot": "${workspaceRoot}/docroot",
@bfodeke
bfodeke / Drupal: Solrsearch.php
Last active November 27, 2017 12:02
Search solr using custom code
<?php
/**
* Good resources.
*
* https://www.triquanta.nl/blog/what-fq-short-summary-solr-query-fields
* https://lucene.apache.org/solr/guide/6_6/common-query-parameters.html
* http://valuebound.com/resources/blog/how-to-create-custom-solr-search-autocomplete-drupal-7
*/
@bfodeke
bfodeke / change_field_type.php
Created December 13, 2017 01:34
Drupal 7: Change field type in the database
<?php
// Manually update the field type in the database to `list_text`.
db_update('field_config')
->fields([
'type' => 'list_text',
])
->condition('field_name', 'field_some_field_name', '=')
->execute();
// Update the field type from 'int' to 'varchar' and update length.
@bfodeke
bfodeke / updateQueryStringParam.js
Created March 8, 2018 04:07
Function to replace url params using the historyAPI
Drupal.behaviors.myModule = {
attach: function (context, settings) {
},
/**
* Explicitly save/update a url parameter using HTML5's replaceState().
*
* @param {string} key
* Url param key.
* @param {string} value
@bfodeke
bfodeke / behat.yml
Created May 23, 2019 15:23
Behat: Using Chrome driver
default:
suites:
default:
contexts:
- FeatureContext
- Drupal\DrupalExtension\Context\DrupalContext
- Drupal\DrupalExtension\Context\MinkContext
- Drupal\DrupalExtension\Context\MessageContext
- Drupal\DrupalExtension\Context\DrushContext
filters:
@bfodeke
bfodeke / gist:99a4fc6c104e67d69faabaefe817474c
Created May 23, 2019 15:25
Behat: Custom step to test clicking on an element with a class
/**
* Clicks on a css element.
*
* @Given I click the :arg1 element
*/
public function iClickTheElement($selector) {
$page = $this->getSession()->getPage();
$element = $page->find('css', $selector);
if (empty($element)) {
@bfodeke
bfodeke / gist:4fc790b6ea27e7a500bf6b37e6872933
Created May 23, 2019 15:26
Behat: Logging in to accounts via email or username using drush
/**
* @Given I log in as :name
*/
public function iLogInAs($name) {
$domain = $this->getMinkParameter('base_url');
// Pass base url to drush command.
$uli = $this->getDriver('drush')->drush('uli', array(
"'" . $name . "'",
"--browser=0",
"--uri=$domain",
@bfodeke
bfodeke / behat.local.yml
Created May 23, 2019 15:32
Behat: Local behat settings
#local configuration
default:
extensions:
Behat\MinkExtension:
base_url: http://localdev.dev
sessions:
default:
goutte:
guzzle_parameters:
verify: false #get around ssl cert on local environment
@bfodeke
bfodeke / gist:270d15b206c420b22b83268255c2e2ba
Created October 20, 2020 21:29
Drupal 8: Uninstall module that has already been removed
// https://www.drupal8.ovh/en/tutoriels/372/remove-uninstall-deleted-module-drupal-registry
drush sql-query "DELETE FROM key_value WHERE collection='system.schema' AND name='module_name';"
@bfodeke
bfodeke / gist:7090e12425f04e104af1034366731138
Created December 17, 2020 20:24
D8/Twig: Get URL of embedded media entity reference
// https://createdbycocoon.com/knowledge/get-media-video-url-twig-drupal-8
Sometimes it may be useful to access the raw media file URL/URI value for a video file that has been uploaded via a Media field on an entity type.
In your Twig template, you may wish to display the raw URL of the file, rather than the embedded video or rendered entity as Drupal 8 natively provides.
It's really simple to access the raw URI. Simply use the following syntax in your Twig file (which will work for nodes, custom block templates, and paragraphs):
`{{ file_url(content.field_video[0]['#media'].field_media_video_file.entity.uri.value) }}`