Features/comments #11

Closed
wants to merge 14 commits into
from

Projects

None yet

2 participants

@fantastic91
Owner

No description provided.

added some commits Jul 11, 2016
@fantastic91 Comment dependency. 00f3dba
@fantastic91 Updated entity type analyzer to support partial matching. 225c87b
@fantastic91 Added comment handler. 53d66ad
@fantastic91 Early return for node plugin. c65d4d4
@fantastic91 Test coverage for Comment handler.
6c3332a
@primsi primsi and 1 other commented on an outdated diff Jul 13, 2016
mailhandler_d8.info.yml
@@ -8,3 +8,4 @@ dependencies:
- inmail
- node
- user
+ - comment
@primsi
primsi Jul 13, 2016

Sold comment handler live in a separate sub module?

@fantastic91
fantastic91 Jul 15, 2016 Owner

Moved the code related to comments to mailhandler_d8_comment submodule.

@primsi primsi and 1 other commented on an outdated diff Jul 13, 2016
src/Plugin/inmail/Handler/MailhandlerComment.php
+ protected function createComment(MessageInterface $message, MailhandlerAnalyzerResultInterface $result) {
+ $subject = $result->getSubject();
+ if (!preg_match('/^\[#(\d+)\]\s+/', $subject, $matches)) {
+ throw new \Exception('Referenced entity ID of the comment could not be identified.');
+ }
+
+ // Get a node ID and update the subject.
+ $node_id = $matches[1];
+ $subject = str_replace(reset($matches), '', $subject);
+
+ // Validate whether user is allowed to post comments.
+ $user = $this->validateUser($result);
+
+ // Create a comment entity.
+ $comment = Comment::create([
+ 'entity_type' => 'node',
@primsi
primsi Jul 13, 2016

Should this leave in handler config, so we can support other entities to?

@fantastic91
fantastic91 Jul 15, 2016 Owner

Added configurable "entity_type" option on the handler.

@primsi primsi and 1 other commented on an outdated diff Jul 13, 2016
src/Plugin/inmail/Handler/MailhandlerComment.php
+ *
+ * @throws \Exception
+ * Throws an exception in case user is not authorized to create a comment.
+ */
+ protected function createComment(MessageInterface $message, MailhandlerAnalyzerResultInterface $result) {
+ $subject = $result->getSubject();
+ if (!preg_match('/^\[#(\d+)\]\s+/', $subject, $matches)) {
+ throw new \Exception('Referenced entity ID of the comment could not be identified.');
+ }
+
+ // Get a node ID and update the subject.
+ $node_id = $matches[1];
+ $subject = str_replace(reset($matches), '', $subject);
+
+ // Validate whether user is allowed to post comments.
+ $user = $this->validateUser($result);
@primsi
primsi Jul 13, 2016

Should we validate if this bundle supports comments? And that even the entity exists?

@fantastic91
fantastic91 Jul 18, 2016 Owner

Seems like validate() doesn't "validate" entity ID, so I added custom validation for entity ID and bundle.

added some commits Jul 14, 2016
@fantastic91 Configurable entity type of a comment.
3933969
@fantastic91 Added mailhandler_d8_comment submodule. 2df1eee
@fantastic91 Removed comment leftovers from the main module. Test updates.
92fc026
@fantastic91 Moved sample comment message to submodule. 8dfefe7
@fantastic91 Added entity type, ID, bundle comment validation. 7c4efa6
@fantastic91 Updated comment tests. 10d28ad
@fantastic91 Fixed comment test.
64b41bb
@fantastic91 Updated hook_form_form_ID_alter.
1802ff9
@fantastic91 Updated tests.
70c7538
@fantastic91 fantastic91 deleted the features/comments branch Jul 22, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment