Problem/Motivation

The newsletter nodes display some strange output in the rendering.
"NoneManage subscriptions" with link to the admin profile edit.

See also image attached:

Proposed resolution

Figure out what element this is and drop it...
And create an issue if functionality of its real purpose is missing.

Remaining tasks

User interface changes

API changes

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Berdir’s picture

That is the newsletter user view element that we always had, with two problems:

- The #theme functions that it is using no longer exists
- it is not defined as an extra field, so it can not be hidden.

The node shows it because they show the user with a special view mode.

This is also in todo.txt already.

miro_dietiker’s picture

Thx for update.
The todo.txt should die (ASAP) and all items will have issues. :-)

Berdir’s picture

This is the todo.txt row for this "simplenews_user_view: Uses old #theme functions"

Arla’s picture

So they should be '#type' => 'item' instead, and should be added with simplenews_entity_extra_field_info()?

Berdir’s picture

A combination of things I guess, an item list for the list of subscriptions, a #type link for the link, maybe a fieldset around it, or something else. And that controlled by an extra field, yes.

mbovan’s picture

Status: Active » Needs review
FileSize
3.64 KB

Changed types to 'item' value and added a condition that allows fields to be hidden. Probably it needs some refactoring.

Berdir’s picture

Status: Needs review » Needs work

Good start.

  1. +++ b/simplenews.module
    @@ -523,46 +523,48 @@ function simplenews_user_delete(UserInterface $account) {
    +        '#type' => 'user_profile_category',
    

    This also no longer exists. I'd suggest a fieldset, as commented above.

  2. +++ b/simplenews.module
    @@ -523,46 +523,48 @@ function simplenews_user_delete(UserInterface $account) {
    +        $build['simplenews']['my_newsletters'] = array(
    +          '#type' => 'item',
    +          '#title' => '',
    +          '#markup' => t('Manage <a href="!url">subscriptions</a>', array('!url' => \Drupal::url('simplenews.newsletter_subscriptions_user', array('user' => $account->id())))),
    +        );
    

    It would be slightly different, but I would recommend to use #type link here, and make the whole text the link text.

Arla’s picture

We tried a fieldset but I think those can only be used in forms? We got an error saying something about #attributes. 'details' might be a better choice, but it looks kinda chunky.

mbovan’s picture

I changed the type from the 'user_profile_category' to 'details' because 'fieldset' gives an error, as Arlid said. Changed the #type for 'Manage subscriptions' to 'link' and made the whole text linkable.

Status: Needs review » Needs work

The last submitted patch, 9: simplenews-fix-for-extra-fields-2410043-9.patch, failed testing.

Arla’s picture

I guess we want some kind of test here, checking that the output is correct. May be necessary to use xpath to identify the correct elements.

Instead of pushing the whole chunk into an if-body, we can set $build['simplenews']['#access'] to the value of (bool) $display->getComponent('simplenews'). That will at least make the diff a lot nicer :)

By the way, neither me nor @mbovan could reproduce this on the node view, only on the user view. Something changed there since original issue summary?

Berdir’s picture

It might make the patch bigger, but an if (getComponent()) is the common and better pattern. with #access, you will waste processing power loading those subscriptions and then not display them.

Access is often easier/better, but not here.

Can you post screenshots of how it looks, with/without details?

Berdir’s picture

(or show me)

mbovan’s picture

Status: Needs work » Needs review
FileSize
18.01 KB
14.24 KB

Here are the screenshots with and without details type.

mbovan’s picture

Subscriptions are now rendered as a list.
Here are two screenshots how changes look like with subscriptions and without subscriptions.

Status: Needs review » Needs work

The last submitted patch, 16: simplenews-fix-for-extra-fields-2410043-16.patch, failed testing.

Status: Needs work » Needs review
miro_dietiker’s picture

Status: Needs review » Reviewed & tested by the community

Looks nice. :-)

Discussions about "None" output ended up in possibly being user specific anyway... And hey, they can disable it now, so if they don't like it, they can make it disappear as a whole or submit an issue to improve it. ;-)

Berdir’s picture

Status: Reviewed & tested by the community » Fixed

Committed and fixed.

  • Berdir committed 68c34e8 on 8.x-1.x authored by mbovan
    Issue #2410043 by mbovan: Fix subscriptions output when viewing users...
miro_dietiker’s picture

Issue summary: View changes
Priority: Normal » Critical
Status: Fixed » Needs work
FileSize
24.23 KB

Awww... ugly story!

Now for a strange reason, this is polluting nodes:
If i create now an article node, it contains that ugly subscription status widget.
It seems each article kindof triggers a user

In worst case we need to revert this. Otherwise, we need a fix.

Uncool. >:-)
(Node teasers, node detail view, everywhere!)

Berdir’s picture

Priority: Critical » Normal

That's not a critical problem ;) And it might be something that we can't fix in simplenews.

What you're seeing is the user, viewed with the compact user mode. You can reconfigure it and it will go away. (workaround => not critical, if we apply the same rules as core ;)).

The problem is that it apparently gets added there by default, because extra fields are made visible there by default it seems. Don't know why. We can only set a default visiblity, so the best we can do I guess is to hide it always by default.

edurenye’s picture

Now it's shown in the user and not in the node.
User:

Node:

mbovan’s picture

Status: Needs review » Needs work
  1. +++ b/simplenews.install
    @@ -135,6 +135,10 @@ function simplenews_install() {
    +  entity_get_display('user', 'user', 'default')
    

    entity_get_display() is deprecated and will be removed before Drupal 9. We can use \Drupal::entityManager()->getStorage('entity_view_display').

    Btw, should we care about the case when there is no user view display? With this patch if user view display is not present we will get the same thing as without the patch.

  2. +++ b/simplenews.module
    @@ -14,6 +14,7 @@ use Drupal\Core\Render\Element;
    +use Drupal\node\Entity\NodeType;
    

    Not needed.

edurenye’s picture

Status: Needs work » Needs review
FileSize
959 bytes
893 bytes

I made those changes.

Berdir’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests
+++ b/simplenews.install
@@ -135,6 +135,10 @@ function simplenews_install() {
+  \Drupal::entityManager()->getStorage('entity_view_display')->load('user.user.default')
+    ->setComponent('simplenews', array(
+      'label' => 'hidden',
+      'type' => 'simplenews',

This wasn't trivial to figure out, lets add a comment about why we do this. That we hide this by default but want to show it for the default view mode.

Also, can we write a test? should be possible to assert that this is not shown on a node in one of the existing tests? We might need to enable the show author setting of the node type for it to work, though.

edurenye’s picture

Test done and comments added.

juanse254’s picture

looks good to me

Berdir’s picture

Status: Needs review » Needs work
Issue tags: -Needs tests
+++ b/src/Tests/SimplenewsTestUI.php
@@ -0,0 +1,40 @@
+ * Test the UI aspects of simplenews.
+ *
+ * @group simplenews
+ */
+class SimplenewsTestUI extends SimplenewsTestBase {
+
+  /**
+   * Test the visibility of subscription user component.
+   */
+  public function testSubscriptionUserComponentVisiblity() {
+    // Create article content type.

We already have plenty of UI tests, it is a bit weird to add a UI test class now.

Also, tests always have a Test suffix.

Instead, I think that this would fit well in SimplenewsAdministrationTest::testContentTypes(), where we already create a node and visit it.

edurenye’s picture

Needs to be debugged by Berdir.
I moved the test there and now fails like there where nothing changed.

The last submitted patch, 26: interdiff-newsletter_node-2410043-24-26.patch, failed testing.

The last submitted patch, 26: newsletter_node-2410043-26.patch, failed testing.

The last submitted patch, 28: newsletter_node-2410043-28-test_only.patch, failed testing.

The last submitted patch, 28: newsletter_node-2410043-28.patch, failed testing.

The last submitted patch, 31: newsletter_node-2410043-31-test_only.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 31: newsletter_node-2410043-31.patch, failed testing.

Berdir’s picture

Status: Needs work » Needs review
FileSize
1.09 KB

See #2551959: Hardcoded usage of compact view mode in template_preprocess_node() and template_preprocess_comment() is problematic.

Considering that, let's just disable it by default and users have to enable it when they want to use it.

Status: Needs review » Needs work

The last submitted patch, 38: newsletter_node-2410043-38.patch, failed testing.

Berdir’s picture

Status: Needs work » Needs review
FileSize
1.67 KB

Fixing the tests.

Berdir’s picture

Status: Needs review » Fixed

Committed.

  • Berdir committed 6dc2466 on 8.x-1.x
    Issue #2410043 by edurenye, mbovan, Berdir: Newsletter node: garbage...

Status: Fixed » Closed (fixed)

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