Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Add extension events for the main relation widgets #1129

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 51 additions & 3 deletions modules/backend/behaviors/RelationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -394,25 +394,73 @@ public function initRelation($model, $field = null)

/*
* View widget
*
* @event relation.extendViewWidget
* Called when the relation viewWidget is created
*
* Example usage:
*
* $controller->bindEvent('relation.extendViewWidget', function (\Backend\Widgets\Lists|\Backend\Widgets\Form $widget, string $field, \Winter\Storm\Database\Model $model) {
* if ($field === 'myRelationField') {
* $widget->model->bindEvent('list.extendColumns', function ($widget) {
* $widget->addColumns([
* 'myNewColumn' => ['label' => 'My New Column'],
* ]);
* });
* }
* });
*/
if ($this->viewWidget = $this->makeViewWidget()) {
$this->controller->relationExtendViewWidget($this->viewWidget, $this->field, $this->model);
$this->controller->bindEvent('relation.extendViewWidget', [$this->controller, 'relationExtendViewWidget']);
$this->controller->fireEvent('relation.extendViewWidget', [$this->viewWidget, $this->field, $this->model], halt:true);
$this->viewWidget->bindToController();
}

/*
* Manage widget
*
* @event relation.extendManageWidget
* Called when the relation manageWidget is created
*
* Example usage:
*
* $controller->bindEvent('relation.extendManageWidget', function (\Backend\Widgets\Lists|\Backend\Widgets\Form $widget, string $field, \Winter\Storm\Database\Model $model) {
* if ($field === 'myRelationField') {
* $widget->model->bindEvent('model.form.filterFields', function ($widget, $fields, $context) {
* if (isset($fields->myFormField)) {
* $fields->myFormField->hidden = true;
* }
* });
* }
* });
*/
if ($this->manageWidget = $this->makeManageWidget()) {
$this->controller->relationExtendManageWidget($this->manageWidget, $this->field, $this->model);
$this->controller->bindEvent('relation.extendManageWidget', [$this->controller, 'relationExtendManageWidget']);
$this->controller->fireEvent('relation.extendManageWidget', [$this->manageWidget, $this->field, $this->model], halt:true);
$this->manageWidget->bindToController();
}

/*
* Pivot widget
*
* @event relation.extendPivotWidget
* Called when the relation pivotWidget is created
*
* Example usage:
*
* $controller->bindEvent('relation.extendPivotWidget', function (\Backend\Widgets\Form $widget, string $field, \Winter\Storm\Database\Model $model) {
* if ($field === 'myRelationField') {
* $widget->model->bindEvent('form.extendFields', function ($widget) {
* $widget->addFields([
* 'myNewPivotField' => ['label' => 'My New Pivot Field'],
* ]);
* });
* }
* });
*/
if ($this->manageMode === 'pivot' && $this->pivotWidget = $this->makePivotWidget()) {
$this->controller->relationExtendPivotWidget($this->pivotWidget, $this->field, $this->model);
$this->controller->bindEvent('relation.extendPivotWidget', [$this->controller, 'relationExtendPivotWidget']);
$this->controller->fireEvent('relation.extendPivotWidget', [$this->pivotWidget, $this->field, $this->model], halt:true);
$this->pivotWidget->bindToController();
}
}
Expand Down
Loading