Skip to content

Instantly share code, notes, and snippets.

View wsydney76's full-sized avatar

Werner wsydney76

  • Munich, Germany
View GitHub Profile
@wsydney76
wsydney76 / storage.twig
Last active April 12, 2026 13:21
Inspect element database records (for education purpose only. Mostly AI generated, so there may be errors)
{#
displayAll — Entry point for recursive element inspection.
Renders the element itself, then walks its field layout to discover
child elements (Matrix/relation fields, ContentBlock fields, rich-text
fields) and recurses into each one, avoiding infinite loops via a
global "handled" set.
@param element Any Craft element (Entry, Asset, Product, Order, …)
@param config Optional overrides: type, heading, level, include
#}
@wsydney76
wsydney76 / craft-db-model-long.md
Last active April 13, 2026 08:36
Craft CMS 5 Content Storage Database Model (draft)

Craft CMS 5 Content Storage Database Model

The central elements table

In Craft CMS 5, the elements table serves as the foundational registry for every piece of content and content-like object in the system. Rather than storing the actual content itself, it provides a unified identity layer that all element types—such as entries, assets, categories, users, and nested entries—inherit from.

Each row in the elements table represents a single element instance and contains core, globally relevant metadata that is independent of site, field layout, or element-specific attributes. This includes the element’s unique ID, its fully qualified class type (which determines behavior and capabilities), and system-level state flags such as whether the element is enabled, archived, or soft-deleted. It also tracks lifecycle timestamps like creation and last update dates.

The key architectural role of this table is to decouple identity and lifecycle management from both localization and content storage. Site-specific da

<?php
namespace modules\temp\console\controllers;
use Craft;
use craft\console\Controller;
use craft\elements\Entry;
use yii\console\ExitCode;
/**
@wsydney76
wsydney76 / ACTIONS.md
Last active June 1, 2025 07:54
ACTIONS: Library functions for calling Craft CMS controllers from JavaScript

How to Use the Craft CMS Actions Twig Component

This documentation explains how to use the @extras/_actions.twig component in Craft CMS to call web controller actions via JavaScript and display success or error notices.


Component Overview

The Actions component allows you to make asynchronous requests to Craft CMS web controller actions and handle responses within your JavaScript code. Additionally, the component can display success or error notifications to users based on the outcome of the requests.

@wsydney76
wsydney76 / VideoService.php
Created January 15, 2025 10:32
Create an image from video asset, that can be used for <video poster="..."> or for index pages.
<?php
namespace modules\art\services;
use Craft;
use craft\base\Component;
use craft\elements\Asset;
use craft\fs\Local;
use craft\helpers\Console;
use Exception;
@wsydney76
wsydney76 / ContentController.php
Created October 25, 2024 15:12
Instant Craft CMS instant search
<?php
namespace modules\main\controllers;
use craft\elements\Entry;
use craft\web\Controller;
use yii\web\Response;
/**
* Content controller
@wsydney76
wsydney76 / MigrationController.php
Created March 19, 2024 18:17
Get fields in Craft CMS 5 with identical settings
<?php
// ....
public function actionConsolidateFieldsCandidates()
{
$signatures = [];
foreach (Craft::$app->getFields()->getAllFields() as $field) {
$signature = [
@wsydney76
wsydney76 / MigrationController.php
Last active April 24, 2024 05:04
Craft CMS CLI command that helps to detect errors after migration to Craft 5 (renamed entry types etc.)
<?php
namespace modules\main\console\controllers;
use Craft;
use craft\console\Controller;
use craft\elements\Entry;
use craft\helpers\Console;
use GuzzleHttp\Exception\GuzzleException;
use yii\console\ExitCode;
@wsydney76
wsydney76 / CollapseSidebarAsset.php
Last active February 29, 2024 19:28
Make sections of Craft 5 element indexes collapsible
<?php
namespace modules\main\web\assets\collapsesidebar;
use craft\web\AssetBundle;
/**
* Collapse Sidebar asset bundle
* Experimental!
*