Skip to content

Instantly share code, notes, and snippets.

View jtarleton's full-sized avatar

James Tarleton jtarleton

View GitHub Profile
/**
* Implements hook_form_FORM_ID_alter() for form--user-login-form.html.twig.
*/
function sfp_form_user_login_form_alter(&$form, $form_state) {
$config = \Drupal::config('system.site');
$site_login_blurb_display = $config->get('site_login_blurb_display');
$site_login_blurb = ($site_login_blurb_display) ? $config->get('site_login_blurb') : '';
$form['#prefix'] = sprintf('<div class="site_login_blurb">%s</div>', $site_login_blurb);
$form['#suffix'] = '';
@jtarleton
jtarleton / htaccess
Created February 6, 2023 23:59
Redirecting one domain to another with mod_rewrite
# Redirect old.org.il to www.new.org/he
# test at: https://htaccess.madewithlove.com/
RewriteCond %{HTTP_HOST} ^old\.org\.il$ [OR]
RewriteCond %{HTTP_HOST} ^\w+\.old\.org\.il$
RewriteRule ^(.*)$ https://www.new.org/he/$1 [R=301,L]
@jtarleton
jtarleton / mymodule.module
Created October 12, 2022 19:31
Adding Additional Fields to a Drupal Core Form (or any Drupal form) Using hook_form_alter
<?php
/**
* @file
* mymodule module file.
*/
use Drupal\Core\Form\FormStateInterface;
/**
@jtarleton
jtarleton / NycTestForm.php
Last active April 16, 2020 17:04
Basic Drupal8 Custom Form
<?php
namespace Drupal\nyc_common\Form;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\nyc_map\Utils\NycLocationServices;
use Drupal\nyc_map\Utils\NycGeometryUtility;
use Drupal\Core\Ajax\AjaxResponse;
@jtarleton
jtarleton / page.html.twig
Last active January 28, 2019 13:57
Drupal 8 Example Page (Inner HTML) template
{#
/**
* @file
* Example subtheme implementation to display a single page.
*
* The doctype, html, head and body tags are not in this template. Instead they
* can be found in the html.html.twig template in this directory.
*
* Available variables:
@jtarleton
jtarleton / html.html.twig
Created January 26, 2019 01:12
Sample Drupal 8 Outer Html Template
{#
/**
* @file
* A subtheme implementation for the basic structure of a single Drupal page.
*
* Variables:
* - logged_in: A flag indicating if user is logged in.
* - root_path: The root path of the current page (e.g., node, admin, user).
* - node_type: The content type for the current node, if the page is a node.
* - head_title: List of text elements that make up the head_title variable.
@jtarleton
jtarleton / node.html.twig
Created January 23, 2019 19:21
Drupal 8 Node Core Template
{#
/**
* @file
* Default theme implementation to display a node.
*
* Available variables:
* - node: The node entity with limited access to object properties and methods.
* Only method names starting with "get", "has", or "is" and a few common
* methods such as "id", "label", and "bundle" are available. For example:
* - node.getCreatedTime() will return the node creation timestamp.
@jtarleton
jtarleton / block.html.twig
Created January 23, 2019 19:06
Drupal 8 Core Block Template
{#
/**
* @file
* Default theme implementation to display a block.
*
* Available variables:
* - plugin_id: The ID of the block implementation.
* - label: The configured label of the block if visible.
* - configuration: A list of the block's configuration values.
* - label: The configured label for the block.
@jtarleton
jtarleton / Vagrantfile
Created July 11, 2018 14:13
Vagrant File for Local Dev Environment: Three Web Servers, One DB Server
Vagrant.configure("2") do |config|
#config.vm.synced_folder "C:\\Users\\jtarleton\\vagrant", "/var/winroot"
#config.vm.network "forwarded_port", guest: 80, host: 8080, host_ip: "192.168.33.10"
#config.vm.provision :shell, path: "bootstrap.sh"
config.vm.define "weblocal" do |weblocal|
weblocal.vm.box = "ubuntu/precise64"
weblocal.vm.synced_folder "C:\\vagrantvm\\adid", "/var/www/adid"
weblocal.vm.synced_folder "C:\\Users\\jtarleton\\vagrant_www", "/var/winroot"
weblocal.vm.synced_folder "C:\\Users\\jtarleton\\vagrant_web\\home\\jtarleton\\tmp", "/home/jtarleton/tmp"
weblocal.vm.network "private_network", ip:"192.168.33.10"
@jtarleton
jtarleton / PatIndex.sql
Created June 27, 2018 13:49
PatIndex MySQL stored procedure
CREATE DEFINER=`root`@`localhost` FUNCTION `PatIndex`(pattern VARCHAR(255), tblString VARCHAR(255)) RETURNS int(11)
DETERMINISTIC
BEGIN
DECLARE i INTEGER;
SET i = 1;
myloop: WHILE (i <= LENGTH(tblString)) DO
IF SUBSTRING(tblString, i, 1) REGEXP pattern THEN