Skip to content

Instantly share code, notes, and snippets.

Avatar

Julian Pustkuchen JPustkuchen

View GitHub Profile
@JPustkuchen
JPustkuchen / drupal-active-config-key-exists.php
Last active February 9, 2022 17:52
Check if configuration with given name exists (like "has()") in active configuration.
View drupal-active-config-key-exists.php
<?php
/**
* Helper function / example code to check
* if the given configuration (by name)
* exists in active configuration.
* @param string $configName
* The id of the configuration to check.
*
* @return boolean
@JPustkuchen
JPustkuchen / drupal-delete-entity-type-bundle.php
Created February 9, 2022 15:27
Drupal 8 / 9: Delete Entity Bundle ($configEntityBildText)
View drupal-delete-entity-type-bundle.php
<?php
// Delete paragraph example_bundle bundle!
/** @var \Drupal\Core\Config\Entity\ConfigEntityStorage $entity_storage */
$entity_storage = \Drupal::entityTypeManager()->getStorage('paragraphs_type');
$configEntityBildText = $entity_storage->load('example_bundle');
$configEntityBildText->delete();
?>
View gist:afc78ed7329969aa206e596ccaa4101d
; Personal Configuration for https://github.com/DanTup/BrowserSelector
; See https://julian.pustkuchen.com/en/open-specific-browser-url-open-clickup-brave
; Default browser is first in list
; Use `{url}` to specify UWP app browser details
[browsers]
ff = C:\Program Files\Mozilla Firefox\firefox.exe
chrome = C:\Program Files (x86)\Google\Chrome\Application\chrome.exe
edge = microsoft-edge:{url}
@JPustkuchen
JPustkuchen / autoreload.js
Last active June 25, 2021 16:18
JavaScript jQuery Page Auto Reload Timer with enable / disable checkbox
View autoreload.js
<script>
$( document ).ready(function() {
window.setInterval(function() {
if($('#autoreload').is(':checked')){
if(('#autoreload-wrapper .countdown').length && (parseInt($('#autoreload-wrapper .countdown').text()) <= 1)){
// Reload every 60 seconds without sending POST again:
window.location.href = window.location.href;
} else {
$('#autoreload-wrapper .countdown').text(parseInt($('#autoreload-wrapper .countdown').text()) - 1);
}
View scrollToViewport.js
(function($) {
/**
* jQuery function to scroll the element into the viewport with
* typical options and menu bar exclusion.
*/
$.fn.scrollToViewport = function(options) {
var settings = $.extend({
/**
* The scroll duration.
*/
@JPustkuchen
JPustkuchen / reload-on-orientation-change-xbrowser.js
Created June 2, 2020 13:31
JavaScript X-Browser reload on orientation change using MatchMedia
View reload-on-orientation-change-xbrowser.js
// RELOAD ON ORIENTAtiON CHANGE:
var mqp = window.matchMedia("(orientation: portrait)");
// Detect initial orientation
var is_portrait = mqp.matches;
var isFullscreen = document.fullscreenElement || document.mozFullScreenElement || document.webkitFullscreenElement || document.msFullscreenElement;
// Add a media query change listener
mqp.addListener(function(m) {
// Check if orientation changed:
if(m.matches) {
// Changed to portrait
@JPustkuchen
JPustkuchen / scrollToMiddle.js
Created August 14, 2019 12:42
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 / CustomBreadcrumbBlock.php
Last active August 8, 2019 07:44
Drupal 8 Custom Breadcrumb block printing the 2 top level breadcrumbs including page title
View CustomBreadcrumbBlock.php
<?php
namespace Drupal\custom_breadcrumb_block\Plugin\Block;
use Drupal\Core\Block\BlockBase;
use Drupal\Core\Breadcrumb\BreadcrumbBuilderInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Routing\RouteMatchInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Core\Controller\TitleResolverInterface;
@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)
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!

@JPustkuchen
JPustkuchen / drupal8-settings-devel-kint-maxLevels-override.md
Last active May 8, 2023 16:39
Drupal 8 kint set maxLevels in settings.php to prevent out of memory
View drupal8-settings-devel-kint-maxLevels-override.md

Currently devel doesn't allow to override KINT configuration in a clean way. Hopefully this will be possible some day via setting in UI or drupal setting override in settings.php Until this happens you may use this dirty trick in settings.php to override the setting.

See issues:

Simply copy this into your settings.php and change the value accordingly (Kint default: 7)