Drupal Version 8.4.2 on the latest dev branch of simplenews.

I am seeing that the Subscriber Entity's form handler definitions are not correctly being applied.

Subscriber.php has following annotations.

*   handlers = {
 *     "storage" = "Drupal\simplenews\Subscription\SubscriptionStorage",
 *     "form" = {
 *       "default" = "Drupal\simplenews\Form\SubscriberForm",
 *       "account" = "Drupal\simplenews\Form\SubscriptionsAccountForm",
 *       "block" = "Drupal\simplenews\Form\SubscriptionsBlockForm",
 *       "page" = "Drupal\simplenews\Form\SubscriptionsPageForm",
 *       "delete" = "Drupal\simplenews\Form\SubscriberDeleteForm",
 *     },

However, when the entity is being called, the defined form handlers are as follows.
simplenews-form-handlers

As a result, all pages and blocks where the forms are build using entityTypeManager->getFormObject('simplenews_subscriber', /*$form_operation e.g. 'block'*/) is not working.

This includes,

  • Subscription Block, which is why this issue is actually occuring.
CommentFileSizeAuthor
simplenews-form-handlers.png50.7 KBjonnyeom

Comments

jonnyeom created an issue. See original summary.

jonnyeom’s picture

Is nobody else getting this error?
I don't think i am using the module incorrectly.

Appreciate the feedback.

berdir’s picture

Status: Active » Postponed (maintainer needs more info)

Nope, definitely not happen for me, and we have lots of tests that are working fine.

The only explanation I have a is an entity type alter hook doing something strange. Any other modules installed that do anything with form modes? They might mess things up.

bmunslow’s picture

I'm experiencing the same issue in Drupal 8.5.1, simplenews release 8.x-1.0-alpha3

Adding Simplenews Subscription block to any visible region throws error:

The website encountered an unexpected error. Please try again later.
Error: Call to undefined method Drupal\simplenews\Form\SubscriberForm::setUniqueId() in Drupal\simplenews\Plugin\Block\SimplenewsSubscriptionBlock->build() (line 164 of modules/simplenews/src/Plugin/Block/SimplenewsSubscriptionBlock.php).

The only module in my installation, that I can think of, which tampers with form modes is form_mode_manager

I will try to uninstall it and see if it makes any difference.

bmunslow’s picture

Hi,

I can confirm that, in my case, module form_mode_manager (8.x-2.0-beta1) was the culprit and caused this fatal error when simplenews subscription block was enabled.

I was able to trace this thanks to @Berdir's previous comment #3.

I searched my module base and got a list of all the modules which implemented hook_entity_type_alter(), which were just a few, and then analyzed the code in each of them.

I got to see very quickly that module form_mode_manager uses this hook to alter the entity handlers for each form mode in each entity type, which results in the corrupted form handlers being set as described by the reporter of this issue, @jonnyeom.

@see: /modules/form_mode_manager/src/EntityTypeInfo.php @@ -74,7

  public function entityTypeAlter(array &$entity_types) {
    $available_entity_types = array_keys($this->formModeManager->getAllFormModesDefinitions());
    foreach ($available_entity_types as $entity_type_id) {
      if ($entity_definition = $entity_types[$entity_type_id]) {
        $this->formModeManager->setEntityHandlersPerFormModes($entity_definition); // <- ENTITY HANDLERS ALTERED
      }
    }
  }

Tracing down this method shows how Form Classes are being altered. If you comment the following line in form_mode_manager, the error disappears and subscription block is shown properly:

+++ b/modules/form_mode_manager/src/FormModeManager.php
@@ -297,7 +297,7 @@ public function setEntityHandlersPerFormModes(EntityTypeInterface $entity_defini
     }

     foreach ($form_modes as $form_mode_name) {
-      $this->setFormClassPerFormModes($entity_definition, $form_mode_name);
+      // $this->setFormClassPerFormModes($entity_definition, $form_mode_name);
       $this->setLinkTemplatePerFormModes($entity_definition, $form_mode_name);
     }
   }

What I don't really knowis what the right way of fixing this issue is... perhaps we should simply file the issue in the form_mode_manager module issue queue?

bmunslow’s picture

As it turns out, an issue was already in the queue of form_mode_manager module reporting conflict with simplenews.

Cross-referenced this issue.

berdir’s picture

Status: Postponed (maintainer needs more info) » Closed (duplicate)

Thanks, closing as duplicate of that, needs to be fixed there.