Commit 8b54960b authored by catch's avatar catch
Browse files

Issue #2925297 by Spokje, mpp, paulvandenburg, anmolgoyal74, gobinathm, catch,...

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 d0ee369a)
parent 3f4dafb9
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -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 @@ protected function getDiscovery() {
   */
  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);
  }

+11 −0
Original line number Diff line number Diff line
@@ -9,6 +9,7 @@
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 @@ protected function setUp(): void {
  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');