Skip to content

Commit

Permalink
Merge pull request #1 from aheinze/master
Browse files Browse the repository at this point in the history
Update from original
  • Loading branch information
charkes committed Jul 25, 2015
2 parents 54ddfd0 + 7fc70e5 commit 5f17992
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
2 changes: 2 additions & 0 deletions modules/core/Cockpit/i18n/en.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,8 @@
'Entry removed' => '',
'Entry saved!' => '',
'Load more...' => '',
'Unique' => '',
'There is already an entry in this collection with this slug for field \'%s\'.',
// Mediamanager
'Mediamanager' => '',
Expand Down
26 changes: 26 additions & 0 deletions modules/core/Collections/Controller/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,32 @@ public function saveentry(){

$col = "collection".$collection["_id"];

// Check for uniqueeness of fields set as unique
foreach ($collection["fields"] as $fieldDefinition) {

$slugName = $fieldDefinition["name"] . "_slug";

if (!empty($fieldDefinition["slug"]) && !empty($fieldDefinition["unique"]) && isset($entry[$slugName])) {

$collision = $this->app->db->findOne("collections/{$col}", [$slugName => $entry[$slugName]]);

if (!$collision) {
continue;
}

// New and colliding or other entry
if (!isset($entry["_id"]) || $entry["_id"] != $collision["_id"]) {

$this->app->response->status = 409;

return sprintf(
$this->app->helper("i18n")->get("There is already an entry in this collection with this slug for field '%s'."),
$fieldDefinition["label"]
);
}
}
}

if (!isset($entry["_id"])){
$entry["created"] = $entry["modified"];
} else {
Expand Down
7 changes: 7 additions & 0 deletions modules/core/Collections/views/collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,13 @@
</div>
</div>
<div class="uk-form-row" data-ng-if="field.slug">
<label class="uk-form-label">@lang('Unique')</label>
<div class="uk-form-controls">
<input type="checkbox" data-ng-model="field.unique" />
</div>
</div>
@if(count($locales))
<div class="uk-form-row">
<label class="uk-form-label">@lang('Localize')</label>
Expand Down

0 comments on commit 5f17992

Please sign in to comment.