Call to undefined method BaseFieldDefinition::getThirdPartySettings()

Created on 25 January 2023, almost 2 years ago
Updated 15 February 2024, 9 months ago

Problem/Motivation

In upgrading the module from version 1.x to version 2.x on a site using Drupal 9.5.2 and PHP 8.0 I ran across the following PHP error.

Error: Call to undefined method Drupal\Core\Field\BaseFieldDefinition::getThirdPartySettings() in Drupal\comment_delete\CommentDeleteManager->getConfig() (line 114 of modules/contrib/comment_delete/src/CommentDeleteManager.php).

It looks as though we are expecting $commentedEntity->getFieldDefinition($comment->getFieldName()); on line 114 of the CommentDeleteManager.php to return a FieldConfigInterface when in fact it returns a FieldDefinitionInterface which does not use the getThirdPartySettings function.

Steps to reproduce

Upgrade a Drupal 9.5 site, with existing comments, from version 1.x to 2.x of the module
Then visit a comment or the /admin/content/comment page.

Proposed resolution

Change how we get the FieldConfigInterface to get a FieldDefinitionInterface.

πŸ› Bug report
Status

Fixed

Version

2.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States rymcveigh

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @rymcveigh
  • πŸ‡¬πŸ‡·Greece vensires

    @rymcveigh, I have the same problem in a website we have built. I there use the comments as a property in a custom entity though and not using the field UI. In order to get more information, could you tell us if you are using the field UI in your entity with the comments or not?

    • 71038010 committed on 2.x
      Issue #3336542: Call to undefined method BaseFieldDefinition::...
  • Status changed to Fixed over 1 year ago
  • πŸ‡ΊπŸ‡ΈUnited States robphillips

    Confirmed using a comment base field definition. 3.x depends on third_party_settings to allow distinct configurations per comment field instance. Base fields don't implement the ThirdPartySettingsInterface hence the error. However, base fields can define the third_party_settings key in the definition settings (see example below). The module code has been adjusted to support both configuration and custom base fields.

    $fields['comment_extra'] = BaseFieldDefinition::create('comment')
          ->setLabel(t('Custom Comment Field'))
          ->setSetting('comment_type', 'comment')
          ->setSetting('third_party_settings', [
            'comment_delete' => [
              'operation' => [
                'hard' => 'hard',
                'hard_partial' => 'hard_partial',
                'soft' => 'soft',
              ],
              'visibility' => 'visible_multiple',
            ],
          ])
          ->setDefaultValue([
            'status' => CommentItemInterface::OPEN,
          ])
          ->setDisplayConfigurable('form', TRUE)
          ->setDisplayConfigurable('view', TRUE);
  • Automatically closed - issue fixed for 2 weeks with no activity.

  • Status changed to Fixed 9 months ago
  • πŸ‡ΊπŸ‡ΈUnited States rymcveigh

    I ran into this same issue and had to dig for a while to find this solution. Could we update the documentation in either the readme or the module description so that folks have an easier time defining the third-party settings on custom baseFieldDefinitions?

Production build 0.71.5 2024