linderp / sulu-base-bundle
Helper classes and functions for sulu
Package info
github.com/pascallinder/SuluBaseBundle
Type:symfony-bundle
pkg:composer/linderp/sulu-base-bundle
Requires
- php: ^8.2
- sulu/sulu: ^3.0.8
- symfony/config: ^6.2 | ^7.0
- symfony/dependency-injection: ^6.2 | ^7.0
- symfony/framework-bundle: ^6.2 | ^7.0
- symfony/http-foundation: ^6.2 | ^7.0
- symfony/http-kernel: ^6.2 | ^7.0
- symfony/intl: ^6.2 | ^7.0
- symfony/security-core: ^6.4 | ^7.1
- symfony/translation: ^6.2 | ^7.0
- twig/twig: ^3.0
Requires (Dev)
- phpunit/phpunit: ^9.6
README
Shared Sulu CMS utilities for admin CRUD scaffolding, locale-aware repositories/controllers, and custom admin field types. Use this bundle from your app code to avoid reimplementing standard Sulu admin patterns.
What This Bundle Provides
- Admin CRUD base:
Admin/AdminCrud.phpplus config value objects for list/form/navigation setup. - Enable toggle:
Admin/AdminEnableToggle.php+Controller/Admin/EnableSwitch.phpfor standard on/off actions. - Locale-aware stack:
Entity/LocaleTrait.php,Repository/LocaleRepositoryUtil.php, andController/Admin/LocaleController.php. - List builder helper:
Common/DoctrineListRepresentationFactory.phpfor paginated list responses. - Doctrine resource loader:
Content/AbstractEntityResourceLoader.phpcentralizes enabled-entity loading, locale setup, and configured property mapping for Sulu smart content. - Content types:
Content/Types/*registered inResources/config/services.yaml. - Theme-aware Twig colors:
theme_color(value, inheritFallback)renders the two-color picker value as CSSlight-dark(). - Admin React fields:
Resources/js/src/components/content/types/*registered inResources/js/src/app.js.
Render Theme Colors in Twig
Use the theme_color function for values from color_picker_custom. The browser picks the matching value from the document's color-scheme:
<section style="background-color: {{ theme_color(content.bgColor) }}"> <h2 style="color: {{ theme_color(content.textColor) }}">{{ content.title }}</h2> </section>
inherit is represented as currentColor by default, which is valid inside CSS light-dark() for text, borders, fills, strokes, and shadows. Pass a property-specific replacement as the optional second argument for backgrounds and other properties:
<div style="background-color: {{ theme_color(content.underlayColor, 'transparent') }}"></div>
Quick Start: Add a New Admin CRUD
- Admin class (extend
AdminCrud):- Implement
define()usingAdminCrudConfig+AdminCrudNavigationConfig+AdminCrudListConfig+AdminCrudFormConfig. - Implement
AdminEnableToggleif the entity has anenabledflag.
- Implement
- Controller (extend
BaseControllerorLocaleController):- Implement
getDataForEntity(),mapDataToEntity(),load(),create(),save(),remove(). - Use
EnableSwitchtrait if you added the enable toggle.
- Implement
- Repository:
- Extend
BaseRepositoryUtilfor plain entities orLocaleRepositoryUtilfor localized entities. - For
LocaleRepositoryUtil, implementappend()andappendSortByJoins()for list/smart content.
- Extend
Example: Minimal Admin Definition
final class EventAdmin extends AdminCrud { public static function define(): AdminCrudConfig { return new AdminCrudConfig( 'events', new AdminCrudNavigationConfig('app.events', 10, 'su-calendar'), new AdminCrudListConfig('app.events', 'events', 'app.events_list'), new AdminCrudFormConfig('title', 'app.events_add', 'app.events_edit', 'event_form') ); } }