Skip to content

Added label panel property for customize #150

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,3 +169,11 @@ You can modify the default index separator using the separator() method when you
```php
NestedForm::make('Posts')->separator('\'),
```

# Modify default label of panel

You can modify default label of panel (Update Related :resource) to any custom. Pass name of label as the fourth argument of the constructor.

```php
NestedForm::make('Posts', 'posts', Post::class, 'Custom label of the panel'),
```
15 changes: 11 additions & 4 deletions src/NestedForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,15 +173,21 @@ class NestedForm extends Field implements RelatableField
*/
protected $returnContext;

/**
* @var string|null
*/
public $panelLabel;

/**
* Create a new nested form.
*
* @param string $name
* @param string|null $attribute
* @param string|null $resource
* @param string $name
* @param string|null $attribute
* @param string|null $resource
* @param string|null $panelLabel
* @return void
*/
public function __construct(string $name, $attribute = null, $resource = null)
public function __construct(string $name, $attribute = null, $resource = null, $panelLabel = null)
{

parent::__construct($name, $attribute);
Expand All @@ -195,6 +201,7 @@ public function __construct(string $name, $attribute = null, $resource = null)
$this->keyName = (new $this->resourceClass::$model)->getKeyName();
$this->viaResource = app(NovaRequest::class)->route('resource');
$this->returnContext = $this;
$this->panelLabel = $panelLabel;

// Nova ^3.3.x need this to fix cannot add relation on create mode
$this->resolve(app(NovaRequest::class)->model());
Expand Down
8 changes: 6 additions & 2 deletions src/NestedFormPanel.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class NestedFormPanel extends Panel
{
/**
* Nested form.
*
*
* @var NestedForm
*/
protected $nestedForm;
Expand All @@ -22,7 +22,11 @@ public function __construct(NestedForm $nestedForm)

$this->nestedForm->asPanel($this);

parent::__construct(__('Update Related :resource', ['resource' => $this->nestedForm->name]), [$this->nestedForm]);
if (!$nestedForm->panelLabel) {
$nestedForm->panelLabel = __('Update Related :resource', ['resource' => $this->nestedForm->name]);
}

parent::__construct($nestedForm->panelLabel, [$this->nestedForm]);
}

/**
Expand Down