The function RadioactivityEmitter::view() only returns parent::view() if the energy value should be displayed, to prevent rendering an empty field.

But with this approach, RadioactivityEmitter::viewElements() doesn't get executed if you choose the 'No value - only emit' formatter display, because ::view() calls ::viewElements(). This means no JS (triggers.js) will be attached to the field and page visits won't be emitted.

I think the solution is to remove the RadioactivityEmitter::view() function and let Drupal use its FormatterBase::view() instead. This way, no #markup will be returned, but the #attached JS will.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

hiddejansman created an issue. See original summary.

Sutharsan’s picture

Priority: Critical » Normal

I don't think this is an undesired behavior and needs to be fixed. If we remove the field formatter than there is no way to (temporary) prevent emitting the energy. We should address this behavior in the documentation.

Changing the priority to Normal. See https://www.drupal.org/node/45111 for a priority description.

jonnyeom’s picture

Perhaps I am not understanding this issue correctly. Does this mean that at the moment, if the radioactivity field to the 'No value - only emit' formatter display, the functionality of this module is basically not loaded onto any of the pages?

Sutharsan’s picture

Status: Active » Needs review
FileSize
1.03 KB

I was under the strong impression that 'No value - only emit' just works as advertised. But it does not emit :(
This patch fixes that.

  • Sutharsan committed 123d04c on 8.x-3.x
    Issue #2846378 by Sutharsan, hiddejansman: No emits if field formatter...
Sutharsan’s picture

Status: Needs review » Fixed

This bugfix is worth a new release. But before that time, I'd like to hear from @all if this fixes the problem at your end too.

jonnyeom’s picture

Just tested with the updated version. The fix is working great. Thanks!

mauritsl’s picture

I can confirm that energy is not emitted with when field is not displayed, and that this patch will fix that issue.

A new release would be helpful.

Status: Fixed » Closed (fixed)

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