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

Commit 08e8e50

Browse files
Merge pull request #1266 from CraigChilds94/bugfix/custom-site-edit-error-#1259
Custom site variable saving fix. Issue #1259
2 parents af7bd00 + 7064244 commit 08e8e50

File tree

2 files changed

+21
-23
lines changed

2 files changed

+21
-23
lines changed

anchor/routes/variables.php

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -100,33 +100,31 @@
100100
});
101101

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

106-
foreach ($input as $key => &$value) {
107-
$value = eq($value);
108-
}
105+
$original = slug($input['key'], '_');
109106

110107
$validator = new Validator($input);
111108

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

114-
// no change
115-
if ($str == $key) {
116-
return false;
111+
// Don't check against the same key
112+
if ($str == $original) {
113+
return true;
117114
}
118115

119-
// check the new key $str is available
120116
return Query::table(Base::table('meta'))
121117
->where('key', '=', $str)
122-
->count() != 0;
118+
->count() == 0;
123119
});
124120

125-
// include prefix length 'custom_'
126121
$validator->check('key')
127-
->is_max(8, __('extend.name_missing'))
122+
->is_max(1, __('extend.name_missing'))
128123
->is_valid_key(__('extend.name_exists'));
129124

125+
$key = $input['key'] = 'custom_' . $original;
126+
$value = $input['value'];
127+
130128
if ($errors = $validator->errors()) {
131129
Input::flash();
132130
Notify::error($errors);

composer.lock

Lines changed: 10 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)