0

I'm working on the D8 port of my xbbcode module; my latest sources are here.

The module is supposed to let administrators enable individual BBCode tags either in the global default settings or in an individual text format that overrides those defaults.

The settings structure for both is basically (in YAML):

tags:
  abbr:
    module: xbbcode
    enabled: 0
  b:
    module: xbbcode_basic
    enabled: 1
  [...]

The default configuration (set in the annotation comment of my filter plugin class) is

/**
 * Provides a filter that converts BBCode to HTML.
 *
 * @Filter(
 *   id = "xbbcode",
 *   title = @Translation("Convert BBCode into HTML."),
 *   type = Drupal\filter\Plugin\FilterInterface::TYPE_MARKUP_LANGUAGE,
 *   settings = {
 *     "autoclose" = FALSE,
 *     "override" = FALSE,
 *     "tags" = {}
 *   }
 * )
 */

However, when I try to create a new text format, I get the following error:

InvalidArgumentException: The configuration property filters.xbbcode.settings.tags.abbr
doesn't exist.
in Drupal\Core\Config\Schema\ArrayElement->get() 
(line 97 of core/lib/Drupal/Core/Config/Schema/ArrayElement.php).

Drupal\Core\Config\StorableConfigBase->castValue('filters.xbbcode.settings.tags.abbr', Array)
Drupal\Core\Config\StorableConfigBase->castValue('filters.xbbcode.settings.tags', Array)
Drupal\Core\Config\StorableConfigBase->castValue('filters.xbbcode.settings', Array)
Drupal\Core\Config\StorableConfigBase->castValue('filters.xbbcode', Array)
Drupal\Core\Config\StorableConfigBase->castValue('filters', Array)
Drupal\Core\Config\Config->save()
Drupal\Core\Config\Entity\ConfigEntityStorage->doSave('bb2', Object)
Drupal\Core\Entity\EntityStorageBase->save(Object)
Drupal\Core\Config\Entity\ConfigEntityStorage->save(Object)
Drupal\Core\Entity\Entity->save()
Drupal\filter\FilterFormatFormBase->submitForm(Array, Object)
Drupal\filter\FilterFormatAddForm->submitForm(Array, Object)
call_user_func_array(Array, Array)
Drupal\Core\Form\FormSubmitter->executeSubmitHandlers(Array, Object)
Drupal\Core\Form\FormSubmitter->doSubmitForm(Array, Object)
Drupal\Core\Form\FormBuilder->processForm('filter_format_add_form', Array, Object)
Drupal\Core\Form\FormBuilder->buildForm(Object, Object)
Drupal\Core\Controller\FormController->getContentResult(Object, Object)
call_user_func_array(Array, Array)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1)
Drupal\Core\StackMiddleware\PageCache->pass(Object, 1, 1)
Drupal\Core\StackMiddleware\PageCache->handle(Object, 1, 1)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1)
Stack\StackedHttpKernel->handle(Object, 1, 1)
Drupal\Core\DrupalKernel->handle(Object)

Some examination of the StorableConfigBase class reveal that it seems to insist on merging my configuration values with the existing ones, down to the bottom level, and when it doesn't find the "abbr" key it shuts down. This seems pretty silly, because obviously an array can gain or lose entries when you save it.

The weird thing is that the global defaults have absolutely no problem when I change them with $this->config('xbbcode.settings')->set('tags', [...])->save() in my own ConfigFormBase settings form.

Edit: filter.format.* has a config schema, while my module doesn't. I'm not sure how to tell this schema "this array may have a number of keys, each of which has the form {enabled: ..., module: ... }

1

I figured out how to declare the filter settings schema by comparing with modules/filter/config/schema/filter.schema.yml and using the Schema docs.

Apparently my schema file simply needs to declare

filter_settings.xbbcode:
  type: filter
  label: 'XBBCode filter'
  mapping:
    [...]
  • 1
    I have no idea how you managed to not have a config schema in the first place, that seems like a problem, but yes, you should implement a config schema that describes your structure. – Berdir Apr 16 '15 at 17:10
  • It seems that missing schemas on your own settings are simply ignored, and even filter.module somehow gleans an implicit schema from the annotation comment? The keys that were described there didn't run into any problems. :) – Christoph Burschka Apr 16 '15 at 17:24
  • Yes, correct, the default schema is defined as a list of strings. That's extremely weird, everywhere else we force plugins to define their schema. I've opened drupal.org/node/2472927. – Berdir Apr 17 '15 at 6:14

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.