Skip to content

Instantly share code, notes, and snippets.

@hudri
hudri / fa5_symbol.sh
Last active Mar 23, 2018
Turn FontAwesome5 raw <svg>s into <symbol>s
View fa5_symbol.sh
cd advanced-options/raw-svg/regular
# prefix filenames with 'far-' so we could mix icons from different style set
rename 's/^/far-/' *.svg
# change opening tag '<svg xmlsn="http://www.w3.org/2000/svg"' into ' <symbol id="current-filename.svg"'
perl -i -pe 's/<svg xmlns="http:\/\/www.w3.org\/2000\/svg"/ <symbol id="$ARGV"/g' *.svg
# remove the trailng '.svg' from the id
perl -i -pe 's/\.svg"/"/g' *.svg
# change closing tag from '</svg>' to '</symbol>'
perl -i -pe 's/<\/svg>/<\/symbol>/g' *.svg
# go into next style directory, repeat with different filename prefix
@hudri
hudri / LinkModifierService.php
Last active Apr 19, 2018
Modify _all_ Drupal links
View LinkModifierService.php
<?php
namespace Drupal\wt_base;
use Symfony\Component\HttpFoundation\RequestStack;
use Drupal\Core\PathProcessor\OutboundPathProcessorInterface;
use Symfony\Component\HttpFoundation\Request;
use Drupal\Core\Render\BubbleableMetadata;
/**
* Class DefaultService.
@hudri
hudri / library.scss
Created May 7, 2018 — forked from certainlyakey/library.scss
URL-encode color SASS function / convert color to hex SASS function
View library.scss
//does not work with colors containing alpha
@function encodecolor($string) {
@if type-of($string) == 'color' {
$hex: str-slice(ie-hex-str($string), 4);
$string:unquote("#{$hex}");
}
$string: '%23' + $string;
@return $string;
}
@hudri
hudri / insert_default_paragraphs_field_value.sql
Created May 29, 2018
Drupal 8: Insert default values for in newly added paragraphs fields
View insert_default_paragraphs_field_value.sql
insert into paragraph__FIELD_NEWFIELD (bundle, deleted, entity_id, revision_id, langcode, delta, FIELD_NEWFIELD_value)
select type, 0, id, revision_id, langcode, 0, DEFAULT_FIELD_VALUE from paragraphs_item where type = 'PARENT_PARAGRAPH_TYPE';
insert into paragraph_revision__FIELD_NEWFIELD (bundle, deleted, entity_id, revision_id, langcode, delta, FIELD_NEWFIELD_value)
select type, 0, id, revision_id, langcode, 0, DEFAULT_FIELD_VALUE from paragraphs_item where type = 'PARENT_PARAGRAPH_TYPE'
View update_remote_datasource.sh
./drs php-eval '$query = \Drupal::entityTypeManager()->getStorage("node")->getQuery();
$query->condition("type", ["wt_room", "wt_package"], "IN");
$nodeIds = $query->execute();
$hotelEntities = \Drupal::entityTypeManager()->getStorage("node")->loadMultiple($nodeIds);
foreach ($hotelEntities as $hotelEntity) {
$hotelEntity->set("remote_datasource", "KOGNITIV");
$hotelEntity->save();
}'
@hudri
hudri / gist:4cb05bd631ef53fa28ca80341f73b8da
Created Aug 24, 2020
Drupal Form with multiple submit buttons in a table
View gist:4cb05bd631ef53fa28ca80341f73b8da
<?php
namespace Drupal\wt_pricetable\Form;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\paragraphs\Entity\Paragraph;
use Drupal\Component\Render\FormattableMarkup;
@hudri
hudri / webform.contact.yml
Created Sep 15, 2020
Webform with processed text causing extra DIV wrapper
View webform.contact.yml
uuid: 8b7b6e7f-dab7-446e-b640-37a3d6efb6bd
langcode: de
status: open
dependencies:
enforced:
module:
- webform
open: null
close: null
weight: 0