Problem description

Recipient handler UI is currently on NodeTabForm, which creates problems:

  1. Cannot set recipient handler if sending via an action.
  2. Inconsistent with Newsletter ID which is set when editing the node
  3. Complicated to calculate the recipient count because it depends on the recipient handler settings (although could be solved with Ajax)

Proposed resolution

Remove recipient handler UI from NodeTabForm. Instead it must be set on the node edit page using a new widget.

Comments

AdamPS created an issue. See original summary.

berdir’s picture

See comment in #3054695: Problem with recipient handler interface and spooling about the views-based recipient handler which I think wouldn't be possible with this and the related issue?

adamps’s picture

Issue summary: View changes

@Berdir #2 - yes I agree.

adamps’s picture

Status: Active » Needs review
StatusFileSize
new16.1 KB

NB Patch applies on top of #1931006: Problem with recipient handlers so it won't apply until that one is committed. However it is still possible to review.

adamps’s picture

Version: 8.x-1.x-dev » 8.x-2.x-dev
StatusFileSize
new16.1 KB
adamps’s picture

StatusFileSize
new16.1 KB

Status: Needs review » Needs work

The last submitted patch, 6: simplenews.issue-widget.3055850-6.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

adamps’s picture

Status: Needs work » Needs review
StatusFileSize
new16.02 KB
new589 bytes

Status: Needs review » Needs work

The last submitted patch, 8: simplenews.issue-widget.3055850-8.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

adamps’s picture

Status: Needs work » Needs review
StatusFileSize
new16.58 KB
new406 bytes

Status: Needs review » Needs work

The last submitted patch, 10: simplenews.issue-widget.3055850-10.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

adamps’s picture

Status: Needs work » Needs review
StatusFileSize
new8 KB
adamps’s picture

StatusFileSize
new24.93 KB

Status: Needs review » Needs work

The last submitted patch, 13: simplenews.issue-widget.3055850-12.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

adamps’s picture

adamps’s picture

Status: Needs work » Needs review
StatusFileSize
new25.62 KB

Status: Needs review » Needs work

The last submitted patch, 16: simplenews.issue-widget.3055850-15.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

adamps’s picture

Status: Needs work » Needs review
StatusFileSize
new27.28 KB
new2.17 KB

Status: Needs review » Needs work

The last submitted patch, 18: simplenews.issue-widget.3055850-18.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

adamps’s picture

Status: Needs work » Needs review
StatusFileSize
new27.3 KB
new573 bytes

Status: Needs review » Needs work

The last submitted patch, 20: simplenews.issue-widget.3055850-20.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

adamps’s picture

Status: Needs work » Needs review
StatusFileSize
new27.34 KB
new834 bytes
adamps’s picture

Issue tags: +Plan to commit
adamps’s picture

Issue summary: View changes
adamps’s picture

jonathanshaw’s picture

  1. +++ b/config/optional/core.entity_form_display.node.simplenews_issue.default.yml
    @@ -33,7 +33,7 @@ content:
    -    type: options_select
    +    type: simplenews_issue
    

    Does this want an update hook? As you've removed the code from NodeTabForm, the module is effectively useless without the widget enabled.

  2. +++ b/src/Form/NodeTabForm.php
    @@ -70,7 +59,6 @@ class NodeTabForm extends FormBase {
    @@ -124,44 +112,6 @@ class NodeTabForm extends FormBase {
    

    So we're keeping the NodeTabForm but moving the settings out of it.

    I think that it's right to put all the settings into the one widget, for the reasons you give on the IS.

    But having those settings live somewhere else other than the NodeTabForm where the sending happens is a bit of a weird UX.

    I suggest a follow-up issue to look at something like adding a 'simplenews' form mode for the node entity, enabling the issue field widget by default only on that form mode, and using that form mode on the NodeTabForm.

  3. +++ b/src/Form/NodeTabForm.php
    @@ -215,29 +164,6 @@ class NodeTabForm extends FormBase {
    -      if (method_exists($class, 'settingsFormValidate')) {
    
    @@ -259,30 +185,6 @@ class NodeTabForm extends FormBase {
    -      if (method_exists($class, 'settingsFormSubmit')) {
    

    We don't seem to have preserved this ability for recipient handlers to validate or respond to submit.

    As I understand it the normal Drupal paradigm for plugins that provide forms is that they have build, validate and submit methods.

    So maybe we should add these to the RecipientHandlerInterface and empty implementations to the base class.

    Core has a PluginFormInterface, so maybe RecipientHandlerInterface should extend that.

  4. +++ b/src/Plugin/Field/FieldWidget/IssueWidget.php
    @@ -0,0 +1,140 @@
    +    $button = $form_state->getTriggeringElement();
    +    $values = $button ? $form_state->getValue($button['#array_parents'][0]) : NULL;
    +    $handler = $this->spoolStorage->getRecipientHandler($items->getEntity(), $values);
    ...
    +      '#default_value' => $handler->getPluginId(),
    

    This is a pretty complicated approach to getting the handler id ... if there's a really good reason to do this rather than just loading the value stored in the field, maybe it's worth making a code comment explaining.

  5. +++ b/src/Plugin/Field/FieldWidget/IssueWidget.php
    @@ -0,0 +1,140 @@
    +    $options = $this->recipientHandlerManager->getOptions();
    +    $element['handler'] = [
    

    If it worth hiding or disabling the handler if there is only one option?

  6. +++ b/src/Plugin/Field/FieldWidget/IssueWidget.php
    @@ -0,0 +1,140 @@
    +      '#description' => t('Please select to configure who to send the email to.'),
    

    Hard to describe this. Some possibilities:
    "Select how recipients are identified."
    "How recipients should be selected."
    "Choose which procedure to use for selecting email recipients."

  7. +++ b/src/Plugin/Field/FieldWidget/IssueWidget.php
    @@ -0,0 +1,140 @@
    +    if ($element['#value'] == '_none') {
    

    Wow, that's an arcane drupalism. Might be worth making a comment linking to #2448545: Modernize form select option helpers and/or #1585930: Render the _none option as an empty value for single select to allow client side validation for explanation.

adamps’s picture

1. I think it's OK without an update hook. If the specified widget is not available, then Drupal uses the default instead - which is exactly what we want.

2. I see your point that people might prefer to have configuration of the destination on the same page as the send button. However that's not how it is now we are not creating a new problem. Feel free to raise an issue. I'm not sure exactly how we could approach it - there are potential difficulties. As discussed in the IS, the destination must be set on the edit page or else sending via an action is broken. I'm not sure how easy it would be to somehow merge a node edit form with the send form. A new form display mode feels perhaps a bit too much as NB it would appear for all content types.

3. We match WidgetInterface which does not have verify and submit methods. The code in settingsForm() for building the form should add verify/submit handlers in the normal way.

4. I added a comment. If you can see a simpler way of doing it then please post your code:-) NB I don't want to hard-code the name of the field into the widget - I'm trying to gradually move away from the "magic field name" simplenews_issue.

5. Yes that's what the code already does:

'#access' => count($options) > 1,

6. Done.

7. I added a comment to explain how it works. I felt that was more useful than linking to an issue that is about changing how it works.

  • AdamPS committed 661b3d6 on 8.x-2.x
    Issue #3055850 by AdamPS: Wrong location of recipient handler UI
    
adamps’s picture

Status: Needs review » Fixed
Issue tags: -Plan to commit

  • AdamPS committed 289648b on 8.x-2.x
    Issue #3055850 by AdamPS: Wrong location of recipient handler UI
    
adamps’s picture

Sorry first commit missed the added file - now corrected

  • f239593 committed on 8.x-2.x
    git commit -m 'Issue #3055850 by AdamPS: Wrong location of recipient...
adamps’s picture

Sorry bad merge - now fixed

Status: Fixed » Closed (fixed)

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