Skip to content

Instantly share code, notes, and snippets.

@onesixromcom
onesixromcom / mymodule.install
Created March 12, 2021 22:55
Create media entities from existing file fields. Drupal 7 to 8 (9) migration.
<?php
use Drupal\media\Entity\Media;
use Drupal\file\Entity\File;
/**
* Create media entities from existing file fields.
*/
function mymodule_update_8801() {
$converts = [
@onesixromcom
onesixromcom / transliterate.sh
Created December 26, 2021 00:23
Transliterate filenames in batch in shell
#!/bin/sh
# Rename utility.
if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
echo "usage: $(basename $0) FILE [...]"
echo
exit 0
fi
IFS=$'
@onesixromcom
onesixromcom / video-service-movie-download.sh
Created April 1, 2022 10:05
This script will download video from online video service website.
#!/bin/bash
# This script will download video from online video service website.
# sudo apt install html-xml-utils
# Usage ./video-service-movie-download.sh https://somewhere-online-movie.web/best-movie.html
if [ -z "$1" ]; then
echo "No url supplied. Please set collection name. (ex: https://somewhere-online-movie.web/best-movie.html)"
exit
fi
@onesixromcom
onesixromcom / bt.sh
Created February 9, 2023 13:24
Repair/Reconnect bluetooth headset and set a2dp profile
#!/bin/sh
sudo rfkill block bluetooth
sudo rfkill unblock bluetooth
sudo systemctl restart bluetooth
# Change MAC address to fit your device.
DEVICE_MAC='12:12:12:12:12:12'
CARD_ID=$(pactl list short cards | grep "module-bluez5-device.c" | awk '{ print $1 }')
# Should check here if card is available.
<?php
namespace Drupal\my_module\Normalizer;
use Drupal\commerce_product\Entity\ProductVariationInterface;
use Drupal\Core\TypedData\TypedDataInternalPropertiesHelper;
use Drupal\serialization\Normalizer\NormalizerBase;
/**
* Converts typed data objects to arrays.
@onesixromcom
onesixromcom / VariationCartNormalizer.php
Created June 14, 2023 08:59
VariationCartNormalizer.php with whitelisted fields for response
<?php
namespace Drupal\my_commerce\Normalizer;
use Drupal\commerce_product\Entity\ProductVariationInterface;
use Drupal\Core\TypedData\TypedDataInternalPropertiesHelper;
use Drupal\serialization\Normalizer\NormalizerBase;
/**
* Converts typed data objects to arrays.
<?php
namespace Drupal\my_module\Plugin\Field\FieldFormatter;
use Drupal\image\Plugin\Field\FieldFormatter\ImageFormatter;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Cache\Cache;
/**
* Plugin implementation of the 'image_default_fallback' formatter.
@onesixromcom
onesixromcom / readukrainianbooks_com-download.sh
Created November 8, 2023 20:31
readukrainianbooks.com downloader
#!/bin/bash
# store arguments in a special array
args=("$@")
URL=${args[0]}
# Check if link to page is present.
if [ -z "$URL" ]; then
echo "No url supplied. Please set collection name. (ex: https://readukrainianbooks.com/6340-faktor-cherchillja-jak-odna-ljudina-zminila-istoriju-boris-dzhonson.html)"
@onesixromcom
onesixromcom / booknet_ua.sh
Created November 20, 2023 23:07
booknet_ua FB2 downloader
#!/bin/bash
# Store arguments in a special array
args=("$@")
URL=${args[0]}
# Check if link to page is present.
if [ -z "$URL" ]; then
echo "No url supplied. Please set collection name. (ex: https://booknet.ua/reader/smttyar-b155659)"
@onesixromcom
onesixromcom / CustomOrderItemProduct.php
Created November 22, 2023 21:24
Negotiate products for Commerce Promo
<?php
namespace Drupal\my_module\Plugin\Commerce\Condition;
use Drupal\commerce\EntityUuidMapperInterface;
use Drupal\commerce\Plugin\Commerce\Condition\ConditionBase;
use Drupal\commerce_product\Plugin\Commerce\Condition\ProductTrait;
use Drupal\commerce\Plugin\Commerce\Condition\PurchasableEntityConditionInterface;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;