Skip to content

Instantly share code, notes, and snippets.

Avatar

Julian Pustkuchen JPustkuchen

View GitHub Profile
@leodutra
leodutra / -setup-windows-wsl-devenv.md
Last active Jul 27, 2021
Install and Setup Windows Subsystem 2 for Linux, Hyper, ZSH + Oh My Zsh + Powerlevel9k + plugins, FNM + VSCode (+ext) and Nerd Font
View -setup-windows-wsl-devenv.md

Setup Windows Subsystem 2 for Linux

Windows Subsystem 2 for Linux, Hyper, ZSH + Oh My Zsh + Powerlevel9k + plugins, FNM + VSCode (+ext) and Nerd Font

To setup native Linux, see this gist

Preview

Requirements

@JPustkuchen
JPustkuchen / scrollToMiddle.js
Created Aug 14, 2019
jQuery: Scroll element to the middle of the viewport
View scrollToMiddle.js
(function($) {
/**
* jQuery function to scroll the viewport middle to the element.
*/
$.fn.scrollToMiddle = function(options) {
var settings = $.extend({
duration: 1000
}, options );
return this.each(function() {
@JPustkuchen
JPustkuchen / d8-remove-wrong-equal-translations-l10n.md
Last active Mar 7, 2021
Drupal 8 CMS: Delete equal customized translation (source language string = target language string)
View d8-remove-wrong-equal-translations-l10n.md

Drupal 8 CMS: Delete equal customized translation (source language string = target language string)

If you should encounter the problem that some translations are wrongly translated with the equal source language string (for example in our case there were German translations for "Author" translated with "Author" or "Published" with "Published"), you may use the following snippet to list them.

SELECT s.lid,s.source, t.translation FROM `locales_source` s
INNER JOIN locales_target t
WHERE s.lid=t.lid AND CONVERT(s.source USING utf8) = CONVERT(t.translation USING utf8) 
AND t.customized=1

To finally delete them, you may use something like this, but make a backup before and know what you're doing!

@Erikdekamps
Erikdekamps / add_translations.install
Last active Apr 14, 2021
Drupal 8 - Programmatically translate strings via hook_update_N()
View add_translations.install
/**
* Helper function for adding translations.
*
* @param array $strings
* The array with strings and their translations.
*/
function _my_module_add_translations(array $strings) {
// Get locale storage service.
$storage = \Drupal::service('locale.storage');
@WengerK
WengerK / README.md
Last active Sep 23, 2020
Drupal 8 - How to translate Config API
View README.md

Article Ressources - Drupal 8, How to translate Config API

This is the Gist repository for my article Drupal 8, How to translate Config API.

Be aware that this article has been wrote for the Blog of Antistatique — Web Agency in Lausanne, Switzerland. A place where I work as Full Stack Web Developer.

Feel free to read it the full article on Medium or check it out on Antistatique.

Content of this Gist :

  • SettingsForm.php : Basic Form Config
@mikecrittenden
mikecrittenden / import.php
Last active Jul 27, 2021
Importing Drupal 8 config programmatically
View import.php
<?php
// Import arbitrary config from a variable.
// Assumes $data has the data you want to import for this config.
$config = \Drupal::service('config.factory')->getEditable('filter.format.basic_html');
$config->setData($data)->save();
// Or, re-import the default config for a module or profile, etc.
\Drupal::service('config.installer')->installDefaultConfig('module', 'my_custom_module');
@leymannx
leymannx / ionos.sh
Last active Jul 16, 2021
1&1 ionos shared webhosting command line PHP Drush Composer Drupal
View ionos.sh
# https://www.ionos.com/community/hosting/php/using-php-composer-in-11-ionos-webhosting-packages/
php -v
# PHP 4.4.9 (cgi-fcgi) (built: Nov 7 2018 13:27:00)
# Copyright (c) 1997-2008 The PHP Group
# Zend Engine v1.3.0, Copyright (c) 1998-2004 Zend Technologies
/usr/bin/php7.1-cli -v
# PHP 7.1.25 (cli) (built: Dec 10 2018 10:11:36) ( NTS )
# Copyright (c) 1997-2018 The PHP Group
@steffenr
steffenr / mymodule.libraries.yml
Created Aug 12, 2016
Attach a CSS or JS library to a View in Drupal 8
View mymodule.libraries.yml
custom_view:
css:
component:
css/custom_view.css: {}
@pfaocle
pfaocle / gen-d8-salt.sh
Created Mar 8, 2016
Generate Drupal 8 hash salt
View gen-d8-salt.sh
drush eval "var_dump(Drupal\Component\Utility\Crypt::randomBytesBase64(55))"
@jmolivas
jmolivas / inject-service-drupal-8.md
Last active Jul 28, 2020
Inject a service from the service container
View inject-service-drupal-8.md

Inject a Service in Drupal 8

Is a good practice to inject a service whenever is possible.

You can verify the service name by:

Looking at the Drupal Static Service Container wrapper class.

Reading the code on the Drupal Class you can find the httpClient method:

  /**