Skip to content

Instantly share code, notes, and snippets.

View JPustkuchen's full-sized avatar

Julian Pustkuchen JPustkuchen

View GitHub Profile
@jehoshua02
jehoshua02 / .bash_alias_composer
Created October 4, 2012 05:32
Bash aliases for Composer
alias composer='php composer.phar'
alias composerinit='curl -s http://getcomposer.org/installer | php; composer init; echo composer.phar >> .gitignore'
alias composerdump='composer dumpautoload --optimize'
@jerbob92
jerbob92 / MyModuleMenuLink.php
Created October 27, 2015 13:31
Drupal 8 Derative Advanced Menu Link Example
@JPustkuchen
JPustkuchen / scrollToMiddle.js
Created August 14, 2019 12:42
jQuery: Scroll element to the middle of the viewport
(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 March 7, 2021 10:23
Drupal 8 CMS: Delete equal customized translation (source language string = target language string)

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!

@chales
chales / cache-warmer-3.sh
Last active January 19, 2022 14:01
A couple of simple options to parse sitemap.xml to warm the cache or for other actions such as generating memory_profiler checks.
# This can be added to your cron job to run right after Drupal's cron or combine them into a single command so
# that it automatically executes when the cron run completes.
wget -q http://www.example.com/sitemap.xml -O - | egrep -o "http://www\.example\.com[^<]+" | wget -q -i - -O /dev/null --wait 1
@juampynr
juampynr / mymodule.md
Last active July 16, 2022 23:41
Drupal 7 Database Updates tricks

This document contains a common database updates in Drupal 7 projects.

Change a field type from textarea to textfield (wipe out its data)

Let's suppose we want to change field_article_summary from text to textarea, but we do not care about loosing its current data.

Start by removing the field through the Admin Interface in your local environment. Then, add the field with the new configuration and recreate the feature where it was exported. Finally, add the following database update:

@Erikdekamps
Erikdekamps / add_translations.install
Last active June 6, 2023 07:40
Drupal 8 - Programmatically translate strings via hook_update_N()
/**
* 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');
@crittermike
crittermike / import.php
Last active August 11, 2023 10:39
Importing Drupal 8 config programmatically
<?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');
@WengerK
WengerK / README.md
Last active November 22, 2023 19:42
Drupal 8 - How to translate Config API

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
@jmolivas
jmolivas / inject-service-drupal-8.md
Last active December 26, 2023 20:21
Inject a service from the service container

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:

 /**