Skip to content

Commit

Permalink
[issue 9] Fix problem with nove Panel
Browse files Browse the repository at this point in the history
  • Loading branch information
kongulov committed Jun 23, 2021
1 parent 7e7eaa4 commit 0ef0bfc
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
],
"require": {
"php": ">=7.1.0",
"spatie/laravel-translatable": "^4.0"
"spatie/laravel-translatable": ">=4.0"
},
"autoload": {
"psr-4": {
Expand Down
11 changes: 7 additions & 4 deletions src/TranslatableTabToRowTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,18 @@ trait TranslatableTabToRowTrait
*/
public function availableFields(NovaRequest $request)
{
$method = $this->fieldsMethod($request);

// needs to be filtered once to resolve Panels
$fields = $this->filter($this->fields($request));
$fields = $this->filter($this->{$method}($request));
$availableFields = [];

foreach ($fields as $key => $field) {
if ($field instanceof NovaTabTranslatable) {
$availableFields[] = $this->filterFieldForRequest($field, $request);
if($this->extractableRequest($request, $this->model())) {
if ($this->doesRouteRequireChildFields()) {
$this->extractChildFields($field->originalFields, $key);
$this->extractChildFields($field, $key);
}
}
} else {
Expand Down Expand Up @@ -114,15 +116,16 @@ protected function doesRouteRequireChildFields(): bool
* @param [array] $childFields [meta fields]
* @return void
*/
protected function extractChildFields($childFields, $key)
protected function extractChildFields($field, $key)
{
foreach ($childFields as $childField) {
foreach ($field->originalFields as $childField) {
if ($childField instanceof NovaTabTranslatable) {
$this->extractChildFields($childField->data, $key);
} else {
if (array_search($childField->attribute, array_column($this->childFieldsArr, 'attribute')) === false) {
// @todo: we should not randomly apply rules to child-fields.
$childField = $this->applyRulesForChildFields($childField);
if (isset($field->panel)) $childField->panel = $field->panel;
$this->childFieldsArr[$key][] = $childField;
}
}
Expand Down

0 comments on commit 0ef0bfc

Please sign in to comment.