SchemaListenerController.php in Drupal 10
File
core/modules/config/tests/config_test/src/SchemaListenerController.php
View source
<?php
namespace Drupal\config_test;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Config\Schema\SchemaIncompleteException;
use Drupal\Core\Controller\ControllerBase;
use Symfony\Component\DependencyInjection\ContainerInterface;
class SchemaListenerController extends ControllerBase {
public function __construct(ConfigFactoryInterface $config_factory) {
$this->configFactory = $config_factory;
}
public static function create(ContainerInterface $container) {
return new static($container
->get('config.factory'));
}
public function test() {
try {
$this->configFactory
->getEditable('config_schema_test.schemaless')
->set('foo', 'bar')
->save();
} catch (SchemaIncompleteException $e) {
return [
'#markup' => $e
->getMessage(),
];
}
}
}