Installation:
composer require alpixel/cmsbundle
Ensure SonataAdminBundle and its dependencies (sonata-project/*) are installed (listed in composer.json).
Enable the Bundle:
Add to config/bundles.php:
Alpixel\CMSBundle\AlpixelCMSBundle::class => ['all' => true],
First Use Case:
Alpixel\CMSBundle\Admin\AbstractAdmin for your CMS entities (e.g., pages, articles).
Example:
use Alpixel\CMSBundle\Admin\AbstractAdmin;
class PageAdmin extends AbstractAdmin {
protected $baseRouteName = 'page';
protected $baseRoutePattern = 'page';
}
services.yaml:
services:
App\Admin\PageAdmin:
tags: [sonata.admin]
Key Configs:
config/packages/lunetics_locale.yaml (required for multilingual support).Alpixel\SEOBundle via config/packages/alpixel_seo.yaml.Alpixel\MediaBundle for file uploads (configured in config/packages/alpixel_media.yaml).First Route:
Access the admin panel at /admin (default route). The bundle integrates with Sonata’s admin dashboard.
Entity Management:
pixassociates/sortable-behavior-bundle for hierarchical content (e.g., nested pages).
Example entity:
use Pix\SortableBehavior\SortableTrait;
class Page {
use SortableTrait;
// ...
}
isDraftable() in AbstractAdmin).Multilingual Content:
happyr/translation-bundle or jms/translation-bundle for locale-specific fields.
Example admin field:
$fieldDescription = $this->getTranslationField('description', 'text', [
'template' => 'AlpixelCMSBundle:Admin:Field:translation.html.twig',
]);
SEO Optimization:
Alpixel\SEOBundle to auto-generate meta titles/descriptions from entity fields.
Example:
// In your Admin class
public function configureRoutes(RouteConfiguration $configuration) {
$configuration->add('seo', $this->getRouterIdParameter() . '/seo');
}
Media Handling:
Alpixel\MediaBundle for file/image uploads. Link media to entities via Sonata’s AssociationType.
Example field:
$formMapper->add('image', 'sonata_type_media', [
'provider' => 'sonata.media.provider.file',
]);
Routing:
jms/i18n-routing-bundle for locale-aware URLs.
Example route:
# config/routes.yaml
page_show:
path: /{_locale}/page/{slug}
defaults: { _controller: 'App\Controller\PageController::show' }
requirements:
_locale: %app.supported_locales%
Blocks and Layouts:
sonata-block-bundle.
Example block service:
services:
app.block.service.page_list:
class: App\Block\PageListBlock
tags: [sonata.block]
templates/AlpixelCMSBundle/ (e.g., Admin/Field/translation.html.twig).// src/EventListener/SitemapListener.php
class SitemapListener {
public function onKernelRequest(GetResponseEvent $event) {
// Modify sitemap generation logic
}
}
Register in services.yaml:
services:
App\EventListener\SitemapListener:
tags: [kernel.event_listener, kernel.request]
white_label feature to customize the admin UI (e.g., logos, colors). Configure in config/packages/alpixel_cms.yaml:
alpixel_cms:
white_label:
logo: 'bundles/acms/images/logo.png'
name: 'My CMS'
Locale Handling:
lunetics_locale-bundle can break multilingual features.config/packages/lunetics_locale.yaml includes:
lunetics_locale:
default_locale: en
supported_locales: en|fr|de
LocaleNotFoundException if translations fail to load.Sonata Admin Version Mismatch:
^3.0. Using ~2.0 may cause errors.composer.json:
"sonata-project/admin-bundle": "^3.0"
Draft Feature Quirks:
isDraftable() method isn’t implemented.isDraftable() in your AbstractAdmin:
protected function isDraftable() {
return true;
}
Sitemap Generation:
getRoute() method returns a valid route:
public function getRoute() {
return 'page_show';
}
Media Provider Conflicts:
Alpixel\MediaBundle may conflict with other media bundles (e.g., sonata-media-bundle).config/packages/alpixel_media.yaml:
alpixel_media:
providers:
file: sonata.media.provider.file
Translation Bundle Conflicts:
jms/translation-bundle and happyr/translation-bundle can cause conflicts.happyr/translation-bundle:
happyr_translation:
default_locale: en
locales: [en, fr, de]
Admin Panel Issues:
php bin/console cache:clear
php bin/console sonata:admin:debug
Database Migrations:
php bin/console doctrine:migrations:migrate
sortable_behavior and translatable extensions are applied to entities.CKEditor Configuration:
egeloen/ckeditor-bundle is configured:
egeloen_ckeditor:
editor: ckeditor
config: {}
Event Debugging:
public function onKernelRequest(GetResponseEvent $event) {
dump($event->getRequest()->attributes->all());
}
Custom Admin Classes:
Alpixel\CMSBundle\Admin\AbstractAdmin to add custom logic (e.g., prePersist hooks):
protected function prePersist($object) {
$object->setCreatedAt(new \DateTime());
}
Dynamic Forms:
sonata_type_model_list for dynamic entity selection:
$formMapper->add('parent', 'sonata_type_model_list', [
'by_reference' => false,
'property' => 'title',
'model_manager' => $this->getModelManager(),
'class' => 'App\Entity\Page',
]);
API Endpoints:
Serializer or ApiPlatform. Example:
# config/packages/api_platform.yaml
api_platform:
formats:
jsonld: ['application/ld+json']
json: ['application/json']
patch_formats:
json
How can I help you explore Laravel packages today?