Problem:

The subscriptions ui block is being rendered with an empty form:

<div id="block-subscriptions-ui-0" class="block-subscriptions-ui-0 block block-subscriptions-ui">
        <div class="block-content">
    <form action="/" method="post" id="subscriptions-ui-node-form" accept-charset="UTF-8"><div><input type="hidden" name="form_build_id" value="form-z7YZtuGZKUpOJiTjqyyqGoYNZua0nq2h75Yszm19hfk">
<input type="hidden" name="form_token" value="91_URLNh5_bLHAbx9z2DBpvAzKbw9C59pY9WdLKAByE">
<input type="hidden" name="form_id" value="subscriptions_ui_node_form">
</div></form>  </div>
</div>

Because we use margins and border the block is rendered with a border but empty.

Context:

The problem for example occurs on the frontpage
The user is logged in and has permission to subscribe to some node types and their content
He's not allowed to subscribe to the static node which the frontpage node is type of

Expected behaviour

The block should not render at all.

Comments

Anybody’s picture

I please need help for further investigation.
The form bulding function in subscruotions_ui.module correctly returns NULL or array() (depending on the case) but the drupal_get_form() functions always render the form so that the block finally receives the empty form HTML and renders it.

I'm now using the following quickfix to hide the block content if the form array has no "account" key (which would always be present for a proper form) and set the block value to NULL to hide the block entirely:

In custom module:

/**
 * Implements hook_block_view_alter().
 */
function MYMODULE_block_view_alter(&$data, $block) {
  // Fix empty form block for registered users on pages without permission to subscribe to.
  // See: https://www.drupal.org/node/2496435
  if ($block->module == 'subscriptions_ui') {
    if (!empty($data['content']) && $data['content']['#form_id'] == 'subscriptions_ui_node_form' && !isset($data['content']['account'])) {      
      $data['content'] = NULL;
    }
  }
}

What we'll need is a solution to tell drupal_get_form() not to render the form if the form function returns an empty array or NULL. Alternatively we could pre-check the result of the form building function not to be NULL to pass the form array to the block. But that would require us to execute subscriptions_ui_node_form() twice?

The problem is between subscriptions_ui_node_form(), drupal_get_form() and subscriptions_ui_block_view() in subscriptions_ui.module.

salvis’s picture

Have your tried the options under STATIC CONTENT on admin/config/system/subscriptions?

Have you tried not showing the block on those pages where you don't want to see it?

Anybody’s picture

Yes the affected content type IS marked as static content!

salvis’s picture

Can you not just not show the block on those pages?

Anybody’s picture

Well that is possible but does not change anything about the bug behind.

salvis’s picture

I'm not sure this really is a Subscriptions bug...

Anybody’s picture

What ever this is, we should fix it. Where would you suggest to put the issue?
I had no other module with this issue yet.

salvis’s picture

It's in the right queue for now.

Help me to understand a bit better: why are you seeing the Subscriptions block at all on the front page? I think it should appear only on node pages. You write that your front page is a node page (which is somewhat unusual), but you've marked the front page content type as static?

So, the bug would be that we get a Subscribe block, even though the list of Subscribe options is empty, for whatever reason? Do we also get a Subscribe form, if we're not using the block?

What exactly is in $data['content'] that you're NULLing? Was it put there by Subscriptions?

Please investigate and post a patch if it can be fixed in the context of Subscriptions.