diff --git a/README.md b/README.md
index 00a5972..c64afd4 100644
--- a/README.md
+++ b/README.md
@@ -1,5 +1,7 @@
# ObHighchartsBundle
+* Updated to work with Symfony 7
+
`ObHighchartsBundle` eases the use of highcharts to display rich graphs and charts in your Symfony application by
providing Twig extensions and PHP objects to do the heavy lifting. The bundle uses the excellent JS library
[Highcharts](http://www.highcharts.com).
@@ -10,7 +12,7 @@ DRY out your chart code by writing it all in PHP!
[](https://packagist.org/packages/ob/highcharts-bundle)
[](https://scrutinizer-ci.com/g/marcaube/ObHighchartsBundle/)
[](https://scrutinizer-ci.com/g/marcaube/ObHighchartsBundle/)
-[](https://insight.sensiolabs.com/projects/4cf81d53-f79c-478e-a172-ac2f60b55f02)
+
## Documentation
@@ -19,7 +21,7 @@ DRY out your chart code by writing it all in PHP!
* [Usage](Resources/doc/usage.md)
* [Cookbook](Resources/doc/cookbook.md)
* [Highcharts API](http://api.highcharts.com/highcharts)
-
+* [SonataAdmin integration](Resources/doc/sonataadmin.md)
## Contributing
diff --git a/Resources/doc/installation.md b/Resources/doc/installation.md
index 8cf3e0c..24cf13c 100644
--- a/Resources/doc/installation.md
+++ b/Resources/doc/installation.md
@@ -1,6 +1,6 @@
# Installation
-1. Run `composer require ob/highcharts-bundle`
+1. Run `composer require mpescador1/highcharts-bundle`
2. Register the bundle in your `app/AppKernel.php`:
diff --git a/Resources/doc/sonataadmin.md b/Resources/doc/sonataadmin.md
new file mode 100644
index 0000000..4de27dc
--- /dev/null
+++ b/Resources/doc/sonataadmin.md
@@ -0,0 +1,196 @@
+# Sonata Admin Integration
+
+Requirements
+- SonataAdminBundle (4.x)
+- ObHighChartsBundle (https://github.com/mpescador1/ObHighchartsBundle)
+
+## Render Template
+
+The template uses in this example reder a block of sonata Admin with the defined chart.
+
+templates/Form/chart_block_single.html.twig
+```twig
+{% extends sonata_block.templates.block_base %}
+{% block block %}
+
+
+
+
+{% endblock %}
+```
+
+## Sonata Admin Yaml Config
+
+We add the block in sonata_admin.blocks and register de block in sonata_blocks.blocks.
+The registered services are below in the services.yaml file.
+
+config/packages/sonata_admin.yaml
+```yaml
+sonata_admin:
+ dashboard:
+ ....
+ blocks:
+ ....
+ - { type: admin.block.service.registrations_chart, position: left }
+sonata_block:
+ blocks:
+ admin.block.service.registrations_chart: #This is the chart block - RegistrationsChartBlockService (below)
+ contexts: [ admin ]
+```
+## Block definition
+
+We define the block service to show in the dashboard. We can add any injected class to build the block.
+
+In this case we inject de ChartService (below) to get the Hightchart object.
+
+src/Block/Service/RegistrationsChartService.php
+```php
+pool = $pool;
+ $this->chartBuilder = $chartBuilder;
+ }
+ /**
+ * {@inheritdoc}
+ */
+ public function execute(BlockContextInterface $blockContext, ?Response $response = null): Response
+ {
+
+ $end = new \DateTime();
+ $start = new \DateTime('7 days ago');
+
+ $chart = $this->chartBuilder->getRegistrationsChart($start, $end);
+
+ return $this->renderPrivateResponse($blockContext->getTemplate(), array(
+ 'chart' => $chart,
+ 'block' => $blockContext->getBlock(),
+ 'settings' => $blockContext->getSettings(),
+ ), $response);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getName()
+ {
+ return 'Users Chart';
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function configureSettings(OptionsResolver $resolver): void
+ {
+ $resolver->setDefaults(array(
+ 'title' => 'Users',
+ 'summaries' => false,
+ 'template' => 'Form/chart_block_single.html.twig',
+ ));
+ }
+}
+```
+## Service definition
+
+This file do the magic, call the HightChart class to build our chart.
+I inject the entity manager because, in many cases, the chart will be populated with database data.
+
+In this example was not use at all.
+
+src/Service/ChartService.php
+```php
+em = $em;
+ }
+
+ public function getRegistrationsChart(\DateTime $start,\DateTime $end){
+ $ob = new Highchart();
+ $ob->chart->renderTo('piechart');
+ $ob->title->text('Browser market shares at a specific website in 2010');
+ $ob->plotOptions->pie(array(
+ 'allowPointSelect' => true,
+ 'cursor' => 'pointer',
+ 'dataLabels' => array('enabled' => false),
+ 'showInLegend' => true
+ ));
+ $data = array(
+ array('Firefox', 45.0),
+ array('IE', 26.8),
+ array('Chrome', 12.8),
+ array('Safari', 8.5),
+ array('Opera', 6.2),
+ array('Others', 0.7),
+ );
+ $ob->series(array(array('type' => 'pie','name' => 'Browser share', 'data' => $data)));
+ return $ob;
+ }
+}
+```
+## Services configuration
+
+We need configure the services injecting the diferent services as shown below.
+
+config/services.yaml
+```yaml
+services:
+ ....
+ admin.block.service.chart:
+ class: App\Service\ChartService
+ arguments: ['@doctrine.orm.entity_manager']
+ public: true
+ admin.block.service.registrations_chart:
+ class: App\Block\Service\RegistrationsChartService
+ arguments:
+ - "@twig"
+ - "@sonata.admin.pool"
+ - "@admin.block.service.chart"
+ tags:
+ - { name: sonata.block }
+ public: true
+ ....
+```
diff --git a/composer.json b/composer.json
index 19e1b77..fc6b13a 100644
--- a/composer.json
+++ b/composer.json
@@ -1,28 +1,31 @@
{
- "name": "ob/highcharts-bundle",
+ "name": "mpescador1/highcharts-bundle",
"type": "symfony-bundle",
+ "version": "1.8",
"description": "Symfony Bundle that ease the use of highcharts to display rich graph and charts in your app",
"keywords": ["symfony", "charting", "charts", "highcharts", "chart", "graph", "graphs", "ob", "marcaube"],
- "homepage": "https://github.com/marcaube/ObHighchartsBundle",
+ "homepage": "https://github.com/mpescador1/ObHighchartsBundle",
"license": "MIT",
"authors": [
{
"name": "Marc Aubé"
+ },{
+ "name": "Miguel Angel Pescador Santirso"
}
],
"require": {
- "php": "^7.2",
- "symfony/http-kernel": "^4.4 || ^5.0",
- "symfony/dependency-injection": "^4.4 || ^5.0",
- "symfony/config": "^4.4 || ^5.0",
- "symfony/yaml": "^4.4 || ^5.0",
+ "php": "^8.3",
+ "symfony/http-kernel": "^6.4|^7",
+ "symfony/dependency-injection": "^6.4|^7",
+ "symfony/config": "^6.4|^7",
+ "symfony/yaml": "^6.4|^7",
"twig/twig": "^2.10 || ^3.0",
"laminas/laminas-json": "^3.1"
},
"require-dev": {
- "symfony/phpunit-bridge": "^4.4 || ^5.0",
- "symfony/framework-bundle": "^4.4 || ^5.0",
+ "symfony/phpunit-bridge": "^4.4 || ^5.0 || ^6 || ^7",
+ "symfony/framework-bundle": "^4.4 || ^5.0 || ^6 ||^7",
"nyholm/symfony-bundle-test": "^1.6.1"
},
"autoload": {