Skip to content
This repository has been archived by the owner on May 19, 2020. It is now read-only.

Commit

Permalink
Merge pull request #1266 from CraigChilds94/bugfix/custom-site-edit-e…
Browse files Browse the repository at this point in the history
…rror-#1259

Custom site variable saving fix. Issue #1259
  • Loading branch information
CraigChilds94 authored Mar 7, 2018
2 parents af7bd00 + 7064244 commit 08e8e50
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 23 deletions.
24 changes: 11 additions & 13 deletions anchor/routes/variables.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,33 +100,31 @@
});

Route::post('admin/extend/variables/edit/(:any)', function ($key) {
$input = Input::get(['key', 'value']);
$input['key'] = 'custom_' . slug($input['key'], '_');
$input = Input::get(['key', 'value']);

foreach ($input as $key => &$value) {
$value = eq($value);
}
$original = slug($input['key'], '_');

$validator = new Validator($input);

$validator->add('valid_key', function ($str) use ($key) {
$validator->add('valid_key', function ($str) use ($original) {

// no change
if ($str == $key) {
return false;
// Don't check against the same key
if ($str == $original) {
return true;
}

// check the new key $str is available
return Query::table(Base::table('meta'))
->where('key', '=', $str)
->count() != 0;
->count() == 0;
});

// include prefix length 'custom_'
$validator->check('key')
->is_max(8, __('extend.name_missing'))
->is_max(1, __('extend.name_missing'))
->is_valid_key(__('extend.name_exists'));

$key = $input['key'] = 'custom_' . $original;
$value = $input['value'];

if ($errors = $validator->errors()) {
Input::flash();
Notify::error($errors);
Expand Down
20 changes: 10 additions & 10 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 08e8e50

Please sign in to comment.