https://github.com/cesurapp/pd-widget
Symfony 5 Simple Widget Bundle
https://github.com/cesurapp/pd-widget
bundle dashboard pdadmin symfony symfony4 widget-library
Last synced: about 1 year ago
JSON representation
Symfony 5 Simple Widget Bundle
- Host: GitHub
- URL: https://github.com/cesurapp/pd-widget
- Owner: cesurapp
- License: mit
- Created: 2018-01-28T12:43:11.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2024-05-14T12:22:09.000Z (about 2 years ago)
- Last Synced: 2025-03-28T16:43:37.754Z (about 1 year ago)
- Topics: bundle, dashboard, pdadmin, symfony, symfony4, widget-library
- Language: PHP
- Homepage:
- Size: 51.8 KB
- Stars: 11
- Watchers: 4
- Forks: 3
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# pdWidget Bundle
Flexible widget system for Symfony 5.
[](https://github.com/appaydin/pd-widget)
[](https://github.com/appaydin/pd-widget)
[](https://github.com/appaydin/pd-widget)
[](https://github.com/appaydin/pd-widget)
Installation
---
### Step 1: Download the Bundle
Open a command console, enter your project directory and execute the
following command to download the latest stable version of this bundle:
```console
$ composer require appaydin/pd-widget
```
This command requires you to have Composer installed globally, as explained
in the [installation chapter](https://getcomposer.org/doc/00-intro.md)
of the Composer documentation.
### Step 2: Enable the Bundle
With Symfony 4, the package will be activated automatically. But if something goes wrong, you can install it manually.
Then, enable the bundle by adding it to the list of registered bundles
in the `config/bundles.php` file of your project:
```php
['all' => true]
];
```
Add Widget Routing:
```yaml
#config/routes.yaml
# Widget Routing
widget:
resource: "@PdWidgetBundle/Resources/config/routing.yml"
```
Edit Doctrine Settings (`config/packages/doctrine.yaml`):
```yaml
doctrine:
orm:
resolve_target_entities:
Pd\WidgetBundle\Entity\UserInterface: App\Entity\User
```
UserInterface field, enter the class for the existing authorization system.
### Step 3: Settings Bundle (Optional)
You can specify the template for the widget container.
```yaml
# config/packages/framework.yaml
pd_widget:
base_template: '@PdWidget/widgetBase.html.twig'
return_route: 'admin_dashboard'
```
Create Your First Widget
---
#### Step 1: Create Widget Event Listener
Widgets work with Event. Create Widget with Event Listener
```php
getWidgetContainer();
// Add Widgets
$widgets
->addWidget((new Item('user_info', 3600)) // Add Cache Time or Default 3600 Second
->setGroup('admin')
->setName('widget_user_info.name')
->setDescription('widget_user_info.description')
->setTemplate('widgets/userInfo.html.twig')
//->setContent('pdWidget Text Content')
//->setRole(['USER_INFO_WIDGET'])
->setData(function () {
return ['userCount' => 5];
})
->setOrder(5)
);
}
}
```
#### Step 2: Create Widget Template
You can create a Twig template for the widget or can only use text content.
```twig
# templates/userInfo.html.twig
{% if widget.isActive %}
{% endif %}
```
#### Step 3: Create Widget Services:
```yaml
# config/services.yaml
# Load All Widgets
App\Widgets\:
resource: '../src/Widgets/*'
tags:
- { name: kernel.event_listener, event: widget.start, method: builder }
# Load Single Widget
App\Widgets\DashboardWidget:
tags:
- { name: kernel.event_listener, event: widget.start, method: builder }
```
Rendering Widgets
---
The creation process is very simple. You should use widget groups for widget creation.
```twig
# Render all 'admin' widget groups
{{ pd_widget_render('admin') }}
# Render selected widgets in 'admin' group
{{ pd_widget_render('admin', ['user_info']) }}
```