- $link = [
- 'title' => ! empty($input['title']) ? $input['title'] : $input['url'],
- 'url' => $input['url'],
- 'description' => ! empty($input['description']) ? $input['description'] : '',
- 'tags' => ! empty($input['tags']) ? implode(' ', $input['tags']) : '',
- 'private' => $private,
- 'created' => new \DateTime(),
- ];
- return $link;
+ $bookmark->setTitle(! empty($input['title']) ? $input['title'] : '');
+ $bookmark->setUrl($url);
+ $bookmark->setDescription(! empty($input['description']) ? $input['description'] : '');
+
+ // Be permissive with provided tags format
+ if (is_string($input['tags'] ?? null)) {
+ $input['tags'] = tags_str2array($input['tags'], $tagsSeparator);
+ }
+ if (is_array($input['tags'] ?? null) && count($input['tags']) === 1 && is_string($input['tags'][0])) {
+ $input['tags'] = tags_str2array($input['tags'][0], $tagsSeparator);
+ }
+
+ $bookmark->setTags(! empty($input['tags']) ? $input['tags'] : []);
+ $bookmark->setPrivate($private);
+
+ $created = \DateTime::createFromFormat(\DateTime::ATOM, $input['created'] ?? '');
+ if ($created instanceof \DateTimeInterface) {
+ $bookmark->setCreated($created);
+ }
+ $updated = \DateTime::createFromFormat(\DateTime::ATOM, $input['updated'] ?? '');
+ if ($updated instanceof \DateTimeInterface) {
+ $bookmark->setUpdated($updated);
+ }
+
+ return $bookmark;