Error when instantiating custom field in custom module

I apologize if the answer to this is obvious, but I am newly-embarked on porting a number of complex custom Drupal 7 modules to Drupal 9. I am using Drupal version 9.3.6, PHP version 7.4.28, mysql, apache2. I have created a custom field as follows, which on install goes without errors and appears in the field list report:

langcode: en status: true dependencies:   module:     - user   enforced:     module:       - test_module id: user.field_test field_name: field_test entity_type: user type: string_long settings:   case_sensitive: false module: core locked: false cardinality: 1 translatable: true indexes: {  } persist_with_no_fields: false custom_storage: false 

But when I try to instantiate it, either with field.field.user.user.field_test.yml or manually through the UI, I get the following error stack:

 [warning] A non-numeric value encountered TypedConfigManager.php:189  [error]  Error: Unsupported operand types in DrupalCoreConfigTypedConfigManager->getDefinitionWithReplacements() (line 189 of /var/www/test_site/web/core/lib/Drupal/Core/Config/TypedConfigManager.php) #0 /var/www/test_site/web/core/lib/Drupal/Core/Config/TypedConfigManager.php(105): DrupalCoreConfigTypedConfigManager->getDefinitionWithReplacements() 

(Sorry, I had to delete the remainder of the stack dump to avoid getting flagged as spam!)

This is the part of TypedConfigManager as follows:

    // Add type and default definition class.     $definition += [       'definition_class' => 'DrupalCoreTypedDataDataDefinition', // Here is line 189       'type' => $type,       'unwrap_for_canonical_representation' => TRUE,     ];     return $definition; 

I am at a loss here. If I create the field storage through the admin interface and instantiate also through the admin interface, everything works fine. I export those definitions through the single export interface, and then I get the failure.

Thank you in advance for any insight!

This article was republished from its original source.
Call Us: 1(800)730-2416

Pixeldust is a 20-year-old web development agency specializing in Drupal and WordPress and working with clients all over the country. With our best in class capabilities, we work with small businesses and fortune 500 companies alike. Give us a call at 1(800)730-2416 and let’s talk about your project.

FREE Drupal SEO Audit

Test your site below to see which issues need to be fixed. We will fix them and optimize your Drupal site 100% for Google and Bing. (Allow 30-60 seconds to gather data.)

Powered by

Error when instantiating custom field in custom module

On-Site Drupal SEO Master Setup

We make sure your site is 100% optimized (and stays that way) for the best SEO results.

With Pixeldust On-site (or On-page) SEO we make changes to your site’s structure and performance to make it easier for search engines to see and understand your site’s content. Search engines use algorithms to rank sites by degrees of relevance. Our on-site optimization ensures your site is configured to provide information in a way that meets Google and Bing standards for optimal indexing.

This service includes:

  • Pathauto install and configuration for SEO-friendly URLs.
  • Meta Tags install and configuration with dynamic tokens for meta titles and descriptions for all content types.
  • Install and fix all issues on the SEO checklist module.
  • Install and configure XML sitemap module and submit sitemaps.
  • Install and configure Google Analytics Module.
  • Install and configure Yoast.
  • Install and configure the Advanced Aggregation module to improve performance by minifying and merging CSS and JS.
  • Install and configure Schema.org Metatag.
  • Configure robots.txt.
  • Google Search Console setup snd configuration.
  • Find & Fix H1 tags.
  • Find and fix duplicate/missing meta descriptions.
  • Find and fix duplicate title tags.
  • Improve title, meta tags, and site descriptions.
  • Optimize images for better search engine optimization. Automate where possible.
  • Find and fix the missing alt and title tag for all images. Automate where possible.
  • The project takes 1 week to complete.