Пример #1
0
 /**
  * @inheritdoc
  */
 public function init()
 {
     //assert proper model is set
     if ($this->subject === null || !ComponentConfig::isActiveRecord($this->subject, false)) {
         $msg = Yii::t('app', 'Setting the model property of type ActiveRecord is mandatory');
         throw new InvalidConfigException($msg);
     }
     ComponentConfig::hasBehavior($this->subject, CommentsBehavior::className(), true);
     //assert proper comment model
     if ($this->commentModel === null || !$this->commentModel instanceof Comment) {
         $msg = Yii::t('app', 'No proper comment model set');
         throw new InvalidConfigException($msg);
     }
 }
Пример #2
0
 /**
  * @inheritdoc
  *
  * @throws \yii\base\InvalidConfigException
  */
 public function init()
 {
     //assert proper model is set
     if ($this->subject === null || !ComponentConfig::isActiveRecord($this->subject, false)) {
         $msg = Yii::t('app', 'Setting the model property of type ActiveRecord is mandatory');
         throw new InvalidConfigException($msg);
     }
     ComponentConfig::hasBehavior($this->subject, CommentsBehavior::className(), true);
     //load the comments
     $this->loadComments();
     //prepare options
     Html::addCssClass($this->options, 'widget-comments');
     Html::addCssClass($this->commentOptions, 'comment');
 }
Пример #3
0
 /**
  * Sets the subject model
  *
  * @param \yii\db\ActiveRecord $subject
  */
 public function setSubject($subject)
 {
     //validate subject model
     ComponentConfig::isActiveRecord($subject, true);
     ComponentConfig::hasBehavior($subject, CommentsBehavior::className(), true);
     //only on unsaved comments
     if (!$this->isNewRecord) {
         $msg = Yii::t('app', 'The subject model can only be set manually on unsaved comments');
         throw new InvalidCallException($msg);
     }
     //set values from subject model
     $this->model_class = $subject->className();
     $this->foreign_pk = PrimaryKey::asJson($subject);
     $this->subject = $subject;
 }