getConfigNames example



  /** * Tests adding config names to mapper. */
  public function testAddingConfigNames() {
    // Get a config names mapper.     $mappers = \Drupal::service('plugin.manager.config_translation.mapper')->getMappers();
    $mapper = $mappers['system.site_information_settings'];

    // Test that it doesn't contain a config name from config_translation_test.     $config_names = $mapper->getConfigNames();
    $this->assertNotContains('config_translation_test.content', $config_names);

    // Call populateFromRouteMatch() to dispatch the "config mapper populate"     // event.     $mapper->populateFromRouteMatch(new RouteMatch('test', new Route('/')));

    // Test that it contains the new config name from config_translation_test.     $config_names = $mapper->getConfigNames();
    $this->assertContains('config_translation_test.content', $config_names);
  }

}
// Add some information to the form state for easier form altering.     $form_state->set('config_translation_mapper', $this->mapper);
    $form_state->set('config_translation_language', $this->language);
    $form_state->set('config_translation_source_language', $this->sourceLanguage);

    $form['#attached']['library'][] = 'config_translation/drupal.config_translation.admin';

    // Even though this is a nested form, we do not set #tree to TRUE because     // the form value structure is generated by using #parents for each element.     // @see \Drupal\config_translation\FormElement\FormElementBase::getElements()     $form['config_names'] = ['#type' => 'container'];
    foreach ($this->mapper->getConfigNames() as $name) {
      $form['config_names'][$name] = ['#type' => 'container'];

      $schema = $this->typedConfigManager->get($name);
      $source_config = $this->baseConfigData[$name];
      $translation_config = $this->configFactory()->get($name)->get();

      if ($form_element = $this->createFormElement($schema)) {
        $parents = ['config_names', $name];
        $form['config_names'][$name] += $form_element->getTranslationBuild($this->sourceLanguage, $this->language, $source_config$translation_config$parents);
      }
    }

    


    $this->mapper = $mapper;
    $this->language = $language;
    return parent::buildForm($form$form_state);
  }

  /** * {@inheritdoc} */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    foreach ($this->mapper->getConfigNames() as $name) {
      $this->languageManager->getLanguageConfigOverride($this->language->getId()$name)->delete();
    }

    // Flush all persistent caches.     $this->moduleHandler->invokeAll('cache_flush');
    foreach (Cache::getBins() as $cache_backend) {
      $cache_backend->deleteAll();
    }

    $this->messenger()->addStatus($this->t('@language translation of %label was deleted', ['%label' => $this->mapper->getTitle(), '@language' => $this->language->getName()]));

    
'_config_translation_form_access' => 'TRUE',
      ]
    );
    $result = $this->configNamesMapper->getDeleteRoute();
    $this->assertSame(serialize($expected)serialize($result));
  }

  /** * Tests ConfigNamesMapper::getConfigNames(). */
  public function testGetConfigNames() {
    $result = $this->configNamesMapper->getConfigNames();
    $this->assertSame($this->pluginDefinition['names']$result);
  }

  /** * Tests ConfigNamesMapper::addConfigName(). */
  public function testAddConfigName() {
    $names = $this->configNamesMapper->getConfigNames();
    $this->configNamesMapper->addConfigName('test');
    $names[] = 'test';
    $result = $this->configNamesMapper->getConfigNames();
    
$languages = $this->languageManager->getLanguages();
    if (count($languages) == 1) {
      $this->messenger()->addWarning($this->t('In order to translate configuration, the website must have at least two <a href=":url">languages</a>.', [':url' => Url::fromRoute('entity.configurable_language.collection')->toString()]));
    }

    try {
      $original_langcode = $mapper->getLangcode();
      $operations_access = TRUE;
    }
    catch (ConfigMapperLanguageException $exception) {
      $items = [];
      foreach ($mapper->getConfigNames() as $config_name) {
        $langcode = $mapper->getLangcodeFromConfig($config_name);
        $items[] = $this->t('@name: @langcode', [
          '@name' => $config_name,
          '@langcode'  => $langcode,
        ]);
      }
      $message = [
        'message' => ['#markup' => $this->t('The configuration objects have different language codes so they cannot be translated:')],
        'items' => [
          '#theme' => 'item_list',
          '#items' => $items,
        ],
/** * {@inheritdoc} */
  public function getTypeLabel() {
    return $this->getTitle();
  }

  /** * {@inheritdoc} */
  public function getLangcode() {
    $langcodes = array_map([$this, 'getLangcodeFromConfig']$this->getConfigNames());

    if (count(array_unique($langcodes)) > 1) {
      throw new ConfigMapperLanguageException('A config mapper can only contain configuration for a single language.');
    }

    return reset($langcodes);
  }

  /** * {@inheritdoc} */
  
Home | Imprint | This part of the site doesn't use cookies.