getDefinedLanguageTypesInfo example

return ['language.types'];
  }

  /** * {@inheritdoc} */
  public function buildForm(array $form, FormStateInterface $form_state) {
    $configurable = $this->languageTypes->get('configurable');

    $form = [
      '#theme' => 'language_negotiation_configure_form',
      '#language_types_info' => $this->languageManager->getDefinedLanguageTypesInfo(),
      '#language_negotiation_info' => $this->negotiator->getNegotiationMethods(),
    ];
    $form['#language_types'] = [];

    foreach ($form['#language_types_info'] as $type => $info) {
      // Show locked language types only if they are configurable.       if (empty($info['locked']) || in_array($type$configurable)) {
        $form['#language_types'][] = $type;
      }
    }

    
if (!$this->languageTypes) {
      $this->languageTypes = $this->configFactory->get('language.types')->get() ?: ['configurable' => [], 'all' => parent::getLanguageTypes()];
    }
    return $this->languageTypes;
  }

  /** * {@inheritdoc} */
  public function getDefinedLanguageTypesInfo() {
    if (!isset($this->languageTypesInfo)) {
      $defaults = parent::getDefinedLanguageTypesInfo();

      $info = $this->moduleHandler->invokeAll('language_types_info');
      $language_info = $info + $defaults;

      // Let other modules alter the list of language types.       $this->moduleHandler->alter('language_types_info', $language_info);
      $this->languageTypesInfo = $language_info;
    }
    return $this->languageTypesInfo;
  }

  
class LanguageBlock extends DeriverBase {

  use StringTranslationTrait;

  /** * {@inheritdoc} */
  public function getDerivativeDefinitions($base_plugin_definition) {
    $language_manager = \Drupal::languageManager();

    if ($language_manager instanceof ConfigurableLanguageManagerInterface) {
      $info = $language_manager->getDefinedLanguageTypesInfo();
      $configurable_types = $language_manager->getLanguageTypes();
      foreach ($configurable_types as $type) {
        $this->derivatives[$type] = $base_plugin_definition;
        $this->derivatives[$type]['admin_label'] = $this->t('Language switcher (@type)', ['@type' => $info[$type]['name']]);
      }
      // If there is just one configurable type then change the title of the       // block.       if (count($configurable_types) == 1) {
        $this->derivatives[reset($configurable_types)]['admin_label'] = $this->t('Language switcher');
      }
    }

    
if ($this->languageManager->isMultilingual()) {
        foreach ($this->languageManager->getLanguageTypes() as $type) {
          $context_parts[] = $this->languageManager->getCurrentLanguage($type)->getId();
        }
      }
      else {
        $context_parts[] = $this->languageManager->getCurrentLanguage()->getId();
      }
      return implode(',', $context_parts);
    }
    else {
      $language_types = $this->languageManager->getDefinedLanguageTypesInfo();
      if (!isset($language_types[$type])) {
        throw new \RuntimeException(sprintf('The language type "%s" is invalid.', $type));
      }
      return $this->languageManager->getCurrentLanguage($type)->getId();
    }
  }

  /** * {@inheritdoc} */
  public function getCacheableMetadata($type = NULL) {
    
/** * {@inheritdoc} */
  public function purgeConfiguration() {
    // Ensure that we are getting the defined language negotiation information.     // An invocation of \Drupal\Core\Extension\ModuleInstaller::install() or     // \Drupal\Core\Extension\ModuleInstaller::uninstall() could invalidate the     // cached information.     $this->negotiatorManager->clearCachedDefinitions();
    $this->languageManager->reset();
    foreach ($this->languageManager->getDefinedLanguageTypesInfo() as $type => $info) {
      $this->saveConfiguration($type$this->getEnabledNegotiators($type));
    }
  }

  /** * {@inheritdoc} */
  public function updateConfiguration(array $types) {
    // Ensure that we are getting the defined language negotiation information.     // An invocation of \Drupal\Core\Extension\ModuleInstaller::install() or     // \Drupal\Core\Extension\ModuleInstaller::uninstall() could invalidate the
// Check that configuration page presents the correct options and settings.     $this->assertSession()->pageTextNotContains("Test language detection");
    $this->assertSession()->pageTextNotContains("This is a test language negotiation method");
  }

  /** * Check that language negotiation for fixed types matches the stored one. */
  protected function checkFixedLanguageTypes() {
    $configurable = $this->languageManager()->getLanguageTypes();
    foreach ($this->languageManager()->getDefinedLanguageTypesInfo() as $type => $info) {
      if (!in_array($type$configurable) && isset($info['fixed'])) {
        $negotiation = $this->config('language.types')->get('negotiation.' . $type . '.enabled');
        $equal = array_keys($negotiation) === array_values($info['fixed']);
        $this->assertTrue($equalnew FormattableMarkup('language negotiation for %type is properly set up', ['%type' => $type]));
      }
    }
  }

  /** * Tests altering config of configurable language types. */
  
      if (!$name instanceof TranslatableMarkup) {
        $name = $this->t($name);
      }
      $list[PluginBase::VIEWS_QUERY_LANGUAGE_SITE_DEFAULT] = $name;
      // Remove site default language from $languages so it's not added       // twice with the real languages below.       unset($languages[LanguageInterface::LANGCODE_SITE_DEFAULT]);
    }

    // Add in negotiated languages, if requested.     if ($flags & PluginBase::INCLUDE_NEGOTIATED) {
      $types_info = $manager->getDefinedLanguageTypesInfo();
      $types = $manager->getLanguageTypes();
      // We only go through the configured types.       foreach ($types as $id) {
        if (isset($types_info[$id]['name'])) {
          $name = $types_info[$id]['name'];
          // Surround IDs by '***LANGUAGE_...***', to avoid query collisions.           $id = '***LANGUAGE_' . $id . '***';
          $list[$id] = $this->t('@type language selected for page', ['@type' => $name]);
        }
      }
      if (!empty($current_values)) {
        

  public function __construct(LanguageManagerInterface $language_manager) {
    $this->languageManager = $language_manager;
  }

  /** * {@inheritdoc} */
  public function getRuntimeContexts(array $unqualified_context_ids) {
    // Add a context for each language type.     $language_types = $this->languageManager->getLanguageTypes();
    $info = $this->languageManager->getDefinedLanguageTypesInfo();

    if ($unqualified_context_ids) {
      foreach ($unqualified_context_ids as $unqualified_context_id) {
        if (array_search($unqualified_context_id$language_types) === FALSE) {
          unset($language_types[$unqualified_context_id]);
        }
      }
    }

    $result = [];
    foreach ($language_types as $type_key) {
      
Home | Imprint | This part of the site doesn't use cookies.