Verified Commit 11426693 authored by Dave Long's avatar Dave Long
Browse files

Issue #3394197 by lauriii, phenaproxima, Wim Leers, longwave, smustgrave,...

Issue #3394197 by lauriii, phenaproxima, Wim Leers, longwave, smustgrave, moshe weitzman: [regression] The new property \Drupal\Core\Form\ConfigFormBase::$typedConfigManager conflicts with some contrib modules

(cherry picked from commit a9865eb3)
parent 2131d249
Loading
Loading
Loading
Loading
Loading
+19 −7
Original line number Diff line number Diff line
@@ -40,12 +40,13 @@ abstract class ConfigFormBase extends FormBase {
   */
  public function __construct(
    ConfigFactoryInterface $config_factory,
    protected ?TypedConfigManagerInterface $typedConfigManager = NULL,
    protected $typedConfigManager = NULL,
  ) {
    $this->setConfigFactory($config_factory);
    if ($this->typedConfigManager === NULL) {
      @trigger_error('Calling ConfigFormBase::__construct() without the $typedConfigManager argument is deprecated in drupal:10.2.0 and will be required in drupal:11.0.0. See https://www.drupal.org/node/3373502', E_USER_DEPRECATED);
      $this->typedConfigManager = \Drupal::service('config.typed');

    if (!$typedConfigManager instanceof TypedConfigManagerInterface) {
      $type = get_debug_type($typedConfigManager);
      @trigger_error("Passing $type to the \$typedConfigManager parameter of ConfigFormBase::__construct() is deprecated in drupal:10.2.0 and must be an instance of \Drupal\Core\Config\TypedConfigManagerInterface in drupal:11.0.0. See https://www.drupal.org/node/3404140", E_USER_DEPRECATED);
    }
  }

@@ -59,6 +60,19 @@ public static function create(ContainerInterface $container) {
    );
  }

  /**
   * Returns the typed config manager service.
   *
   * @return \Drupal\Core\Config\TypedConfigManagerInterface
   *   The typed config manager service.
   */
  protected function typedConfigManager(): TypedConfigManagerInterface {
    if ($this->typedConfigManager instanceof TypedConfigManagerInterface) {
      return $this->typedConfigManager;
    }
    return \Drupal::service('config.typed');
  }

  /**
   * {@inheritdoc}
   */
@@ -158,13 +172,11 @@ public function storeConfigKeyToFormElementMap(array $element, FormStateInterfac
   * {@inheritdoc}
   */
  public function validateForm(array &$form, FormStateInterface $form_state) {
    assert($this->typedConfigManager instanceof TypedConfigManagerInterface);

    $map = $form_state->get(static::CONFIG_KEY_TO_FORM_ELEMENT_MAP) ?? [];
    foreach (array_keys($map) as $config_name) {
      $config = $this->configFactory()->getEditable($config_name);
      static::copyFormValuesToConfig($config, $form_state, $form);
      $typed_config = $this->typedConfigManager->createFromNameAndData($config_name, $config->getRawData());
      $typed_config = $this->typedConfigManager()->createFromNameAndData($config_name, $config->getRawData());

      $violations = $typed_config->validate();
      // Rather than immediately applying all violation messages to the