Add comment

@param EntityInterface $entity Entity to add the comment to
@param string $comment Comment
@param string $userId User which wrote the note
@return ModelHistory
357206
public function addComment(EntityInterface $entity, string $comment, string $userId = null): ModelHistory
    {
        $add = $this->add($entity, ModelHistory::ACTION_COMMENT, $userId, [
            'data' => [
                'comment' => $comment
            ]
        ]);

        return $add;
    }
344219
public function can_post_in_discussion(stdClass $user, discussion_entity $discussion) : bool {
        $forum = $this->get_forum();
        $forumrecord = $this->get_forum_record();
        $discussionrecord = $this->get_discussion_record($discussion);
        $context = $this->get_context();
        $coursemodule = $forum->get_course_module_record();
        $course = $forum->get_course_record();

        return forum_user_can_post($forumrecord, $discussionrecord, $user, $coursemodule, $course, $context);
    }
327311
public function addComment($creditmemoIncrementId, $comment = null, $notifyCustomer = null, $includeComment = null)
    {
        return $this->__createAction('order_creditmemo.addComment', func_get_args());
    }
377159
public function addCommentAction(
        Request $request,
        $authorToken,
        $context,
        $source
    ) {
        $requestBag = $request->request;
        $content = $requestBag->get('content');
        $authorName = $requestBag->get('author_name');
        $authorEmail = $requestBag->get('author_email');
        $parentId = $requestBag->get('parent');

        /**
         * @var CommentInterface|null $parent
         */
        $parent = $parentId > 0
            ? $this
                ->commentRepository
                ->find($parentId)
            : null;

        $comment = $this
            ->commentManager
            ->addComment(
                $source,
                $context,
                $content,
                $authorToken,
                $authorName,
                $authorEmail,
                $parent
            );

        $commentStructure = $this
            ->commentCache
            ->createCommentStructure($comment);

        return new Response(json_encode([
            'entity' => $commentStructure,
            'children' => [],
        ]));
    }
931583
public function commentPermalink(Request $request, CommentInterface $comment) {
    if ($entity = $comment->getCommentedEntity()) {
      // Check access permissions for the entity.
      /* @var \Drupal\Core\Entity\Entity $entity */
      if (!$entity->access('view')) {
        throw new AccessDeniedHttpException();
      }
      /* @var \Drupal\Core\Url $url */
      if ($url = $entity->urlInfo('canonical')) {
        // Redirect the user to the correct entity.
        return $this->redirectToOriginalEntity($url, $comment, $entity);
      }
    }
    throw new NotFoundHttpException();
  }
1090816
private function createCreateForm(UserGroup $entity)
    {
        $options = array ('action' => $this->generateUrl('admin_usergroup_create'),
                          'method' => 'POST'
                         );

        $form = $this->createForm(new UserGroupType(), $entity, $options);

        return $form;
    }
768891
public function add_user_context(int $userid) : contextlist {
        $sql = "SELECT DISTINCT ctx.id
                  FROM {context} ctx
                 WHERE ctx.contextlevel = :contextlevel
                   AND ctx.instanceid = :instanceid";
        return $this->add_from_sql($sql, ['contextlevel' => CONTEXT_USER, 'instanceid' => $userid]);
    }
55554
public void updateComment(int commentId, CommentUpdate comment) {
		getResourceFactory().getApiResource("/comment/" + commentId)
				.entity(comment, MediaType.APPLICATION_JSON_TYPE).put();
	}
1169836
public function setComment(\Innova\CollecticielBundle\Entity\Comment $comment)
    {
        $this->comment = $comment;

        return $this;
    }
1236139
public function addCommentOnColumn($table, $column, $comment)
    {
        $table = $this->db->quoteTableName($table);
        $column = $this->db->quoteColumnName($column);
        $comment = $this->db->quoteValue($comment);

        $this->execute("COMMENT ON COLUMN $table.$column IS $comment;");
    }
334512
public function addComment(Comment $comment)
    {
        if (!$this->comments->contains($comment)) {
            $this->comments->add($comment);
        }
    }
134146
private function setEditableInComment(
        Comment $comment,
        string $authorUUID
    ) {
        if ($authorUUID === $comment->getAuthorUUID()) {
            $comment->setEditable(true);
        }
    }
753805
public function createFollow(Entity $entity, array $uuids) {

    foreach ($uuids as $uuid) {
      // Load the user(s) by the given uuid(s).
      $account = $this->loadByUuid('user', $uuid);

      $properties = [
        'uid' => $account->id(),
        'entity_type' => 'node',
        'entity_id' => $entity->id(),
        'flag_id' => 'follow_content',
      ];

      // Check the current flaggings.
      $flaggings = \Drupal::entityTypeManager()
        ->getStorage('flagging')
        ->loadByProperties($properties);
      $flagging = reset($flaggings);

      // If the user is already following, then nothing happens.
      // Else we create the flagging with the properties above.
      if (empty($flagging)) {
        $flagging = Flagging::create($properties);
        if ($flagging) {
          $flagging->save();
        }
      }
    }

  }
121944
protected function createNode(NodeInterface $commentCollection, CommentDtoInterface $comment): NodeInterface
    {
        $commentNodeType = $this->nodeTypeManager->getNodeType(self::COMMENT_NODE_TYPE);
        $commentNodeTemplate = new NodeTemplate();
        $commentNodeTemplate->setNodeType($commentNodeType);

        $commentNode = $commentCollection->createNodeFromTemplate($commentNodeTemplate);
        $commentNode->setProperty('name', $comment->getName());
        $commentNode->setProperty('email', $comment->getEmail());
        $commentNode->setProperty('content', $comment->getContent());
        $commentNode->setProperty('createdAt', $comment->getCreatedAt());
        $commentNode->setHidden($comment->isHidden());

        if ($this->addCommentToTop) {
            $firstComment = $commentCollection->getChildNodes(null, 1);
            
            if ($firstComment) {
                $commentNode->moveBefore($firstComment[0]);
            }
        }

        return $commentNode;
    }
344132
protected function updateUserShadowLogin(Entity\Users $userEntity)
    {
        if (Carbon::now() > $userEntity->getShadowvalidity()) {
            $userEntity->setShadowpassword(null);
            $userEntity->setShadowtoken(null);
            $userEntity->setShadowvalidity(null);
        }

        return $userEntity;
    }
255106
public function create(UserInterface $user)
    {
        $entity = static::ENTITY_CLASSNAME;

        $reminder = new $entity($user);

        $this->save($reminder);

        return $reminder;
    }
771752
public function commentAsUser(?Model $user, string $comment)
    {
        $commentClass = config('comments.comment_class');

        $comment = new $commentClass([
            'comment' => $comment,
            'is_approved' => ($user instanceof Commentator) ? ! $user->needsCommentApproval($this) : false,
            'user_id' => is_null($user) ? null : $user->getKey(),
            'commentable_id' => $this->getKey(),
            'commentable_type' => get_class(),
        ]);

        return $this->comments()->save($comment);
    }