Skip to content

Commit

Permalink
Fix group detection in route, missing array key (#180)
Browse files Browse the repository at this point in the history
  • Loading branch information
bstrahija authored and barryvdh committed Mar 4, 2017
1 parent d991d53 commit 4d91fce
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 24 deletions.
32 changes: 9 additions & 23 deletions src/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,14 @@ public function getIndex($group = null)
->with('deleteEnabled', $this->manager->getConfig('delete_enabled'));
}

public function getView()
public function getView($group = null)
{
$groups = func_get_args();
$group = implode('/', $groups);
return $this->getIndex($group);
}

protected function loadLocales()
{
//Set the default locale as the first one.
//Set the default locale as the first one.
$locales = Translation::groupBy('locale')
->select('locale')
->get()
Expand All @@ -72,13 +70,9 @@ protected function loadLocales()
return array_unique($locales);
}

public function postAdd(Request $request)
public function postAdd($group = null)
{
$keys = explode("\n", $request->get('keys'));

$groups = func_get_args();
array_shift($groups); // remove the $request
$group = implode('/', $groups);
$keys = explode("\n", request()->get('keys'));

foreach($keys as $key){
$key = trim($key);
Expand All @@ -89,14 +83,11 @@ public function postAdd(Request $request)
return redirect()->back();
}

public function postEdit(Request $request, $group)
public function postEdit($group = null)
{
if(!in_array($group, $this->manager->getConfig('exclude_groups'))) {
$groups = func_get_args();
array_shift($groups); // remove the $request
$group = implode('/', $groups);
$name = $request->get('name');
$value = $request->get('value');
$name = request()->get('name');
$value = request()->get('value');

list($locale, $key) = explode('|', $name, 2);
$translation = Translation::firstOrNew([
Expand All @@ -111,11 +102,8 @@ public function postEdit(Request $request, $group)
}
}

public function postDelete()
public function postDelete($group = null)
{
$groups = func_get_args();
$key = array_pop($groups); // the last arg is the key
$group = implode('/', $groups);
if(!in_array($group, $this->manager->getConfig('exclude_groups')) && $this->manager->getConfig('delete_enabled')) {
Translation::where('group', $group)->where('key', $key)->delete();
return ['status' => 'ok'];
Expand All @@ -137,10 +125,8 @@ public function postFind()
return ['status' => 'ok', 'counter' => (int) $numFound];
}

public function postPublish()
public function postPublish($group = null)
{
$groups = func_get_args();
$group = implode('/', $groups);
$this->manager->exportTranslations($group);

return ['status' => 'ok'];
Expand Down
2 changes: 1 addition & 1 deletion src/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public function exportTranslations($group)
if($group == '*')
return $this->exportAllTranslations();

$tree = $this->makeTree(Translation::ofTranslatedGroup($group)->orderByGroupKeys($this->config['sort_keys'])->get());
$tree = $this->makeTree(Translation::ofTranslatedGroup($group)->orderByGroupKeys(array_get($this->config, 'sort_keys', false))->get());

foreach($tree as $locale => $groups){
if(isset($groups[$group])){
Expand Down

0 comments on commit 4d91fce

Please sign in to comment.