Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
With translatable fields in core we might have multiple language versions of the same node. In this scenatio we might meed to filter out comments per language.
Comment | File | Size | Author |
---|---|---|---|
#74 | 605630-comment-admin-d7.patch | 4.25 KB | andypost |
#72 | 605630-comment-admin-d7.patch | 4.24 KB | andypost |
#58 | comment_lang_admin.png | 10.89 KB | plach |
#56 | comment_lang.jpg | 34.38 KB | peximo |
#53 | language_comments-605630-53.patch | 9.94 KB | peximo |
Comments
Comment #1
peximo CreditAttribution: peximo commentedThis patch implements a content language filter on node comments.
The patch add a language column in {comment}; in this column we save the content language code negotiated while viewing the comment post page.
Comment, for each module that implements hook_comment_filter_info(), invoke hook_comment_filter(); each module that implements this hook can alter the $query object.
The patch also implements this hook in locale that filter the node comments by node content language.
Comment #2
peximo CreditAttribution: peximo commentedComment #3
alexanderpas CreditAttribution: alexanderpas commentedmodule_invoke()?
This review is powered by Dreditor.
Comment #4
peximo CreditAttribution: peximo commentedreplaced, thx.
Comment #5
sunHm, this actually filters by the current global content language, and not by the assigned language of the node.
Missing PHPDoc.
Furthermore, both hooks need to be documented in comment.api.php.
I'm not yet 100% familiar with the new entity controller... this looks a bit like a query builder to me. I think that we prepare and pass the query conditions elsewhere initially instead.
Now I figure that this snippet probably doesn't belong to the entity controller, but to comment's thread builder function... so that makes a bit more sense - although I just rolled a patch that moved query conditions into the function signature ($mode, $pages), so that the caller can decide on that.
Instead of module_invoke(), we need to build the target $function, test whether function_exists($function) and directly invoke $function($query) instead.
Missing trailing period (full-stop).
In general, the inline documentation/comments are a bit lacking in this patch.
This makes no sense.
1) The hook returns an array and you are accessing an object.
2) We keep the array and just use module_invoke_all() here (a single line).
3) With m_i_a(), the initial declaration of $filters can go, because it always returns an array.
Instead of the surrounding if() statement, you take the expression of the condition and place it into #access.
Missing trailing comma here.
I guess that this is the hunk where a comment is saved?
Why do we store the current global content language and not the displayed language of the node?
Please roll your patches with diff -up, so we can see what is changed.
Why not null?
Please use single quotes here.
Missing trailing comma.
I'm on crack. Are you, too?
Comment #6
Dries CreditAttribution: Dries commentedI'd recommend that we split this patch in two halfs. One patch that stores the language information with the comments, and one patch that provides the filter. The part that stores the language information is a no-brainer, except that it doesn't look like one can edit the language afterwards.
Comment #7
sunDone: #605862: Store language for comments
Comment #8
andypostIt's a good idea to remove node_load() but next line will give exception about non-existent object $node
Comment #9
peximo CreditAttribution: peximo commentedYes, because with translatable fields without translation.module the node language is always only one but we can have fields translated; with this patch we can show a node with translated fields depending on the selected content language and filtering the comments for this language.
For the documentation, I don't write (and speak also :)) english very well, plach will help me tomorrow.
The others problems/comments are fixed.
Comment #10
peximo CreditAttribution: peximo commentedSorry, wrong indentation on previous patch.
Comment #11
alexanderpas CreditAttribution: alexanderpas commented@Dries:
something for a seperate UI patch?
Comment #12
peximo CreditAttribution: peximo commentedPatch with documentation.
Comment #13
andypostSuppose we should care about admin/content/comment as Dries pointed at #605862: Store language for comments
Something like admin/content filters for moderation
Comment #14
plach@andypost: We might want to introduce a language selector in the comment form just as in the node form. Only users with the appropriate permission would see it, the others would get language based on
global $language
.Comment #15
catchWhy not a query tag and hook_query_alter() here?
Comment #16
andypostsuppose, count query should be affected too
Comment #17
catchApart from query tag vs. hook_comment_filter_info() - if for some reason we do need a specific hook, we also need hook docs in comment.api.php
Comment #18
webchickHm. Sorry, this approach is not going to fly. We do not want to start defining hooks of modules that implement hooks of other modules all over the place. Would become a spaghetti factory. I also don't like the coupling between locale and comment.
Comment #19
andypostRealized query_alter aproach only one thing todo - make a permission for Filtering comments
Comment #20
andypostForget to add comment module patch, now it's full
But now there's no permission check for altering comment filters
Need a review on comments, oh my english
Comment #21
catchJust discussed this briefly with andypost. I was wondering about the node type variable, the reason that's needed is to stop locale.module altering the query just because it's enabled, even if the feature isn't needed (you can have locale module enabled, but not comments posted in multiple languages). That makes sense now. My only concern here is that the UI text doesn't really explain what the feature is (and I'm not sure how much it needs to be exposed) - makes me think about filtering in comment admin, not a module-provided filter. So not marking RTBC just yet, but not CNW either.
Comment #22
andypostThe old hook_comment_info() collects possible filters mostly for settings page to allow enable some filters for comments
To re-implement this functionality:
1) gather modules by module_implements('query_comment_filter_alter')
2) change settings for node to checkboxes with a list of modules
3) http://drupal.org/node/310077 pass metadata for query so every alter could check it's permissions
4) write an example alter for locale module
This patch is working example...
Comment #23
sunQuery tags don't hurt, you can unconditionally add them, so this can go.
Why don't you add the tag to the query before it is cloned?
This will display a list of checkboxes with module names... "locale" (lowercase; the internal module name) being one of them. Not sure whether that's grokable.
module_list() isn't required at all here. you could use drupal_map_assoc() instead, but that doesn't solve the underlying issue explained above.
This review is powered by Dreditor.
Comment #24
andypost@sun agree, tags and meta could be added unconditional
I dont know when the query is cloned... so tags and meta are added just after other tags added.
I know that module_list produce a lowercase but I found no ability to get the Real module-name.
This is just an example - maybe for contrib to add more granular permission for comment filters.
Comment #25
andypostAdded a tags because this needs some UI
1) Ability to enable filters for comments (basically core allows comments to be filtered by language by switching language if locale module enabled and checkbox allows it for {node-type} at admin/structure/types/manage/{node-type})
screenshot attached - last patch provides ugly t('Comment filters') checkboxes at node-type-edit form admin/structure/types/manage/{node-type}
peximo's patch gathers filter names with a additional hook which give ability to show - Filter by content language instead of plain module name, maybe it's a good idea to add this hook or maybe just form-alter aproach?
2) admin/contant/comment screen - should we add language column when locale module enabled? like /admin/content does for nodes
3) Ability to filter comments in moderation queue at admin/content/comment (suppose this task for contrib, if so we could make this alterable in code and describe in docs)
Comment #26
andypostScreen-shot attached
Comment #28
peximo CreditAttribution: peximo commentedIMO one module should be able to add multiple filters (locale can add one for filtering comments on content language and another one for filtering by user prefered language etc.). With current approach this seem to me impossible.
IMO the comment language is a useful information so it should be showed in comments_overview. I don't know wich is the correct distinction to show this field: locale is enabled? Is there at least one node with a language?
I have add another features that IMO is useful: the comment language selection for users with 'change comments language' permission in both comment post and edit.
Comment #29
andypostLet's change module_list() with new http://api.drupal.org/api/function/system_get_info/7 from #561452: Add API function to get module/theme info without rebuilding it.
This give us a real module name with internal module name as option value
Comment #30
peximo CreditAttribution: peximo commented@andypost: it's a good solution, but remains that one module can implement only one filter.
Comment #31
peximo CreditAttribution: peximo commentedThere's another problem with this approach: there isn't a description of what the filter does. I know that for a content type I have enabled a filter given by a module but via UI I do not know what this filter does.
Comment #32
andypost@peximo Agree exactly with all your points but main problem is api-freeze
Comment #33
plachBesides what you said above there is something to polish here:
You need
drupal_multilingual()
here. You might want to change$multilanguage
into$multilingual
also.trailing whitespaces
module_implements()
already usesmodule_list()
, IMO this line is useless.trailing whitespaces
drupal_multilingual()
trailing whitespace
This should be
otherwise language neutral comments will disappear.
I'm on crack. Are you, too?
Comment #34
peximo CreditAttribution: peximo commentedBecause api-freeze it's impossible to have here a patch that handle comments filters. The previous solution that implements one filter per module with the name of the module as description in the UI is IMO not acceptable.
Rather it is preferable that each module implements its filters for the comments, eg. user.module can filtering the comments by the $user->language etc.
In the previous patch there is a features for the comment language administration; this features is IMO important, so a repost the patch without the filter system but with this features.
Comment #35
plachFYI: a comment filter has been re-introduced in #539110: TF #4: Translatable fields UI
Comment #37
peximo CreditAttribution: peximo commentedrerolled
Comment #38
peximo CreditAttribution: peximo commentedComment #39
plachThe patch looks good, works fine and responds to the requirement Dries expressed in #605862-2: Store language for comments and in #6:
This might need some tests, primarily check if language conditions (multilingual site, multilingual content type) are respected.
There are also some small things to fix:
Should be "Enable the language column ...". Watch out for the trailing whitespaces in the first line.
Shoud be "... and the user has the 'change comments permission'". Watch out for the trailing whitespaces.
Locale defines
locale_multilingual_node_type()
to check if a content type is multilingual, but using it would introduce an explicit dependency from Locale. However we are already implicitly doing it by checking a configuration variable (and a logic) defined by Locale.Trailing whitespace.
I'm on crack. Are you, too?
Comment #40
plachComment #41
peximo CreditAttribution: peximo commentedFor the node form is locale in locale_form_alter() that add the language selector controlling if a content type has multilingual support. So if we don't control this support also in comment we might have a node without the language selector but with associated comments with this features.
And this behavior is IMO not consistent.
Perhaps the language selector and the permission should be set by locale?
I have fixed the others things.
Comment #42
plachYes, probably the changes to comment.module should be straightforwardly moved to locale.module.
These lines must be fixed.
This review is powered by Dreditor.
Comment #43
plachComment #44
peximo CreditAttribution: peximo commentedOk, with this patch comment adds only the administration language column, the language selector and the 'change comments' permission is added by locale.
Because to do this we must have the node->type property, I have added $node object to the comment form.
Comment #45
peximo CreditAttribution: peximo commentedadded tests.
Comment #46
plachI am happy with this one, except for some minor issue:
I just realized "comments language" should be replaced by "comment language" everywhere in this patch.
Trailing whitespaces ;)
"Test that the language column is not present with only one language enabled." sounds better.
According to the change above: "The language column is not present."
As above: "Test that the language column is present with more than one language enabled."
"The language column is present."
The permission name is wrong.
Should be "Functional tests for the comment language selector." Moreover on the top of locale.test there is a summary of tests which should be integrated.
Should be "Post a comment to the previously created article."
Why the user has also the 'administer comments" permission? Shouldn't be enough the 'change comment language' one?
Again: "Test that the language selector is present." sounds better.
Do we really need this change?
This review is powered by Dreditor.
Comment #47
peximo CreditAttribution: peximo commentedFixed with plach suggestion.
Comment #49
peximo CreditAttribution: peximo commentedrerolled
Comment #50
peximo CreditAttribution: peximo commentedComment #51
peximo CreditAttribution: peximo commentedI have forgot to replace "comments language" with "comment language".
Comment #52
sunHmmm.... shouldn't this be a more generic permission that applies to nodes + stuff as well?
Minor: Missing trailing comma.
errr... WTF? Do me a favor and remove this entire TOC instead, please. ;)
I'm on crack. Are you, too?
Comment #53
peximo CreditAttribution: peximo commentedI wouldn't use a single permission because you might not wish to give a user the ability to select the language either for a node and for a comment.
IMO comment permissions should be separated from node ones.
Plach has added this TOC after reading this in Guidelines - Test template:
Fixed the trailing comma.
Comment #54
plachI am not sure this can still go in, but I think the current patch takes care of the issue and responds to the requirement Dries expressed in #605862-2: Store language for comments and in #6:
Comment #55
webchickCould we get some updated screenshots for this issue? I'm really hoping it looks different than http://drupal.org/files/issues/comment_filters.png because that makes absolutely no sense. :P
Comment #56
peximo CreditAttribution: peximo commentedThe patch add a language selector when a comment is posted or edited, not a filter. Attached there is a screenshot.
Comment #57
plachThe patch implements also the language column in the comments admin UI. See #34 for details.
Comment #58
plachHere is a screenshot
Comment #59
Bojhan CreditAttribution: Bojhan commented:o the user has to select the language he is commenting in?
Comment #60
peximo CreditAttribution: peximo commented@bojhan: user with proper permission (change comment language) can select the comment language. If not, you set a default comment language #624290: Wrong default comment language.
Comment #61
Dries CreditAttribution: Dries commentedMmm, personally, I'm not really keen on the UI changes here. At the same time, I don't see how else to deal with this.
Given that we already have #624290: Wrong default comment language in core, is the UI best exposed through a contributed module (for D7)? I think we should have covered the 95% case with #624290.
Either way, should this be a new permission or should we leverage the existing i18n permissions?
Comment #62
plachComment #63
peximo CreditAttribution: peximo commentedWithout the UI part in comment.module (the language column in the comment administration) we would have a mismatch between the default behavior of administration of the nodes (which shows a language column in the administration page) and comments. The part in locale.module (the language selector) I think may be in a contributed module.
I think we should have a new permission for distinguish users like translators and users, also anonymous, that doesn't translate contents but that can select their comment language.
Comment #64
sunI also feel uneasy about this patch.
The system should be smart enough to figure out the language of a comment automatically. I.e., yes, we want to store a language for comments.
But displaying and editing a comment's language does not really make sense for 99% of all use-cases. That should be left for contrib.
Comment #65
peximo CreditAttribution: peximo commentedI agree but IMO at least the language column in comments administration should be in core.
Comment #66
sunCan you explain why, please? I'm not sure I see the use-case for it.
Comment #67
peximo CreditAttribution: peximo commentedI think that without the comment language column we miss an useful information: obviously if we have a default behavior (node translated via node translation and comments related uniquely to one node) this column can be superfluous, but with a node translated via translatable fields and comments filtered by language (#641034: Make comment lists filterable) this information seems to me important.
If later then it will be implemented a language selector with a contribuited module this information will be much more important.
I don't think that this column should be added by the same contributed module that add the selector: for node is node module that add the language column, not locale nor translation, although the visualization of this column depends on the enabling of translation module.
Comment #68
Dave ReidHave a language select on comment forms makes a whole lot of sense. Plus it would be super useful for textual analysis (like in Mollom) to be able to better analyze text based on its language.
Comment #69
mcload CreditAttribution: mcload commentedsubscribing
Comment #70
retester2010 CreditAttribution: retester2010 commented#53: language_comments-605630-53.patch queued for re-testing.
Comment #72
andypostSo maybe proceed with admin interface?
Comment #74
andypostUpdated test
Comment #75
Bojhan CreditAttribution: Bojhan commentedWhat needs review? Did we fix the part that everyone feels uncomfortable about?
Comment #76
Jurgen8en CreditAttribution: Jurgen8en commented#74: 605630-comment-admin-d7.patch queued for re-testing.