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 / 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 / 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 / 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 / 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 / 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 / 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 / mymodule.css
Created July 26, 2017 14:33 — forked from AlexSkrypnyk/mymodule.css
Drupal 'add more' and 'remove single' AJAX buttons on multi value custom field using FormAPI
input.form-submit.button-small {
padding: 4px 8px;
font-weight: bold;
}
.container-inline input.form-submit.button-small + .ajax-progress.ajax-progress-throbber .throbber {
position: absolute;
left: 19px;
margin-top: 7px;
}
@bfodeke
bfodeke / Drupal: Create redirect
Created June 16, 2017 12:16
Create a redirect to a path using the redirect module.
// Apply redirect from old content to new content.
$old_alias = 'some/old/path';
$new_alias = 'node/' . $node->nid;
$redirect = new stdClass();
redirect_object_prepare($redirect);
$redirect->source = $old_alias;
$redirect->redirect = $new_alias;
redirect_save($redirect);
/**
* Implements hook_page_alter().
*/
function mymodule_page_alter(&$page) {
if (!extension_loaded('newrelic')) {
return;
}
$name = NULL;
@bfodeke
bfodeke / Drupal: Field and Instance Export
Last active May 11, 2017 14:30
After creating a field in the UI, get the export code to put in custom module.
<?php
// https://steindom.com/articles/exporting-and-creating-field-definitions-drupal-7
$entity_type = 'node';
$field_name = 'field_name';
$bundle_name = 'content_type';
$info_config = field_info_field($field_name);
$info_instance = field_info_instance($entity_type, $field_name, $bundle_name);
unset($info_config['id']);