This is useful functionality if you need it - and I've just encountered a need for it! So thanks.

The problem I ran into is that I only need to comment permissions by role on one content type, but the module was stopping comments working on unmanaged types. The culprit is this code:

  foreach ($types as $type) {
    if ($build['#bundle'] == $type) {

The value of $type for unmanaged types is 0, so this comparison defaults to numeric. $build['#bundle'] is the content-type name and as a non-numeric string evaluates to 0, so the condition is true for all unmanaged types. The result is the comment form is never shown.

It can be fixed simply by changing to:

  foreach ($types as $type) {
    if ($type && $build['#bundle'] == $type) {

I've added this test to all similar lines of code to avoid pitfalls and pointless string comparisons.

There is also inconsistent testing for whether $types[$node->type] is non-0 (occurs several times). In some places isset($types[$node->type]) is used, which is wrong - isset() returns true for a 0 value. The safest test is !empty($types[$node->type]), I've changed all occurrences to this.

There's also some rather crazy indenting of braces which I've tidied up. This is currently working for me, patch to follow.

CommentFileSizeAuthor
#2 unmanaged-types-2890104-2.patch4.08 KBRickJ
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Rick J created an issue. See original summary.

RickJ’s picture

Patch

  • sdstyles committed 30fe5cf on 7.x-2.x
    Issue #2890104 by RickJ, sdstyles: Comments blocked for unmanaged types
    
sdstyles’s picture

Status: Needs review » Fixed

Fixed in 7.x-2.x branch.
Thanks!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.