Issue #2925297 by Spokje, mpp, paulvandenburg, anmolgoyal74, gobinathm, catch, mmrares, shubhangi1995, Martijn de Wit: Fatal error on config form with translation enabled when config is missing
(cherry picked from commit d0ee369a05
)
merge-requests/2670/head
parent
ce4429b692
commit
ba5b309131
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace Drupal\Core\Config;
|
||||
|
||||
use Drupal\Component\Render\FormattableMarkup;
|
||||
use Drupal\Component\Utility\NestedArray;
|
||||
use Drupal\Core\Cache\CacheBackendInterface;
|
||||
use Drupal\Core\Config\Schema\ConfigSchemaAlterException;
|
||||
|
@ -75,6 +76,13 @@ class TypedConfigManager extends TypedDataManager implements TypedConfigManagerI
|
|||
*/
|
||||
public function get($name) {
|
||||
$data = $this->configStorage->read($name);
|
||||
if ($data === FALSE) {
|
||||
// For a typed config the data MUST exist.
|
||||
$data = [];
|
||||
trigger_error(new FormattableMarkup('Missing required data for typed configuration: @config', [
|
||||
'@config' => $name,
|
||||
]), E_USER_ERROR);
|
||||
}
|
||||
return $this->createFromNameAndData($name, $data);
|
||||
}
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@ use Drupal\Core\TypedData\ComplexDataInterface;
|
|||
use Drupal\Core\TypedData\Type\IntegerInterface;
|
||||
use Drupal\Core\TypedData\Type\StringInterface;
|
||||
use Drupal\KernelTests\KernelTestBase;
|
||||
use PHPUnit\Framework\Error\Error;
|
||||
use Symfony\Component\Validator\ConstraintViolationListInterface;
|
||||
|
||||
/**
|
||||
|
@ -38,6 +39,16 @@ class TypedConfigTest extends KernelTestBase {
|
|||
public function testTypedDataAPI() {
|
||||
/** @var \Drupal\Core\Config\TypedConfigManagerInterface $typed_config_manager */
|
||||
$typed_config_manager = \Drupal::service('config.typed');
|
||||
|
||||
// Test non-existent data.
|
||||
try {
|
||||
$typed_config_manager->get('config_test.non_existent');
|
||||
$this->fail('Expected error when trying to get non-existent typed config.');
|
||||
}
|
||||
catch (Error $e) {
|
||||
$this->assertEquals('Missing required data for typed configuration: config_test.non_existent', $e->getMessage());
|
||||
}
|
||||
|
||||
/** @var \Drupal\Core\Config\Schema\TypedConfigInterface $typed_config */
|
||||
$typed_config = $typed_config_manager->get('config_test.validation');
|
||||
|
||||
|
|
Loading…
Reference in New Issue