2

Drupal\Core\Config\ConfigNameException: Missing namespace in Config object name media_entity_file_replace. in Drupal\Core\Config\ConfigBase::validateName() (line 97 of core/lib/Drupal/Core/Config/ConfigBase.php).

i don't quite get what i have done wrong in my config form

media_entity_file_replace/src/Form/MediaEntityFileReplaceSettingsForm.php

namespace Drupal\media_entity_file_replace\Form;

use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;

/**
 * Configure media_entity_file_replace settings for this site.
 */
class MediaEntityFileReplaceSettingsForm extends ConfigFormBase {

1 Answer 1

4

The error comes from Drupal\Core\Config\ConfigBase:

public static function validateName($name) {
  // The name must be namespaced by owner.
  if (strpos($name, '.') === FALSE) {
    throw new ConfigNameException("Missing namespace in Config object name {$name}.");
  }
...

Do you reference a configuration object somewhere in your form without a period? For example:

$config = \Drupal::config('config_with_no_namespace');
3
  • 3
    This is the reason. I understand why the reason of the exception is not much clear: The documentation for \Drupal::config() doesn't make it explicit; it just says that the name of the configuration object, passed to the method, typically corresponds to a configuration file. If the configuration file is media_entity_file_replace.yml, passing media_entity_file_replace to Drupal::config() seems correct.
    – avpaderno
    Commented Dec 23, 2021 at 20:44
  • 3
    I agree that it's not clear. I'm sure you get it, but for people who may be confused by this, the rationale is that it avoids configuration name clashes - you might have a configuration for your module called general_settings but so might many other modules, namespacing it with the module name ensures it's unique, e.g. mymodule.general_settings.
    – Geat
    Commented Dec 23, 2021 at 22:22
  • fixed with renaming config/install/media_entity_file_replace.settings.yml and $config = $this->config('media_entity_file_replace.settings');
    – Matoeil
    Commented Dec 24, 2021 at 10:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.