Skip to content

Commit

Permalink
small refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
dustin10 committed Oct 8, 2011
1 parent 7159bef commit ffe5c37
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 9 deletions.
2 changes: 1 addition & 1 deletion app/config/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,4 @@ vich_geographical:
info_window: VichSf2TweetsBundle:Map:infoWindow.html.twig

vich_tweet_formatter:
twig: true
twig: true
5 changes: 2 additions & 3 deletions src/Vich/Sf2TweetsBundle/Controller/TweetController.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,13 @@ public function getTweetsAction()
*/
public function postTweetsAction()
{
$form = $this->get('vich_sf2tweets.form.tweet');
$handler = $this->get('vich_sf2tweets.form.handler.tweet');

$success = $handler->handle();
if ($success) {
return array('tweet' => $form->getData());
return array('tweet' => $handler->getTweet());
}

return array('form' => $form);
return array('form' => $handler->getForm());
}
}
5 changes: 2 additions & 3 deletions src/Vich/Sf2TweetsBundle/Entity/Tweet.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ class Tweet implements TweetInterface
* @ORM\Column(type="string", length="255", name="twitter_user_screen_name")
*
* @Assert\NotBlank(message="The twitter user screen name is required.", groups={"CreateTweet"})
* @Assert\MinLength(limit="2", message="The user screen name is too short.", groups={"CreateTweet"})
* @Assert\MaxLength(limit="255", message="The user screen name is too long.", groups={"CreateTweet"})
*
* @var string $twitterUserScreenName
Expand All @@ -51,9 +50,9 @@ class Tweet implements TweetInterface
/**
* @ORM\Column(type="string", length="255", name="twitter_user_avatar_url")
*
* @Assert\NotBlank(message="The twitter user screen name is required.", groups={"CreateTweet"})
* @Assert\NotBlank(message="The twitter user avatar url is required.", groups={"CreateTweet"})
* @Assert\Url(message="The twitter user avatar url is invalid.", groups={"CreateTweet"})
* @Assert\MaxLength(limit="255", message="The user screen name is too long.", groups={"CreateTweet"})
* @Assert\MaxLength(limit="255", message="The user avatar url is too long.", groups={"CreateTweet"})
*
* @var string $twitterUserAvatarUrl
*/
Expand Down
20 changes: 20 additions & 0 deletions src/Vich/Sf2TweetsBundle/Form/Handler/TweetFormHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,26 @@ class TweetFormHandler
*/
protected $form;

/**
* Gets the form.
*
* @return Form The form.
*/
public function getForm()
{
return $this->form;
}

/**
* Gets the tweet.
*
* @return Tweet The tweet.
*/
public function getTweet()
{
return $this->form->getData();
}

/**
* Constructs a new instance of TweetFormHandler.
*
Expand Down
2 changes: 1 addition & 1 deletion src/Vich/Sf2TweetsBundle/Form/Type/TweetType.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ public function buildForm(FormBuilder $builder, array $options)
->add('twitterId')
->add('twitterUserScreenName')
->add('twitterUserAvatarUrl')
->add('twitterUserLocation')
->add('message')
->add('messageEntities')
->add('twitterUserLocation')
;

$builder->addEventListener(FormEvents::BIND_CLIENT_DATA, function(FilterDataEvent $e) {
Expand Down
4 changes: 3 additions & 1 deletion src/Vich/Sf2TweetsBundle/Resources/config/form.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
<argument>tweet</argument>
<argument />
<argument type="collection">
<argument key="validation_groups">CreateTweet</argument>
<argument key="validation_groups" type="collection">
<argument>CreateTweet</argument>
</argument>
</argument>
</service>

Expand Down

0 comments on commit ffe5c37

Please sign in to comment.