hasOverrides example

    /** @var \Drupal\Core\Config\StorageInterface $overridden_sync */
    $overridden_sync = $sync->createCollection('language.fr');
    $overridden_sync->write('system.site', ['name' => 'French site name']);

    // Before we start the import, the change to the site name should not be     // present. This action also primes the cache in the config factory so that     // we can test whether the cached data is correctly updated.     $config = $this->config('system.site');
    $this->assertNotEquals('English site name', $config->getRawData()['name']);

    // Before the import is started the site name should not yet be overridden.     $this->assertFalse($config->hasOverrides());
    $override = $language_manager->getLanguageConfigOverride('fr', 'system.site');
    $this->assertTrue($override->isNew());

    // Start the import of the new configuration.     $this->configImporter->reset()->import();

    // Verify the new site name in the default language.     $config = $this->config('system.site')->getRawData();
    $this->assertEquals('English site name', $config['name']);

    // Verify the overridden site name.

  public function testOverrideData($data$module_data$setting_data) {
    // Set initial data.     $this->config->setData($data);

    // Check original data was set correctly.     $this->assertConfigDataEquals($data);

    // Save so that the original data is stored.     $this->config->save();
    $this->assertFalse($this->config->hasOverrides());
    $this->assertOverriddenKeys($data[]);

    // Set module override data and check value before and after save.     $this->config->setModuleOverride($module_data);
    $this->assertConfigDataEquals($module_data);
    $this->assertOverriddenKeys($data$module_data);

    $this->config->save();
    $this->assertConfigDataEquals($module_data);
    $this->assertOverriddenKeys($data$module_data);

    
/** * Determines if the menu has configuration overrides. * * @return bool * TRUE if the menu has configuration overrides, otherwise FALSE. */
  protected function hasMenuOverrides() {
    // @todo Replace the following with $this->menu->hasOverrides() in https://www.drupal.org/project/drupal/issues/2910353     // and remove this function.     return $this->configFactory->get($this->menu->getEntityType()
      ->getConfigPrefix() . '.' . $this->menu->id())->hasOverrides();
  }

}
':input[name="layout[enabled]"]' => ['checked' => FALSE],
          ],
          'invisible' => [
            ':input[name="layout[enabled]"]' => ['checked' => FALSE],
          ],
        ],
      ];
      if (!$is_enabled) {
        $form['layout']['allow_custom']['#attributes']['disabled'] = 'disabled';
      }
      // Prevent turning off overrides while any exist.       if ($this->hasOverrides($this->entity)) {
        $form['layout']['enabled']['#disabled'] = TRUE;
        $form['layout']['enabled']['#description'] = $this->t('You must revert all customized layouts of this display before you can disable this option.');
        $form['layout']['allow_custom']['#disabled'] = TRUE;
        $form['layout']['allow_custom']['#description'] = $this->t('You must revert all customized layouts of this display before you can disable this option.');
        unset($form['layout']['allow_custom']['#states']);
        unset($form['#entity_builders']['layout_builder']);
      }
    }
    // For non-canonical modes, the existing value should be preserved.     else {
      $form['layout']['allow_custom'] = [
        
// Unset links to Site Information form, we can make these changes here.     unset($form['block_branding']['use_site_name']['#description']$form['block_branding']['use_site_slogan']['#description']);

    $site_config = $this->configFactory->getEditable('system.site');
    // Load the immutable config to load the overrides.     $site_config_immutable = $this->configFactory->get('system.site');
    $form['site_information'] = [
      '#type' => 'details',
      '#title' => $this->t('Site details'),
      '#open' => TRUE,
      '#access' => $this->currentUser->hasPermission('administer site configuration') && !$site_config_immutable->hasOverrides('name') && !$site_config_immutable->hasOverrides('slogan'),
    ];
    $form['site_information']['site_name'] = [
      '#type' => 'textfield',
      '#title' => $this->t('Site name'),
      '#default_value' => $site_config->get('name'),
      '#required' => TRUE,
    ];
    $form['site_information']['site_slogan'] = [
      '#type' => 'textfield',
      '#title' => $this->t('Slogan'),
      '#default_value' => $site_config->get('slogan'),
      
Home | Imprint | This part of the site doesn't use cookies.