Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

comment form enhancement (based on #2)

  • Loading branch information...
commit a7d94009e97433d6ea05c198b11d5d0c09ee027d 1 parent c88ba41
@nibsirahsieu authored
View
42 lib/form/sfNestedCommentFrontForm.class.php
@@ -1,27 +1,39 @@
<?php
class sfNestedCommentFrontForm extends sfNestedCommentForm
{
- public function configure()
+ public function configure()
{
parent::configure();
+
+ $user = $this->getOption('user', null);
- $this->useFields(array('id', 'author_name', 'author_email', 'author_url', 'content', 'sf_comment_id'));
+ if ($user && $user->isAuthenticated()) {
+ $this->useFields(array('id', 'author_name', 'author_email', 'author_url', 'content', 'sf_comment_id', 'user_id'));
+
+ $this->widgetSchema['author_name'] = new sfWidgetFormInputHidden();
+ $this->widgetSchema['author_email'] = new sfWidgetFormInputHidden();
+ $this->widgetSchema['author_url'] = new sfWidgetFormInputHidden();
+ $this->widgetSchema['user_id'] = new sfWidgetFormInputHidden();
+ } else {
+ $this->useFields(array('id', 'author_name', 'author_email', 'author_url', 'content', 'sf_comment_id'));
+
+ $this->widgetSchema['author_name']->setLabel('Name (required)');
+ $this->widgetSchema['author_email']->setLabel('Mail (required) (will not be published)');
+ $this->widgetSchema['author_url']->setLabel('Website');
+ }
$this->validatorSchema['author_name'] = new sfValidatorString(array('required' => true));
$this->validatorSchema['author_email'] = new sfValidatorEmail(array('required' => true));
$this->validatorSchema['author_url'] = new sfValidatorUrl(array('required' => false));
$this->validatorSchema['content'] = new sfValidatorString(array('required' => true));
+
$this->widgetSchema['content']->setAttributes(array('rows' => 10, 'class' => 'resizable'));
- $this->widgetSchema['author_name']->setLabel('Name (required)');
- $this->widgetSchema['author_email']->setLabel('Mail (required) (will not be published)');
- $this->widgetSchema['author_url']->setLabel('Website');
$this->widgetSchema['content']->setLabel('Comment (required)');
- $allowedTags = sfNestedCommentConfig::getAllowedTags();
- if ($allowedTags)
+ if ($allowedTags = sfNestedCommentConfig::getAllowedTags())
{
$this->widgetSchema->setHelp('content', 'You may use these HTML tags and attributes: '.htmlentities(implode(' ', $allowedTags)));
}
-
+
$this->widgetSchema['commentable_model'] = new sfWidgetFormInputHidden();
$this->widgetSchema['commentable_id'] = new sfWidgetFormInputHidden();
$this->validatorSchema['commentable_model'] = new sfValidatorString();
@@ -60,4 +72,18 @@ protected function doUpdateObject($values)
$this->getObject()->setsfNestedCommentableModel($commentable);
}
+
+ protected function updateDefaultsFromObject()
+ {
+ parent::updateDefaultsFromObject();
+
+ $user = $this->getOption('user');
+
+ if ($user && $user->isAuthenticated()) {
+ $this->setDefault('user_id', $user->getAuthorId());
+ $this->setDefault('author_name', $user->getAuthorName());
+ $this->setDefault('author_email', $user->getAuthorEmail());
+ $this->setDefault('author_url', $user->getAuthorWebsite());
+ }
+ }
}
View
6 lib/model/plugin/PluginsfNestedComment.php
@@ -43,12 +43,6 @@ public function preSave(PropelPDO $con = null)
{
$parent = sfNestedCommentQuery::create()->findPk($this->getSfCommentId());
$this->insertAsLastChildOf($parent);
- if ($this->getUserId())
- {
- $this->setIsModerated(false);
- $parent->setIsModerated(false);
- $parent->save($con);
- }
}
}
return parent::preSave($con);
View
4 lib/sfNestedCommentTools.class.php
@@ -38,10 +38,10 @@ public static function getCommentableObject(BaseObject $commentModel)
return PropelQuery::from($commentModel->getCommentableModel())->findPk($commentModel->getCommentableId());
}
- public static function createCommentForm($commentableObject)
+ public static function createCommentForm($commentableObject, sfBasicSecurityUser $user = null)
{
$comment = new sfNestedComment();
- $form = new sfNestedCommentFrontForm($comment);
+ $form = new sfNestedCommentFrontForm($comment, array('user' => $user));
$form->setDefault('commentable_model', get_class($commentableObject));
$form->setDefault('commentable_id', $commentableObject->getPrimaryKey());
return $form;
View
2  modules/sfNestedComment/lib/BasesfNestedCommentActions.class.php
@@ -28,7 +28,7 @@ protected function prepareMailParameter($comment)
public function executeAddComment(sfWebRequest $request)
{
- $this->commentForm = new sfNestedCommentFrontForm();
+ $this->commentForm = new sfNestedCommentFrontForm(null, $this->getUser());
$bindValues = $request->getParameter($this->commentForm->getName());
if (sfNestedCommentConfig::isRecaptchaEnabled())
{
View
2  modules/sfNestedComment/lib/BasesfNestedCommentComponents.class.php
@@ -13,6 +13,6 @@ public function executeRecentComments()
public function executeShowComments(sfWebRequest $request)
{
$this->comments = sfNestedCommentTools::getComments($this->object, $request);
- $this->commentForm = sfNestedCommentTools::createCommentForm($this->object);
+ $this->commentForm = sfNestedCommentTools::createCommentForm($this->object, $this->getUser());
}
}

1 comment on commit a7d9400

@Pezmc

Lovely, I shall have a play shortly!

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