Skip to content
Browse files

Fix tags editing.

  • Loading branch information...
1 parent f8a6a92 commit fdedb324be93279317ccee240a4e38cca3b3b3c9 @gwoo gwoo committed Dec 1, 2012
Showing with 16 additions and 8 deletions.
  1. +12 −6 models/Posts.php
  2. +2 −1 views/posts/add.html.php
  3. +2 −1 views/posts/edit.html.php
View
18 models/Posts.php
@@ -95,15 +95,21 @@ public static function __init(array $options = array()) {
if (!empty($params['entity']->comments) && is_object($params['entity']->comments)) {
$params['entity']->comments = $params['entity']->comments->data();
}
- if (!empty($params['entity']->tags) && is_string($params['entity']->tags)) {
- $params['entity']->tags = array_unique(array_filter(explode(
- ",", str_replace(' ', '', $params['entity']->tags)
+ $tags = $params['entity']->tags;
+
+ if (!empty($params['data']['tags'])) {
+ $tags = $params['data']['tags'];
+ }
+ if (!empty($tags) && is_string($tags)) {
+ $tags = array_unique(array_filter(explode(
+ ",", str_replace(' ', '', $tags)
)));
- if (!empty($params['entity']->tags)) {
- $params['entity']->tags->each(function($v) use ($classes) {
+ if (!empty($tags)) {
+ $tags = array_map(function($v) use ($classes) {
return $classes['inflector']::slug($v);
- });
+ }, $tags);
}
+ $params['data']['tags'] = $params['entity']->tags = $tags;
}
$params['entity']->rating = $params['entity']->rating();
return $chain->next($self, $params, $chain);
View
3 views/posts/add.html.php
@@ -30,7 +30,8 @@
</div>
<label for="PostTags" class="tags">Tags:</label>
<?php echo $this->form->text('tags', array(
- 'id' => 'PostTags', 'value' => ($post->tags) ? join(', ', $post->tags->to('array')) : null
+ 'id' => 'PostTags',
+ 'value' => (is_object($post->tags)) ? join(', ', $post->tags->to('array')) : null
)); ?>
<small class="post-notes">separate tags with commas.</small>
<?php echo $this->form->submit('save'); ?>
View
3 views/posts/edit.html.php
@@ -32,7 +32,8 @@
</div>
<label for="PostTags" class="tags">Tags:</label>
<?php echo $this->form->text('tags', array(
- 'id' => 'PostTags', 'value' => ($post->tags) ? join(', ', $post->tags->to('array')) : null
+ 'id' => 'PostTags',
+ 'value' => (is_object($post->tags)) ? join(', ', $post->tags->to('array')) : null
)); ?>
<small class="post-notes">separate tags with commas.</small>
<?php echo $this->form->submit('save'); ?>

0 comments on commit fdedb32

Please sign in to comment.
Something went wrong with that request. Please try again.