Skip to content

Instantly share code, notes, and snippets.

@DanLaufer
DanLaufer / Drupal 8 - Add onclick javascript to form submit button in php
Created October 19, 2018 14:52
Drupal 8 - Add onclick javascript to form submit button in php
$form['actions']['submit'] = [
'#type' => 'submit',
'#value' => $submit_button_text,
'#button_type' => 'primary',
'#attributes' => ['disabled' => 'disabled',
'onclick' => "window.open('".$file_url."', '_blank');"],
];
@DanLaufer
DanLaufer / Drupal 8 - Pass arguments to buildForm()
Created October 19, 2018 14:50
Drupal 8 - Pass arguments to buildForm()
// 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') {
@DanLaufer
DanLaufer / Bash - Alias for grep with flags
Last active October 19, 2018 14:37
Bash - Alias for a better grep
function greppy
{
grep -Hnoir "$1" .
}
@DanLaufer
DanLaufer / Bash - Function to make a new drupal 8 site with lando
Created October 19, 2018 14:36
Bash - Function to make a new drupal 8 site with lando
function drupalnew
{
if [ "$1" = "--help" ]; then
echo "The drupalnew command takes 2 arguments: drupalnew <sitename | ex: my_site> <version | ex: 8.6.x>"
return 1
fi
if [ "$1" = "--version" ]; then
echo "Drupalnew 0.0.1"
return 1
@DanLaufer
DanLaufer / Bash - Function to check for an odd number of occurances of a string in a file
Last active October 19, 2018 14:35
Bash - Function to check for an odd number of occurances of a string in a file
# $1 is the name of the element to search
# $2 is the file to search
function checkodd(){
if [ $# -ne 2 ]; then
echo "Please use the following format: checkodd <string to check> <location>"
else
for f in "$2"/* "$2"/**/* ; do
if [ -f "$f" ]; then
stringcount=$(grep -o $1 $f | wc -l)
if [ $((stringcount % 2)) -eq 1 ]; then
@DanLaufer
DanLaufer / Bash - Function add aliases
Created October 19, 2018 14:33
Bash - Function add aliases
# this command will add an alias and source the .zshrc
# $1 is the keys for the alias
# $2 is what will run. Put in quotes.
function newalias
{
if [ "$1" != "" ] && [ "$2" != "" ]; then
echo 'alias '$1'='"\""$2"\"" >> ~/.zshrc
alias "$1"="$2"
else
echo "The newalias command takes two arguments as follows: newalias <alias command> <alias function, in double quotes>"
@DanLaufer
DanLaufer / Bash - Function to open Chrome
Created October 19, 2018 14:31
Bash - Function to open Chrome
function chrome(){
/usr/bin/open -a "/Applications/Google Chrome.app" "$1"
}
@DanLaufer
DanLaufer / js-if-exists-shorthand.js
Last active May 12, 2019 17:48
JS - if exists shorthand
this.App || (this.App = {});
@DanLaufer
DanLaufer / Drupal 8 - Expand Paragraph Titles
Last active October 19, 2018 04:45
Drupal 8 - Expand Paragraph Titles
/**
* implements hook_form_node_form_alter()
* @author Daniel Laufer
* Add validation to the XXX content type.
*/
function mymodule_form_node_form_alter(&$form, FormStateInterface $form_state, $form_id) {
// expand paragraph titles
$form['#attached']['library'][] = 'mytheme/expand_paragraph';
}
@DanLaufer
DanLaufer / Alexa - Adjust how Alexa says words using Phonetics
Created August 8, 2018 14:44
Alexa - Adjust how Alexa says words using Phonetics
// using https://open-dict-data.github.io/ipa-lookup/en/?#
<phoneme alphabet="ipa" ph="/ˈk æp/">cap</phoneme>