Skip to content

Instantly share code, notes, and snippets.

View megclaypool's full-sized avatar

Meg Claypool megclaypool

View GitHub Profile

In Drupal 9.4, jQuery.once() has been removed. However, there's a Javascript function, once(), that can replace it with a little rewriting:

var closeButton = $("#off-canvas .offcanvas__close");
      
closeButton.once().on("click", function () {
  closeOffCanvas();
});

once takes 3 arguments: 1. Arbitrary key, 2. CSS selector, 3. context

❗When you install qBittorrent, make sure to install NordVPN first. Then you want to make sure to limit qBittorrent so it will only use NordVPN’s connection (saving you from getting in trouble if you forget to turn on the VPN before torrenting).

  1. Make sure NordVPN is disconnected
  2. In Terminal, type ifconfig
  3. Connect NordVPN
  4. In Terminal, type ifconfig again
  5. Find the connection that’s been added (in my case, it was utun4)
  6. In qBittorrent, open the preferences and click on Advanced
  7. Set the Network Interface to your NordVPN connection and click OK.
  8. Test it by heading over to the Ubuntu alternative downloads page (these files are totally legal to download, so if something goes wrong you won’t get in trouble)
  9. Pick a few versions of Ubuntu to download, and load the (old fashioned non-magnet 😛 ) torrent files into qBittorrent

To list the fonts that are available on your system, run the following command in the terminal:

system_profiler -json SPFontsDataType | grep \"family | sort | uniq

This will show the name you need to supply to VSCode to use the font.

Any font that is activated on the Mac will be available to VSCode. I am using a patched font, and by applying the name that is shown using the command above, I was able to use it in VSCode.

@megclaypool
megclaypool / themename.theme
Last active November 9, 2023 20:20
[Load code into head of Drupal site] On NIJC the client wanted to load a hotjar script into the head of the document (which then calls another script and attaches it to the head). However, they only wanted the script to load on certain pages. Here's
/**
* implements hook_page_attachments_alter
* @param array $attachments
*/
//thanks: https://www.drupal.org/theme-guide/8/assets#configurable-javascript
function gavias_tico_subtheme_page_attachments_alter(array &$attachments) {
/**
* Hotjar tracking code for NIJC
*/

[Fix for Prettier Error: Unexpected doc.type 'concat']

As of 10-30-2023, the Prettier Melody plugin that allows Prettier to work on .twig files hasn't been updated in ages. Meanwhile, Prettier has been updated to 3.0, which (it turns out) was a breaking change as far as the Twig Melody plugin is concerned.

The Solution

Downgrade your Prettier to 2.8 using npm install prettier@2.8

@megclaypool
megclaypool / filter.php
Last active September 22, 2023 22:33
[Add a submenu toggle button to WordPress menu items with children] Here are the PHP code and JS that will let you create a toggle and cause it to actually toggle classes and aria-expanded attributes. Use styles to show and hide the submenu, and to
// Add this to an appropriate php file in your theme
// Change the function name and the "visually-hidden" class name as appropriate
// Note that this is a WireMedia theme, so is using their icons function.
// You can use css to create the chevron instead
require_once 'icons.php';
function j40a_parent_menu_item_buttons($output, $item, $depth, $args) {
if (in_array('menu-item-has-children', $item->classes, true)) {
@megclaypool
megclaypool / RenderMenu.php
Last active August 23, 2023 01:16
These are set up as Twig functions in a module in the NIJC site. This might be pretty sweet to import as a Radicati Drupal module?
<?php
/**
* @file
* Contains \Drupal\custom_blocks_forms\Twig\KintExtension.
*/
namespace Drupal\custom_blocks_forms\Twig;
use Drupal;
@megclaypool
megclaypool / config-files.md
Last active May 20, 2023 06:06
[Drupal Import and delete config files programmatically (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
 *
@megclaypool
megclaypool / taxonomy-info.md
Last active May 20, 2023 06:00
[Drupal create and delete taxonomy and terms programmatically (PHP)]
use Drupal\taxonomy\Entity\Vocabulary;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\field\Entity\FieldConfig;
use Drupal\taxonomy\Entity\Term;

/**
 * Implements hook_install().
 */
function radicati_social_install() {