Views error: missing schema in Drupal\Core\Config\Development\ConfigSchemaChecker
2 min readJun 1, 2021
Drupal\Core\Config\Schema\SchemaIncompleteException: Schema errors for views.view.audit_log with the following errors: views.view.audit_log:display.advanced_audit_log_page.display_options.exposed_form.options missing schema in Drupal\Core\Config\Development\ConfigSchemaChecker->onConfigSave() (line 94 of core/lib/Drupal/Core/Config/Development/ConfigSchemaChecker.php).
I created a custom @ViewsExposedForm()
<?php
namespace Drupal\custom_audit_log\Plugin\views\exposed_form;
use Drupal\Core\Form\FormStateInterface;
use Drupal\views\Plugin\views\exposed_form\ExposedFormPluginBase;
/**
* Exposed form plugin that provides an exposed form on Audit log views.
*
* @ingroup views_exposed_form_plugins
*
* @ViewsExposedForm(
* id = "custom_audit_log_exposed_form",
* title = @Translation("Audit Log exposed form"),
* help = @Translation("Audit Log exposed form")
* )
*/
class AuditLogExposedForm extends ExposedFormPluginBase {
/**
* {@inheritdoc}
*/
public function exposedFormAlter(&$form, FormStateInterface $form_state) {
if (isset($form['user_name']) && isset($form['user_mail'])) {
$form['user_name']['#access'] = FALSE;
$form['user_mail']['#access'] = FALSE;
$form['name_or_mail'] = [
'#title' => $this->t('User name or email'),
'#type' => 'textfield',
'#size' => 50,
];
$form['#submit'][] = [$this, 'customFormSubmit'];
}
}
/**
* {@inheritdoc}
*/
public function exposedFormSubmit(&$form, FormStateInterface $form_state, &$exclude) {
// Exlude the "name_or_mail" from view exposed_raw_input.
// User can search by user name or user email on this input.
// But on the backend we split the value on two separeted conditions.
/* @see AuditLogExposedForm::customFormSubmit() */
$exclude[] = 'name_or_mail';
parent::exposedFormSubmit($form, $form_state, $exclude);
}
/**
* Set the user_name and user_mail fields.
*
* @param array $form
* An associative array containing the structure of the form.
* @param \Drupal\Core\Form\FormStateInterface $form_state
* The current state of the form.
*
* @noinspection PhpUnusedParameterInspection
*/
public function customFormSubmit(array &$form, FormStateInterface $form_state) {
$name_or_mail = trim($form_state->getValue('name_or_mail'));
$form_state->setValue('user_name', $name_or_mail);
$form_state->setValue('user_mail', $name_or_mail);
}
}
And after saving the view I got an error
Drupal\Core\Config\Schema\SchemaIncompleteException: Schema errors for views.view.audit_log with the following errors: views.view.audit_log:display.advanced_audit_log_page.display_options.exposed_form.options missing schema in Drupal\Core\Config\Development\ConfigSchemaChecker->onConfigSave() (line 94 of core/lib/Drupal/Core/Config/Development/ConfigSchemaChecker.php).
To fix I create schema file:
modules/custom_audit_log/config/schema/custom_audit_log.exposed_form.schema.yml
# Schema for the views exposed form.
views.exposed_form.custom_audit_log_exposed_form:
type: views_exposed_form
label: 'Audit Log exposed form'