Drupal 8.0.1

When adding a new field of type 'Mailchimp Subscription' I get the following error.

Fatal error: Declaration of Drupal\mailchimp_lists\Plugin\Field\FieldFormatter\MailchimpListsSubscribeDefaultFormatter::viewElements() must be compatible with Drupal\Core\Field\FormatterInterface::viewElements(Drupal\Core\Field\FieldItemListInterface $items, $langcode) in /XXXX/public_html/modules/mailchimp/modules/mailchimp_lists/src/Plugin/Field/FieldFormatter/MailchimpListsSubscribeDefaultFormatter.php on line 24

It allows the creation of the field still, but you cannot do the following "Select a list to sync with on the Field Settings tab before configuring the field instance." - because the field settings tab throws the following fatal error.

Fatal error: Cannot access protected property Drupal\field\Entity\FieldConfig::$field_type in /XXXX/public_html/modules/mailchimp/modules/mailchimp_lists/mailchimp_lists.module on line 54

Looks like on line 48

$storage = $form_state->getStorage();

$storage is now protected (haven't looked to see what it was before) and therefore

if ($field_config->field_type == 'mailchimp_lists_subscription') {

is no longer evaluating.

This then prevents me from selecting a list for the field.

Comments

mikefyfer created an issue. See original summary.

mikefyfer’s picture

Status: Active » Closed (duplicate)
Related issues: +#2628058: Cannot access protected property

Marking as a duplicate of this issue - https://www.drupal.org/node/2628058

On line 53 of the mailchimp_lists.module file a protected property is retrieved which throws an error on editing any field settings form.

if ($field_config->field_type == 'mailchimp_lists_subscription') {

This should be changed to

if ($field_config->getType() == 'mailchimp_lists_subscription') {
mikefyfer’s picture

Title: Fatal error: Cannot access protected property Drupal\field\Entity\FieldConfig » Fatal error: Declaration of Drupal\mailchimp_lists\Plugin\Field\FieldFormatter\MailchimpListsSubscribeDefaultFormatter::viewElements() must be compatible with Drupal\Core\Field\FormatterInterface::viewElements(Drupal\Core\Field\FieldItemListInterface $ite
Status: Closed (duplicate) » Active

Changing title to reflect the main issue, the issue that was marked as a duplicate was really only in reference to the second part of this issue.

mikefyfer’s picture

Title: Fatal error: Declaration of Drupal\mailchimp_lists\Plugin\Field\FieldFormatter\MailchimpListsSubscribeDefaultFormatter::viewElements() must be compatible with Drupal\Core\Field\FormatterInterface::viewElements(Drupal\Core\Field\FieldItemListInterface $ite » When adding a new field of type 'Mailchimp Subscription' get fatal error.
Fonkel’s picture

Any update on this issue? Currently this blocks me from making a viewmode for sending contact form emails.

  • ruscoe committed 78c6e76 on 8.x-1.x
    Issue #2635974 by mikefyfer: Fatal error when adding Mailchimp...
ruscoe’s picture

Status: Active » Fixed

Thanks for the report. This is now fixed in the 8.x-1.x dev branch.

Badlapje’s picture

Not sure this is fixed, i've just tried to create a simple content type with an email field and i'm getting this error:

Fatal error: Declaration of Drupal\mailchimp_lists\Plugin\Field\FieldFormatter\MailchimpListsSubscribeDefaultFormatter::viewElements(Drupal\Core\Field\FieldItemListInterface $items) must be compatible with Drupal\Core\Field\FormatterInterface::viewElements(Drupal\Core\Field\FieldItemListInterface $items, $langcode) in rootofmysite\modules\mailchimp\modules\mailchimp_lists\src\Plugin\Field\FieldFormatter\MailchimpListsSubscribeDefaultFormatter.php on line 0

Although additionally i should note i don't see any configuration options for mailchimp after enabling all 4 modules.

mikefyfer’s picture

Version: 8.x-1.0-alpha2 » 8.x-1.x-dev
Status: Fixed » Active

Yeah, I'm going to reopen this. I just installed the latest dev and I'm still experiencing the same issue.

  • ruscoe committed 3f50bb3 on 8.x-1.x
    Issue #2635974 by mikefyfer: Fatal error when adding Mailchimp...
ruscoe’s picture

I wasn't able to reproduce the error with MailchimpListsSubscribeDefaultFormatter, but the error message in #8 shows MailchimpListsSubscribeDefaultFormatter::viewElements missing its second parameter ($langcode).

@Badlapje / @mikefyfer, would you mind checking your version of MailchimpListsSubscribeDefaultFormatter.php matches this line?

Related - I noticed the same problem existed in MailchimpListsFieldSubscribeFormatter. This commit adds the missing parameter there.

ruscoe’s picture

Status: Active » Closed (cannot reproduce)