Skip to content

Instantly share code, notes, and snippets.

View kevinquillen's full-sized avatar

Kevin kevinquillen

View GitHub Profile
@kevinquillen
kevinquillen / SearchResults.php
Created September 6, 2016 16:58
Example of a Controller using SearchAPI to generate a results page (without Views).
<?php
namespace Drupal\velirsearch\Controller;
use Drupal\Core\Controller\ControllerBase;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\Request;
use Drupal\velirsearch\Service\PagerService;
class SearchResults extends ControllerBase {
@kevinquillen
kevinquillen / FeatureContext.php
Last active July 22, 2020 18:47
A Behat definition that will instruct the client to press a vertical tab, useful for forms leveraging Field Group in Drupal (Shiny admin theme).
/**
* @When I press the :vertical_tab vertical tab
* @param $vertical_tab
*/
public function iPressTheVerticalTab($vertical_tab) {
$this->getSession()->getDriver()->click('//*[contains(@class, "node-form")]/div/div[contains(@class, "vertical-tabs")]/ul/*/a/strong[text()="' . $vertical_tab . '"]');
}
@kevinquillen
kevinquillen / module.php
Last active July 10, 2017 20:39
Importing to a SQL table from a CSV file in Drupal, so you don't have to parse exceptionally large CSVs line by line and instead can do so with MySQL querying. This snippet assumes you have read the column headers already from the CSV and passed them as parameters, as well as the temp table name you want to use.
<?php
/**
* Creates a temporary table to hold values from an uploaded CSV.
* @param $table_name
* @param $columns
* @param $message
* @param $context
*/
function csv_import_create_temp_table($table_name, $columns) {
@kevinquillen
kevinquillen / README.md
Created June 2, 2013 21:25
Reddit Widget for Dashing

Preview

Description

Took a little inspiration from the News widget to construct this Reddit widget. Simply add the subreddit .json feed URLs that you want to the top of the reddit.rb job script, and the widget will cycle through each one, showing top posts, their score, and comment count. You can also set the maxcount higher or lower, the default is 5 posts.

##Usage

@kevinquillen
kevinquillen / gist:4235124
Created December 7, 2012 18:02
Adding menu names to the ul menus in Drupal 7
function themename_menu_link(&$variables) {
$element = $variables['element'];
$sub_menu = '';
$element['#attributes']['data-menu-parent'] = $element['#original_link']['menu_name'] . '-' . $element['#original_link']['depth'];
if ($element['#below']) {
$sub_menu = drupal_render($element['#below']);
}