1

I have a custom field setup that I created similar to this tutorial. I exported all my fields on my node to a test module and enable it during my PHPUnit test.

I run my test with the following command:

php ./core/scripts/run-tests.sh --verbose --php /usr/local/bin/php --url http://nginx --class "Drupal\my_module\Tests\ExpenseTest"

And I get the following error:

The test did not complete due to a fatal error.
Exception Uncaught e ConfigSchemaCheck   95 Drupal\Core\Config\Development\Conf
Drupal\Core\Config\Schema\SchemaIncompleteException: Schema errors for
core.entity_form_display.paragraph.my_field.default with the
following errors:
core.entity_form_display.paragraph.my_field.default:content.field_city_state.settings.size
missing schema,
core.entity_form_display.paragraph.my_field.default:content.field_city_state.settings.autocomplete_route_name
missing schema,
core.entity_form_display.paragraph.my_field.default:content.field_city_state.settings.placeholder
missing schema in
Drupal\Core\Config\Development\ConfigSchemaChecker->onConfigSave() (line
95 of

This is part of my core.entity_form_display.paragraph.my_field.default.yml file:

field_city_state:
weight: 2
settings:
  size: '60'
  autocomplete_route_name: my_module.city_autocomplete
  placeholder: ''
third_party_settings: {  }
type: city_state_default
region: content

If I remove the settings it doesn't give me the error (Although I am not testing that field yet).

This is my module's Field Type Class:

<?php

namespace Drupal\my_module\Plugin\Field\FieldType;

use Drupal\Core\Field\FieldItemBase;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\Core\TypedData\DataDefinition;
use Drupal\Core\Field\FieldItemInterface;

/**
 * Plugin implementation of the 'city_state' field type.
 *
 * @FieldType(
 *   id = "city_state",
 *   label = @Translation("City/State"),
 *   description = @Translation("An entity field containing city/state"),
 *   category = @Translation("Address"),
 *   default_widget = "city_state_default",
 *   default_formatter = "city_state_default"
 * )
 */
class CityStateItem extends FieldItemBase implements FieldItemInterface {

  /**
   * {@inheritdoc}
   */
  public static function schema(FieldStorageDefinitionInterface $field_definition) {
    return [
      'columns' => [
        'state_code' => [
          'type' => 'varchar',
          'length' => 2,
        ],
        'city' => [
          'type' => 'varchar',
          'length' => 255,
        ],
      ],
    ];
  }

  /**
   * {@inheritdoc}
   */
  public static function propertyDefinitions(FieldStorageDefinitionInterface $field_definition) {
    $properties['state_code'] = DataDefinition::create('string')->setLabel(t('State Code'));
    $properties['city'] = DataDefinition::create('string')->setLabel(t('City'));

    return $properties;
  }

  /**
   * {@inheritdoc}
   */
  public function isEmpty() {
    $value = $this->state_code;
    return $value === NULL || $value === '';
  }

  /**
   * Get city string.
   *
   * @return string
   *   Returns city name.
   */
  public function getCity() {
    return $this->city;
  }

  /**
   * Get state code string.
   *
   * @return string
   *   Returns the state code.
   */
  public function getStateCode() {
    return $this->state_code;
  }

}

This is my module's schema file:

city_state:
  type: mapping
  label: 'City/State settings'
  mapping:
    state_code:
      type: string
      label: 'State Code'
    city:
      type: string
      label: 'City'

Don't understand why I am getting this error and only during Testing. (No issues when running config import on dev and staging).

  • After removing the settings items and just have settings: { } I was able to still save to the custom field. – albertski Feb 18 '18 at 22:40
3

You only get that error during testing because the core testing base classes add a config schema checker during testing.

You have 2 options, the first is the easiest, but is not recommended, and that is to disable the strict config checking in your test by setting this variable to false in your test class:

  /**
   * Set to TRUE to strict check all configuration saved.
   *
   * @see \Drupal\Core\Config\Development\ConfigSchemaChecker
   *
   * @var bool
   */
  protected $strictConfigSchema = FALSE;

This approach is not preferred because you then have invalid config schema data in your module. It would be far better to fix the schema.

Instead of city_state: in your schema file, something more specific like:

field.field_settings.city_state:

or since this appears to be display related, it might be

field.formatter.settings.city_state:

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.