Add Elementor event loop preset library and separate releases
All checks were successful
WordPress release / release (push) Successful in 5s
Loop Builder release / release (push) Successful in 4s

This commit is contained in:
josh
2026-11-13 11:00:14 -05:00
parent db4747d85f
commit d15dce1e84
20 changed files with 3617 additions and 17 deletions

View File

@@ -0,0 +1,259 @@
<?php
namespace EventLabs\LoopBuilder;
use Elementor\Utils;
defined( 'ABSPATH' ) || exit;
final class Presets {
public static function families(): array {
return [
'classic' => __( 'Classic', 'eventlabs-loop-builder' ),
'minimal' => __( 'Minimal', 'eventlabs-loop-builder' ),
'modern' => __( 'Modern', 'eventlabs-loop-builder' ),
];
}
public static function layouts(): array {
return [
'grid' => __( 'Grid', 'eventlabs-loop-builder' ),
'list' => __( 'List', 'eventlabs-loop-builder' ),
'carousel' => __( 'Carousel', 'eventlabs-loop-builder' ),
];
}
public static function catalog(): array {
static $catalog;
if ( isset( $catalog ) ) {
return $catalog;
}
$catalog = [];
foreach ( self::recipes() as $family => $recipes ) {
foreach ( array_keys( self::layouts() ) as $layout ) {
foreach ( $recipes as $name => $recipe ) {
$catalog[ "$family-$layout-$name" ] = [
'title' => $recipe['title'],
'description' => $recipe['description'],
'family' => $family,
'layout' => $layout,
'recipe' => $name,
];
}
}
}
return $catalog;
}
public static function elements( string $slug ): array {
$tree = self::tree( $slug );
return $tree ? [ self::element( $tree, false ) ] : [];
}
public static function render( string $slug, Card $card ): string {
$tree = self::tree( $slug );
return $tree ? self::markup( $tree, $card ) : '';
}
public static function sample( string $slug ): string {
$tree = self::tree( $slug );
return $tree ? self::markup( $tree, null ) : '';
}
private static function recipes(): array {
static $recipes;
if ( isset( $recipes ) ) {
return $recipes;
}
$group = static fn( string $name, array $children ): array => [ 'classes' => 'ell-preset-' . $name, 'children' => $children ];
$photo = static fn( string $size = 'large' ): array => $group( 'media', [
[ 'image', [ 'show_placeholder' => 'yes', 'image_size' => $size ] ],
] );
$excerpt = static fn( int $words ): array => [ 'excerpt', [ 'excerpt_words' => $words ] ];
$recipes = [
'classic' => [
'program' => [
'title' => __( 'Program', 'eventlabs-loop-builder' ),
'description' => __( 'Wide photo, event details, and a button.', 'eventlabs-loop-builder' ),
'parts' => [
$photo(),
$group( 'body', [ 'categories', 'schedule', 'title', 'venue', $excerpt( 24 ), 'link' ] ),
],
],
'gazette' => [
'title' => __( 'Gazette', 'eventlabs-loop-builder' ),
'description' => __( 'Editorial headline with a framed photo and venue address.', 'eventlabs-loop-builder' ),
'parts' => [
$group( 'body', [ 'categories', 'title', 'schedule', $excerpt( 20 ), 'address', 'link' ] ),
$photo( 'medium_large' ),
],
],
'invitation' => [
'title' => __( 'Invitation', 'eventlabs-loop-builder' ),
'description' => __( 'Centered type with a date medallion and event details.', 'eventlabs-loop-builder' ),
'parts' => [
$group( 'body', [ 'date_badge', 'categories', 'title', 'venue', 'schedule', 'link' ] ),
],
],
'ticket' => [
'title' => __( 'Ticket', 'eventlabs-loop-builder' ),
'description' => __( 'Perforated date stub beside the title, venue, and price.', 'eventlabs-loop-builder' ),
'parts' => [
$group( 'rail', [ 'date_badge', 'cost' ] ),
$group( 'body', [ 'categories', 'title', 'schedule', 'venue', 'link' ] ),
],
],
],
'minimal' => [
'lineup' => [
'title' => __( 'Lineup', 'eventlabs-loop-builder' ),
'description' => __( 'Date marker, title, and venue in a compact row.', 'eventlabs-loop-builder' ),
'parts' => [
$group( 'rail', [ 'date_badge' ] ),
$group( 'body', [ 'title', 'time', 'venue', 'link' ] ),
],
],
'bulletin' => [
'title' => __( 'Bulletin', 'eventlabs-loop-builder' ),
'description' => __( 'Text-led card with a headline, schedule, and short description.', 'eventlabs-loop-builder' ),
'parts' => [
$group( 'body', [ 'categories', 'title', 'schedule', $excerpt( 19 ), 'link' ] ),
],
],
'snapshot' => [
'title' => __( 'Snapshot', 'eventlabs-loop-builder' ),
'description' => __( 'Small square photo beside the headline and schedule.', 'eventlabs-loop-builder' ),
'parts' => [
$photo( 'medium' ),
$group( 'body', [ 'title', 'schedule', 'venue' ] ),
],
],
'agenda' => [
'title' => __( 'Agenda', 'eventlabs-loop-builder' ),
'description' => __( 'Schedule strip above a simple title and location.', 'eventlabs-loop-builder' ),
'parts' => [
$group( 'strip', [ 'schedule' ] ),
$group( 'body', [ 'title', 'venue', 'address', 'link' ] ),
],
],
],
'modern' => [
'cover' => [
'title' => __( 'Cover', 'eventlabs-loop-builder' ),
'description' => __( 'Edge-to-edge photo with the title and schedule overlaid.', 'eventlabs-loop-builder' ),
'parts' => [
$photo(),
$group( 'body', [ 'categories', 'title', 'schedule', 'venue', 'link' ] ),
],
],
'split' => [
'title' => __( 'Split', 'eventlabs-loop-builder' ),
'description' => __( 'Photo and a dark detail panel with event actions.', 'eventlabs-loop-builder' ),
'parts' => [
$photo(),
$group( 'body', [
'categories', 'title', 'schedule', 'venue', $excerpt( 18 ),
$group( 'actions', [ 'link', 'share' ] ),
] ),
],
],
'panorama' => [
'title' => __( 'Panorama', 'eventlabs-loop-builder' ),
'description' => __( 'Photo with a floating date badge and a light details panel.', 'eventlabs-loop-builder' ),
'parts' => [
$group( 'hero', [ $photo(), $group( 'badge', [ 'date_badge' ] ) ] ),
$group( 'body', [ 'categories', 'title', 'schedule', 'venue', $group( 'actions', [ 'cost', 'link' ] ) ] ),
],
],
'studio' => [
'title' => __( 'Studio', 'eventlabs-loop-builder' ),
'description' => __( 'Bold text card with a color accent, schedule, and price.', 'eventlabs-loop-builder' ),
'parts' => [
$group( 'strip', [ 'categories', 'status' ] ),
$group( 'body', [ 'title', 'schedule', $excerpt( 22 ), 'organizer', $group( 'actions', [ 'cost', 'link' ] ) ] ),
],
],
],
];
return $recipes;
}
private static function tree( string $slug ): array {
$preset = self::catalog()[ $slug ] ?? null;
if ( ! $preset ) {
return [];
}
[ 'family' => $family, 'layout' => $layout, 'recipe' => $recipe ] = $preset;
return [
'classes' => "ell-preset ell-preset-family-$family ell-preset-layout-$layout ell-preset-style-$recipe",
'children' => self::recipes()[ $family ][ $recipe ]['parts'],
];
}
private static function field( string|array $node ): array {
return is_string( $node ) ? [ $node, [] ] : $node;
}
private static function element( string|array $node, bool $inner = true ): array {
$id = Utils::generate_random_string();
if ( isset( $node['children'] ) ) {
return [
'id' => $id, 'elType' => 'container', 'isInner' => $inner,
'settings' => [ 'content_width' => 'full', 'css_classes' => $node['classes'] ],
'elements' => array_map( self::element( ... ), $node['children'] ),
];
}
[ $key, $settings ] = self::field( $node );
return [
'id' => $id, 'elType' => 'widget', 'widgetType' => 'eventlabs-loop-field',
'settings' => [ 'field' => $key ] + $settings,
'elements' => [],
];
}
private static function markup( string|array $node, ?Card $card ): string {
if ( isset( $node['children'] ) ) {
$children = '';
foreach ( $node['children'] as $child ) {
$children .= self::markup( $child, $card );
}
return '' === $children ? '' : '<div class="' . esc_attr( $node['classes'] ) . '">' . $children . '</div>';
}
[ $key, $settings ] = self::field( $node );
return $card ? $card->field( $key, $settings ) : self::sample_field( $key, $settings );
}
private static function sample_field( string $key, array $settings ): string {
switch ( $key ) {
case 'image':
return '<figure class="ell-field ell-image"><span class="ell-preset-sample-photo" aria-hidden="true"></span></figure>';
case 'date_badge':
return '<span class="ell-field ell-date-badge"><span class="ell-date-month">' . esc_html__( 'Jul', 'eventlabs-loop-builder' )
. '</span><strong class="ell-date-day">18</strong><span class="ell-date-weekday">' . esc_html__( 'Sat', 'eventlabs-loop-builder' ) . '</span></span>';
case 'categories':
return '<div class="ell-field ell-categories"><span class="ell-chip">' . esc_html__( 'Live music', 'eventlabs-loop-builder' ) . '</span></div>';
case 'title':
return '<p class="ell-field ell-title">' . esc_html__( 'Music in the gardens', 'eventlabs-loop-builder' ) . '</p>';
case 'schedule':
return '<span class="ell-field ell-schedule">' . esc_html__( 'July 18 · 7:00 pm', 'eventlabs-loop-builder' ) . '</span>';
case 'link':
return '<span class="ell-field ell-link">' . esc_html__( 'View event', 'eventlabs-loop-builder' ) . '</span>';
}
$label = match ( $key ) {
'time' => __( '7:00 pm', 'eventlabs-loop-builder' ),
'venue' => __( 'Botanical Garden', 'eventlabs-loop-builder' ),
'address' => __( '24 Garden Lane', 'eventlabs-loop-builder' ),
'organizer' => __( 'Garden Arts Collective', 'eventlabs-loop-builder' ),
'excerpt' => wp_trim_words( __( 'An evening of live music among the garden paths and summer blooms.', 'eventlabs-loop-builder' ), $settings['excerpt_words'] ?? 25 ),
'cost' => __( 'Free', 'eventlabs-loop-builder' ),
'share' => __( 'Share', 'eventlabs-loop-builder' ),
'status' => __( 'Featured', 'eventlabs-loop-builder' ),
default => '',
};
return '' === $label ? '' : '<p class="ell-field ell-' . esc_attr( $key ) . '">' . esc_html( $label ) . '</p>';
}
}