Skip to content

Instantly share code, notes, and snippets.

View nickopris's full-sized avatar

Nick Opris nickopris

  • London, UK
View GitHub Profile
// in preprocessing.php
$variables['lead_form'] =
\Drupal::formBuilder()->getForm('Drupal\my_form_module\Form\LeadForm', 'hero_video');
//it passes that extra variable through getForm into an arguments array added on the end of buildForm
public function buildForm(array $form, FormStateInterface $form_state, string $gated_content_context = NULL) {
if($gated_content_context === 'hero_video') {
@nickopris
nickopris / FeatureContext.php
Created April 17, 2024 13:58
Behat get current user
<?php
declare(strict_types = 1);
use Drupal\DrupalExtension\Context\RawDrupalContext;
/**
* Defines step definitions that are generally useful for the project.
*/
class FeatureContext extends RawDrupalContext {
@nickopris
nickopris / install.sh
Last active April 18, 2024 20:26
Development setup
# Prerequisites
# place this script in a directory called tools to sit at he same level as your project directory
# an .env file with credentials inside tools
# get the solr archive from prod or me. should be extracted into tools with the name solr_8.x_config
# Be aware that git pull and docker image pull are subjected to quota limits and may need to authenticate.
# script vars
PROJECT_DIRECTORY="your-project-new-folder"
MY_FORKED_REPO='https://github.com/...'
<?php
// Turn off all error reporting
error_reporting(0);
// Configuration
$user = 'your_login';
$password = 'you_password';
$host = 'imap.gmail.com';
@nickopris
nickopris / cf7-floating-labels-example-form.html
Created January 19, 2023 21:36 — forked from sagive/cf7-floating-labels-example-form.html
Contact Form 7 (CF7) Floating Labels.
<div class="newsletterSignUpFooter">
<div class="form-group">[text* your-name class:form-control class:input-lg] <label for="your-name">First Name</label></div>
<div class="form-group">[text* text-777 class:form-control class:input-lg] <label for="your-name">Last Name</label></div>
<div class="form-group">[email* your-email class:form-control class:input-lg] <label for="your-name">Your Email</label></div>
<div class="">[submit class:btn class:btn-warning class:btn-lg class:w100 "Send"]</div>
</div>
<?php
/**
* @file Contains \Drupal\custom_module\Plugin\Field\FieldType\RoleRate
*/
namespace Drupal\custom_module\Plugin\Field\FieldType;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\Core\Field\Plugin\Field\FieldType\EntityReferenceItem;
use Drupal\Core\Form\FormStateInterface;
@nickopris
nickopris / shoutcast.php
Created April 7, 2022 11:58 — forked from njh/shoutcast.php
PHP script to check the status of a Shoutcast stream
<?php
$PLAYLIST_URL = 'http://www.bbc.co.uk/radio/listen/live/r1.pls';
set_time_limit(5);
// Fetch and parse a .pls playlist file
// @returns an array of URLs in the playlist
function readPlaylist($url)
<?php
$dates = [
"12/01/2021",
"12/05/2021",
"12/09/2021",
"12/10/2021",
"12/11/2021",
"12/15/2021",
"12/10/2021",
@nickopris
nickopris / geoLocationFromPostcode.php
Created March 6, 2021 09:11
Postcodes.io geolocation search by postcode
<?php
/**
* @param $postcode
*
* @return array
*/
function getGeoLocationFromPostcode($postcode) {
$geo = [];
$url = "https://api.postcodes.io/postcodes/" . $postcode;
@nickopris
nickopris / haversine.php
Created March 6, 2021 09:08
Geolocation distance between two points with lat and lon values
<?php
/**
* https://www.movable-type.co.uk/scripts/latlong.html
* @param $lat1
* @param $lat2
* @param $lon1
* @param $lon2
*
* @return float|int