-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from optimistdigital/translatable-support
Resolve row fields values. Add nova-translatable support
- Loading branch information
Showing
7 changed files
with
256 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
export default { | ||
data() { | ||
return { | ||
activeLocale: null, | ||
}; | ||
}, | ||
|
||
beforeMount() { | ||
Nova.$on('nova-translatable@setAllLocale', this.setActiveLocale); | ||
}, | ||
|
||
methods: { | ||
getFieldLocales(locales) { | ||
return Object.keys(locales) | ||
.sort((a, b) => { | ||
if (a === Nova.config.locale && b !== Nova.config.locale) return -1; | ||
if (a !== Nova.config.locale && b === Nova.config.locale) return 1; | ||
return 0; | ||
}) | ||
.map(key => ({ key, name: locales[key] })); | ||
}, | ||
|
||
setAllLocales(newLocale) { | ||
Nova.$emit('nova-translatable@setAllLocale', newLocale); | ||
}, | ||
|
||
setActiveLocale(newLocale) { | ||
this.activeLocale = newLocale; | ||
}, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<?php | ||
|
||
namespace OptimistDigital\NovaSimpleRepeatable; | ||
|
||
use JsonSerializable; | ||
use Laravel\Nova\Fields\Field; | ||
use Laravel\Nova\Fields\FieldCollection; | ||
|
||
class Row implements JsonSerializable | ||
{ | ||
protected $fields; | ||
protected $attributes; | ||
|
||
public function __construct($fields = null, $attributes = []) | ||
{ | ||
$this->fields = new FieldCollection($fields); | ||
$this->attributes = $attributes; | ||
} | ||
|
||
/** | ||
* Get a cloned instance with set values | ||
* | ||
* @param array $attributes | ||
* @return Row | ||
*/ | ||
public function duplicateAndHydrate(array $attributes = []) | ||
{ | ||
return new static ($this->fields->map(function ($field) { | ||
return $this->cloneField($field); | ||
}), $attributes); | ||
} | ||
|
||
/** | ||
* Resolve fields using given attributes. | ||
* | ||
* @return void | ||
*/ | ||
public function resolve() | ||
{ | ||
$this->fields->each->resolve($this->attributes); | ||
} | ||
|
||
/** | ||
* Create a working field clone instance | ||
* | ||
* @param \Laravel\Nova\Fields\Field $original | ||
* @return \Laravel\Nova\Fields\Field | ||
*/ | ||
protected function cloneField(Field $original) | ||
{ | ||
$field = clone $original; | ||
|
||
$callables = ['displayCallback', 'resolveCallback', 'fillCallback', 'requiredCallback']; | ||
|
||
foreach ($callables as $callable) { | ||
if (!is_a($field->$callable ?? null, \Closure::class)) continue; | ||
$field->$callable = $field->$callable->bindTo($field); | ||
} | ||
|
||
return $field; | ||
} | ||
|
||
public function jsonSerialize() | ||
{ | ||
return [ | ||
'fields' => $this->fields->jsonSerialize(), | ||
]; | ||
} | ||
} |
Oops, something went wrong.