Skip to content

Instantly share code, notes, and snippets.

@SkyLundy
SkyLundy / DeepLEngine.php
Created February 8, 2025 20:01
Add a supported language to DeepL in Fluency that is not returned via the languages API endpoint
<?php
declare(strict_types=1);
namespace Fluency\Engines\DeepL;
use \InvalidArgumentException;
use Fluency\App\{ FluencyErrors, FluencyLocalization };
use Fluency\DataTransferObjects\{
EngineApiUsageData,
@SkyLundy
SkyLundy / user_switcher_example.php
Last active November 7, 2024 15:55
ProcessWire hooks and user switching example
<?php
declare(strict_types=1);
namespace ProcessWire;
require_once __DIR__ . './HookUtils/SwitchUser';
wire()->addHookAfter('Pages::saveReady(template=important_template)', function(HookEvent $e) {
$page = $e->arguments('page');
@SkyLundy
SkyLundy / UserSwitcher.php
Created November 6, 2024 22:20
A support class that switches between the current ProcesssWire user an another specified ProcessWire user
<?php
declare(strict_types=1);
namespace ProcessWire;
use InvalidArgumentException;
use RuntimeException;
use function ProcessWire\wire;
@SkyLundy
SkyLundy / hook_show_message_to_user_pagetree.php
Created November 6, 2024 22:04
Show a ProcessWire user a message when viewing the page tree
<?php
declare(strict_types=1);
namespace ProcessWire;
/**
* Show a message, warning, or error when the page tree is viewed
*/
@SkyLundy
SkyLundy / runtime_only_custom_action_field_markup.php
Last active November 10, 2024 17:22
FieldtypeRuntimeOnly field markup for a custom action
<?php
/**
* Create an interactive action button on admin page edit page very fast and easy
*/
// Optionally make rendering conditional if that's useful
$shouldShowTheButton = true;
?>
<?php if ($shouldShowTheButton): ?>
@SkyLundy
SkyLundy / runtime_only_action_hook.php
Created November 6, 2024 21:37
Hook that watches for specific GET variables before executing in the admin
<?php
declare(strict_types=1);
namespace ProcessWire;
use Exception;
/**
* Executes a custom action if a get parameter is present in the admin
@SkyLundy
SkyLundy / hook_convert_log_values_to_json.php
Created November 6, 2024 21:14
Automatically convert log content to JSON
<?php
declare(strict_types=1);
namespace ProcessWire;
use stdClass;
/**
* Automatically converts array or object log values to JSON
@SkyLundy
SkyLundy / pw_fieldtype_map_marker_alpine_tailwind_google_map.php
Last active November 8, 2024 17:48
Render a Google Map using a ProcessWire FieldtypeMapMarker field, Alpine JS, and Tailwind
<?php namespace ProcessWire;
/**
* Renders a Google Map
* Map is loaded via intersect when scrolling reaches threshold slightly above the rendered container element.
*/
$mapField = $page->your_fieldtype_marker_field_here;
$apiKey = $modules->get('FieldtypeMapMarker')->googleApiKey;
$address = null;
$mapMarker = 1;
$title = null;
@SkyLundy
SkyLundy / hook_use_separate_address_field_for_fieldtype_map_marker.php
Created November 6, 2024 20:32
Use a separate field to control the address for a FieldtypeMapMaker field
<?php
declare(strict_types=1);
namespace ProcessWire;
/**
* Sets the map address from the address subfields
*
* This uses a ProFields Custom Field called address with subfields to store the address
@SkyLundy
SkyLundy / hook_translate_all_fields_on_page_save.php
Created November 6, 2024 20:15
Translate all multilanguage fields on page save via UI or API
<?php
declare(strict_types=1);
namespace ProcessWire;
require_once __DIR__ . '/../HookUtils/TranslateField.php';
/**
* Automatically translates content for multilanguage fields when a page is saved