codeconsortium/ccdn-component-dashboard-bundle
Installation
composer require codeconsortium/ccdn-component-dashboard-bundle
Add to AppKernel.php:
new CodeConsortium\CCDNComponentDashboardBundle\CCDNComponentDashboardBundle(),
Enable Dashboard
Configure routing in app/config/routing.yml:
ccdn_component_dashboard:
resource: "@CCDNComponentDashboardBundle/Resources/config/routing.yml"
prefix: /
First Use Case Register a dashboard link from a custom bundle via a service tag:
# app/config/services.yml
services:
my_bundle.dashboard_integrator:
class: MyBundle\Dashboard\DashboardIntegrator
tags:
- { name: ccdn_component_dashboard.integrator }
Define the integrator class:
namespace MyBundle\Dashboard;
use CodeConsortium\CCDNComponentDashboardBundle\Dashboard\DashboardIntegratorInterface;
class DashboardIntegrator implements DashboardIntegratorInterface
{
public function getLinks()
{
return [
[
'label' => 'My Bundle',
'route' => 'my_route',
'icon' => 'glyphicon glyphicon-home',
'order' => 1,
],
];
}
}
Service Registration
Use ccdn_component_dashboard.integrator tag to register dashboard links from any bundle. Avoid coupling by keeping integrators lightweight and focused on link definitions.
Dynamic Link Generation Leverage Symfony’s dependency injection to fetch services dynamically:
public function getLinks()
{
$links = [];
foreach ($this->container->getParameter('my_config') as $item) {
$links[] = [
'label' => $item['name'],
'route' => 'item_route',
'icon' => $item['icon'],
];
}
return $links;
}
Conditional Rendering
Use isActive() in integrators to highlight current routes:
public function isActive($routeName)
{
return $routeName === 'my_active_route';
}
Grouping Links
Organize links into collapsible sections using the group key:
return [
[
'group' => 'Admin',
'links' => [
['label' => 'Users', 'route' => 'user_index'],
['label' => 'Settings', 'route' => 'settings_index'],
],
],
];
Twig Integration
Extend the default template (Resources/views/Dashboard/dashboard.html.twig) to customize rendering:
{% extends 'CCDNComponentDashboardBundle::dashboard.html.twig' %}
{% block dashboard_title %}{{ 'Custom Dashboard'|trans }}{% endblock %}
Asset Management
Override CSS/JS by extending the bundle’s asset paths in your assets.yml:
assets:
dashboard_styles:
inputs:
- { resource: "@CCDNComponentDashboardBundle/Resources/public/css/dashboard.css" }
- { resource: "path/to/your/custom.css" }
Authentication
Secure the dashboard route in security.yml:
security:
access_control:
- { path: ^/dashboard, roles: ROLE_USER }
Symfony Version Mismatch
The bundle targets Symfony 2.4 and PHP 5.4. Use a compatibility layer (e.g., symfony/symfony:2.4.*) if upgrading:
composer require symfony/symfony:2.4.*
Service Tag Misconfiguration
Ensure the tag name is exactly ccdn_component_dashboard.integrator (case-sensitive). Verify with:
php app/console debug:container --tag=ccdn_component_dashboard.integrator
Routing Conflicts
The default route (/dashboard) may clash with other bundles. Override in routing.yml:
ccdn_component_dashboard:
resource: "@CCDNComponentDashboardBundle/Resources/config/routing.yml"
prefix: /admin/dashboard # Custom prefix
Icon Dependencies The bundle relies on Bootstrap Glyphicons. If missing, add to your layout:
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-glyphicons.css">
Check Registered Integrators Dump integrators in a controller:
$integrators = $this->get('ccdn_component_dashboard.dashboard_integrator_collection');
dump($integrators->getIntegrators());
Log Link Generation
Enable debug mode and check app/logs/dev.log for errors during link compilation.
Template Overrides Clear cache after extending Twig templates:
php app/console cache:clear
Custom Dashboard Layout
Override the entire dashboard template by copying Resources/views/Dashboard/dashboard.html.twig to app/Resources/CCDNComponentDashboardBundle/views/Dashboard/.
Dynamic Integrator Loading
Implement DashboardIntegratorInterface to fetch links from external APIs:
public function getLinks()
{
$client = new \GuzzleHttp\Client();
$response = $client->get('https://api.example.com/links');
return json_decode($response->getBody(), true);
}
Event Listeners
Extend dashboard behavior via events (e.g., ccdn_component_dashboard.build):
services:
my_bundle.dashboard_listener:
class: MyBundle\EventListener\DashboardListener
tags:
- { name: kernel.event_listener, event: ccdn_component_dashboard.build, method: onBuild }
Localization Translate link labels using Symfony’s translation system:
return [
'label' => 'my_bundle.dashboard.link_label', // Translatable key
'route' => 'my_route',
];
Define translations in app/Resources/translations/messages.en.yml:
my_bundle:
dashboard:
link_label: "Custom Label"
How can I help you explore Laravel packages today?