Skip to content

Instantly share code, notes, and snippets.

@vistar
vistar / d9-remove-wrong-equal-translations-l10n.md
Last active April 23, 2022 15:54 — forked from JPustkuchen/d8-remove-wrong-equal-translations-l10n.md
Drupal 9 CMS: Delete equal customized translation (source language string = target language string)

Drupal 9 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!

<?php
namespace Drupal\projects\Plugin\Block;
use Drupal\Component\Serialization\Json;
use Drupal\Core\Block\Annotation\Block;
use Drupal\Core\Block\BlockBase;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
function encryptData($data) {
$plainText = json_encode($data);
$bytesToBeEncrypted = $plainText;
$passwordBytes = utf8_encode("p@SSword");
$passwordBytes = hash('sha256', $passwordBytes, true);
$saltBytes = array(1,2,3,4,5,6,7,8);
$saltBytesstring = "";
@andypost
andypost / docker-compose.yaml
Last active August 8, 2022 05:49
Drupal 8 template for core dev + chromium
version: "2.1"
services:
php:
image: skilldlabs/php:8-fpm
container_name: core8
restart: always
working_dir: /var/www/html/web
volumes:
<?php
/**
* @When I switch to the frame by selector "[title=:arg1]"
*/
public function switchToIFrameFromSelector($iframeSelector) {
$function = <<<JS
(function(){var iframe = document.querySelector("$iframeSelector");iframe.name = "iframeToSwitchTo";})()
JS;
try {
@signalpoint
signalpoint / example.php
Last active July 16, 2022 23:41
Drupal 8 Set Message Example
<?php
// The drupal_set_message() function is being deprecated!
// @see https://api.drupal.org/api/drupal/core%21includes%21bootstrap.inc/function/drupal_set_message/8.5.x
// > Deprecated in Drupal 8.5.0 and will be removed before Drupal 9.0.0.
// > Use \Drupal\Core\Messenger\MessengerInterface::addMessage() instead.
// In some custom code.
\Drupal::messenger()->addMessage('Say something else');
@clrockwell
clrockwell / PromotionAdvanced.php
Created December 6, 2017 21:50
commerce_order_report plugin
<?php
namespace Drupal\scholarrx_reports\Plugin\Commerce\ReportType;
use Drupal\commerce_order\Adjustment;
use Drupal\commerce_order\Entity\OrderInterface;
use Drupal\commerce_order\Entity\OrderItemInterface;
use Drupal\commerce_promotion\Entity\CouponInterface;
use Drupal\commerce_promotion\Entity\Promotion;
use Drupal\commerce_reports\Annotation\CommerceReportType;
@jmolivas
jmolivas / ._README.md
Last active January 2, 2018 15:57
Basic docker configuration for drupal projects

Basic docker configuration for drupal projects

Extra steps

  1. If not using DrupalConsole you will need to add the vlucas/phpdotenv dependency to load the .env file. You can do that using composer:
composer require vlucas/phpdotenv
  1. Add the TRAEFIK_HOST value to /etc/hosts
@luksak
luksak / CartEventSubscriber.php
Last active October 19, 2017 18:14
Display message if order total is below a certain amount such as to get free shipping after adding products to the cart and when viewing the cart page.
<?php
namespace Drupal\MODULE\EventSubscriber;
use Drupal\commerce_order\Entity\Order;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Drupal\commerce_cart\Event\CartEntityAddEvent;
use Drupal\commerce_cart\Event\CartEvents;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
@luksak
luksak / CustomShippingInformation.php
Created October 8, 2017 13:19
Commerce shippping pane that automatically chooses a shipping method without providing a UI for the cutomer
<?php
namespace Drupal\MODULE\Plugin\Commerce\CheckoutPane;
use Drupal\commerce_shipping\Entity\ShipmentInterface;
use Drupal\commerce_shipping\Entity\ShippingMethod;
use Drupal\commerce_shipping\Plugin\Commerce\CheckoutPane\ShippingInformation;
use Drupal\Core\Entity\Entity\EntityFormDisplay;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;