Skip to content

Commit dc982b5

Browse files
Merge pull request #47 from 23gauravS/fixed-event-sevice-provider
Fixed EventServiceProvider and vite configuration
2 parents 1336577 + 87e74c2 commit dc982b5

File tree

11 files changed

+950
-663
lines changed

11 files changed

+950
-663
lines changed

docs/.vuepress/version-configs/2.1.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,13 @@ module.exports = [
4848
path: setVersionPrefix('packages'),
4949
collapsable: true,
5050
children: setVersionPrefix([
51+
['packages/create-package', 'Getting Started'],
5152
['packages/add-menu-in-admin', 'Admin Menu'],
5253
['packages/assets', 'Assets'],
5354
['packages/blade-components', 'Blade Components'],
5455
['packages/create-acl', 'Access Control List'],
5556
['packages/create-models', 'Models'],
5657
['packages/create-migrations', 'Migrations'],
57-
['packages/create-package', 'Getting Started'],
5858
['packages/controllers', 'Controllers'],
5959
['packages/datagrid', 'DataGrid'],
6060
['packages/layouts', 'Layouts'],

docs/.vuepress/version-configs/master.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,13 @@ module.exports = [
4848
path: setVersionPrefix('packages'),
4949
collapsable: true,
5050
children: setVersionPrefix([
51+
['packages/create-package', 'Getting Started'],
5152
['packages/add-menu-in-admin', 'Admin Menu'],
5253
['packages/assets', 'Assets'],
5354
['packages/blade-components', 'Blade Components'],
5455
['packages/create-acl', 'Access Control List'],
5556
['packages/create-models', 'Models'],
5657
['packages/create-migrations', 'Migrations'],
57-
['packages/create-package', 'Getting Started'],
5858
['packages/controllers', 'Controllers'],
5959
['packages/datagrid', 'DataGrid'],
6060
['packages/layouts', 'Layouts'],

docs/2.0/advanced/render-event.md

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,27 @@ The `view_render_event()` function in Krayin allows developers to inject content
1010

1111
To utilize the `view_render_event()` function effectively, follow these steps:
1212

13-
In this example `admin.contacts.persons.create.header.before` and `admin.contacts.persons.create.header.after` are custom event names that denote where content should be injected before and after the page-header section, respectively inside the `packages/Webkul/Admin/src/Resources/views/contacts/persons/create.blade.php` fie
13+
In this example, `admin.contacts.persons.edit.form_controls.before` and `admin.contacts.persons.edit.form_controls.after`
14+
are custom event names that denote where content should be injected before and after the form controls section, respectively inside the `packages/Webkul/Admin/src/Resources/views/contacts/persons/edit.blade.php` file.
15+
1416

1517
### Listening to Events
1618

1719
To handle these events and inject content dynamically, you need to listen to them in your application’s event system (typically in the `EventServiceProvider`).
1820

19-
Open your `EventServiceProvider.php` file located in `app/Providers` or similar directory.
21+
Create a file named `EventServiceProvider.php` inside your package’s `Providers` directory:
2022

2123
In the `boot()` method of your `EventServiceProvider`, add event listeners as follows:
2224

2325
```php
2426
<?php
2527

26-
namespace Webkul\Category\Providers;
28+
namespace Webkul\<PackageName>\Providers;
2729

2830
use Illuminate\Support\ServiceProvider;
2931
use Illuminate\Support\Facades\Event;
3032

31-
class CategoryServiceProvider extends ServiceProvider
33+
class EventServiceProvider extends ServiceProvider
3234
{
3335
/**
3436
* Register any events for your application.
@@ -37,17 +39,22 @@ class CategoryServiceProvider extends ServiceProvider
3739
*/
3840
public function boot()
3941
{
40-
Event::listen('admin.contacts.persons.create.header.before', function($viewRenderEventManager) {
41-
$viewRenderEventManager->addTemplate('path/to/before_content_template.blade.php');
42+
Event::listen('admin.contacts.persons.edit.form_controls.before', function($viewRenderEventManager) {
43+
$viewRenderEventManager->addTemplate('product::shop.quotes.create');
4244
});
4345

44-
Event::listen('admin.contacts.persons.create.header.after', function($viewRenderEventManager) {
45-
$viewRenderEventManager->addTemplate('path/to/after_content_template.blade.php');
46+
Event::listen('admin.contacts.persons.edit.form_controls.after', function($viewRenderEventManager) {
47+
$viewRenderEventManager->addTemplate('product::shop.quotes.view');
4648
});
4749
}
4850
}
4951
```
50-
Replace `'path/to/before_content_template.blade.php'` and `'path/to/after_content_template.blade.php'` with the actual paths to the Blade template files you want to inject.
52+
53+
In this example:
54+
55+
- We’re listening to the event: `admin.contacts.persons.edit.form_controls.before` amd `admin.contacts.persons.edit.form_controls.after`.
56+
- We're dynamically injecting the template: `product::shop.quotes.create` and `product::shop.quotes.view`, where `product` is the supposed namespace of the package and `shop.quotes.create` and `shop.quotes.view` are the view names.
57+
- The contents of that Blade file will be rendered at the position of the event in the DOM
5158

5259
:::warning
5360
Make sure that you have registered the **`EventServiceProvider`** in your own service provider.
@@ -63,6 +70,6 @@ Replace `'path/to/before_content_template.blade.php'` and `'path/to/after_conten
6370

6471
- `Integration`: Integrate this functionality carefully into your Krayin application to maintain coherence and readability of your codebase
6572

66-
- `Customization`: Customize event names (`'admin.contacts.persons.create.header.before'`, `'admin.contacts.persons.create.header.after'`) and template paths according to your specific application needs and structure.
73+
- `Customization`: Customize event names (`'admin.contacts.persons.edit.form_controls.before'`, `'admin.contacts.persons.edit.form_controls.after'`) and template paths according to your specific application needs and structure.
6774

6875
By following these steps, you can effectively leverage the `view_render_event()` function in Krayin to dynamically inject content into template sections, enhancing flexibility and customization options within your application.

0 commit comments

Comments
 (0)