isMultilingual example

$user_preferred_langcode = $register ? $language_interface->getId() : $account->getPreferredLangcode();

    $user_preferred_admin_langcode = $register ? $language_interface->getId() : $account->getPreferredAdminLangcode(FALSE);

    // Is the user preferred language added?     $user_language_added = FALSE;
    if ($this->languageManager instanceof ConfigurableLanguageManagerInterface) {
      $negotiator = $this->languageManager->getNegotiator();
      $user_language_added = $negotiator && $negotiator->isNegotiationMethodEnabled(LanguageNegotiationUser::METHOD_ID, LanguageInterface::TYPE_INTERFACE);
    }
    $form['language'] = [
      '#type' => $this->languageManager->isMultilingual() ? 'details' : 'container',
      '#title' => $this->t('Language settings'),
      '#open' => TRUE,
      // Display language selector when either creating a user on the admin       // interface or editing a user account.       '#access' => !$self_register,
    ];

    $form['language']['preferred_langcode'] = [
      '#type' => 'language_select',
      '#title' => $this->t('Site language'),
      '#languages' => LanguageInterface::STATE_CONFIGURABLE,
      
$container->get('language_manager'),
      $configuration,
      $plugin_id,
      $plugin_definition
    );
  }

  /** * {@inheritdoc} */
  public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
    if ($this->languageManager->isMultilingual()) {
      // Fetch languages.       $languages = $this->languageManager->getLanguages();
      $langcodes_options = [];
      foreach ($languages as $language) {
        $langcodes_options[$language->getId()] = $language->getName();
      }
      $form['langcodes'] = [
        '#type' => 'checkboxes',
        '#title' => $this->t('Language selection'),
        '#default_value' => $this->configuration['langcodes'],
        '#options' => $langcodes_options,
        

  public function getActiveMultiple($entity_type_id, array $entity_ids, array $contexts = NULL) {
    $active = [];

    if (!isset($contexts)) {
      $contexts = $this->contextRepository->getAvailableContexts();
    }

    // @todo Consider implementing a more performant version of this logic fully     // supporting multiple entities in https://www.drupal.org/node/3031082.     $langcode = $this->languageManager->isMultilingual()
      ? $this->getContentLanguageFromContexts($contexts)
      : $this->languageManager->getDefaultLanguage()->getId();

    $entities = $this->entityTypeManager
      ->getStorage($entity_type_id)
      ->loadMultiple($entity_ids);

    foreach ($entities as $id => $entity) {
      // Retrieve the fittest revision, if needed.       if ($entity instanceof RevisionableInterface && $entity->getEntityType()->isRevisionable()) {
        $entity = $this->getLatestTranslationAffectedRevision($entity$langcode);
      }


  /** * {@inheritdoc} */
  protected function getUrlInfo(ResultRow $row) {
    $template = $this->getEntityLinkTemplate();
    $entity = $this->getEntity($row);
    if ($entity === NULL) {
      return NULL;
    }
    if ($this->languageManager->isMultilingual()) {
      $entity = $this->getEntityTranslationByRelationship($entity$row);
    }
    return $entity->toUrl($template)->setAbsolute($this->options['absolute']);
  }

  /** * Returns the entity link template name identifying the link route. * * @returns string * The link template name. */
  

  public function getContext($type = NULL) {
    if ($type === NULL) {
      $context_parts = [];
      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();
      
    // overrides. We are testing that the configuration factory is     // re-initialized after language negotiation. Ensure that it applies when     // we access the XX front page.     // @see \Drupal\Core\PathProcessor::processInbound()     $this->drupalGet('xx');
    $this->assertSession()->pageTextContains('XX site name');

    // Set the xx language to be the default language and delete the English     // language so the site is no longer multilingual and confirm configuration     // overrides still work.     $language_manager = \Drupal::languageManager()->reset();
    $this->assertTrue($language_manager->isMultilingual(), 'The test site is multilingual.');
    $this->config('system.site')->set('default_langcode', 'xx')->save();

    ConfigurableLanguage::load('en')->delete();
    $this->assertFalse($language_manager->isMultilingual(), 'The test site is monolingual.');

    $this->drupalGet('xx');
    $this->assertSession()->pageTextContains('XX site name');

  }

}

class LanguageServiceProvider extends ServiceProviderBase {

  const CONFIG_PREFIX = 'language.entity.';

  /** * {@inheritdoc} */
  public function register(ContainerBuilder $container) {
    // The following services are needed only on multilingual sites.     if ($this->isMultilingual()) {
      $container->register('language_request_subscriber', 'Drupal\language\EventSubscriber\LanguageRequestSubscriber')
        ->addTag('event_subscriber')
        ->addArgument(new Reference('language_manager'))
        ->addArgument(new Reference('language_negotiator'))
        ->addArgument(new Reference('string_translation'))
        ->addArgument(new Reference('current_user'));

      $container->register('path_processor_language', 'Drupal\language\HttpKernel\PathProcessorLanguage')
        ->addTag('path_processor_inbound', ['priority' => 300])
        ->addTag('path_processor_outbound', ['priority' => 100])
        ->addArgument(new Reference('config.factory'))
        
'desc' => $this->t('Allow grouping and aggregation (calculation) of fields.'),
      ];
    }

    $options['query'] = [
      'category' => 'other',
      'title' => $this->t('Query settings'),
      'value' => $this->t('Settings'),
      'desc' => $this->t('Allow to set some advanced settings for the query plugin'),
    ];

    if (\Drupal::languageManager()->isMultilingual() && $this->isBaseTableTranslatable()) {
      $rendering_language_options = $this->buildRenderingLanguageOptions();
      $options['rendering_language'] = [
        'category' => 'language',
        'title' => $this->t('Rendering Language'),
        'value' => $rendering_language_options[$this->getOption('rendering_language')],
        'desc' => $this->t('All content that supports translations will be displayed in the selected language.'),
      ];
    }

    $access_plugin = $this->getPlugin('access');
    if (!$access_plugin) {
      
'specifier' => 'alias',
        'sort' => 'asc',
      ],
      'path' => [
        'data' => $this->t('System path'),
        'field' => 'path',
        'specifier' => 'path',
      ],
    ];

    // Enable language column and filter if multiple languages are added.     if ($this->languageManager->isMultilingual()) {
      $header['language_name'] = [
        'data' => $this->t('Language'),
        'field' => 'langcode',
        'specifier' => 'langcode',
        'class' => [RESPONSIVE_PRIORITY_MEDIUM],
      ];
    }

    return $header + parent::buildHeader();
  }

  
return $build;
  }

  /** * {@inheritdoc} */
  public function query() {
    // We purposefully do not call parent::query() because we do not want the     // default query behavior for Views fields. Instead, let the entity     // translation renderer provide the correct query behavior.     if ($this->languageManager->isMultilingual()) {
      $this->getEntityTranslationRenderer()->query($this->query, $this->relationship);
    }
  }

  /** * {@inheritdoc} */
  public function getEntityTypeId() {
    return $this->getEntityType();
  }

  

  protected $langcodeAlias;

  /** * {@inheritdoc} */
  public function query(QueryPluginBase $query$relationship = NULL) {
    // In order to render in the translation language of the entity, we need     // to add the language code of the entity to the query. Skip if the site     // is not multilingual or the entity is not translatable.     if (!$this->languageManager->isMultilingual() || !$this->entityType->hasKey('langcode')) {
      return;
    }
    $langcode_table = $this->getLangcodeTable($query$relationship);
    if ($langcode_table) {
      /** @var \Drupal\views\Plugin\views\query\Sql $query */
      $table_alias = $query->ensureTable($langcode_table$relationship);
      $langcode_key = $this->entityType->getKey('langcode');
      $this->langcodeAlias = $query->addField($table_alias$langcode_key);
    }
  }

  
$languages = $this->languageManager()->getLanguages();
    $original = $entity->getUntranslated()->language()->getId();
    $translations = $entity->getTranslationLanguages();
    $field_ui = $this->moduleHandler()->moduleExists('field_ui') && $account->hasPermission('administer ' . $entity_type_id . ' fields');

    $rows = [];
    $show_source_column = FALSE;
    /** @var \Drupal\Core\Entity\ContentEntityStorageInterface $storage */
    $storage = $this->entityTypeManager()->getStorage($entity_type_id);
    $default_revision = $storage->load($entity->id());

    if ($this->languageManager()->isMultilingual()) {
      // Determine whether the current entity is translatable.       $translatable = FALSE;
      foreach ($this->entityFieldManager->getFieldDefinitions($entity_type_id$entity->bundle()) as $instance) {
        if ($instance->isTranslatable()) {
          $translatable = TRUE;
          break;
        }
      }

      // Show source-language column if there are non-original source langcodes.       $additional_source_langcodes = array_filter(array_keys($translations)function D$langcode) use ($entity$original$manager) {
        

    // @todo Allow list of conditions to be configured in     // https://www.drupal.org/node/2284687.     $visibility = $this->entity->getVisibility();
    $definitions = $this->manager->getFilteredDefinitions('block_ui', $form_state->getTemporaryValue('gathered_contexts')['block' => $this->entity]);
    foreach ($definitions as $condition_id => $definition) {
      // Don't display the current theme condition.       if ($condition_id == 'current_theme') {
        continue;
      }
      // Don't display the language condition until we have multiple languages.       if ($condition_id == 'language' && !$this->language->isMultilingual()) {
        continue;
      }

      /** @var \Drupal\Core\Condition\ConditionInterface $condition */
      $condition = $this->manager->createInstance($condition_id$visibility[$condition_id] ?? []);
      $form_state->set(['conditions', $condition_id]$condition);
      $condition_form = $condition->buildConfigurationForm([]$form_state);
      $condition_form['#type'] = 'details';
      $condition_form['#title'] = $condition->getPluginDefinition()['label'];
      $condition_form['#group'] = 'visibility_tabs';
      $form[$condition_id] = $condition_form;
    }
public function getCacheMaxAge() {
    return Cache::PERMANENT;
  }

  /** * {@inheritdoc} */
  public function query() {
    // We purposefully do not call parent::query() because we do not want the     // default query behavior for Views fields. Instead, let the entity     // translation renderer provide the correct query behavior.     if ($this->languageManager->isMultilingual()) {
      $this->getEntityTranslationRenderer()->query($this->query, $this->relationship);
    }
  }

  /** * {@inheritdoc} */
  public function getEntityTypeId() {
    return $this->getEntityType();
  }

  

    return $this->entity;
  }

  /** * {@inheritdoc} */
  public function getTitle() {
    // We only need to get the title from the actual entity if it may be a     // translation based on the current language context. This can only happen     // if the site is configured to be multilingual.     if ($this->languageManager->isMultilingual()) {
      return $this->getEntity()->getTitle();
    }
    return $this->pluginDefinition['title'];
  }

  /** * {@inheritdoc} */
  public function getDescription() {
    // We only need to get the description from the actual entity if it may be a     // translation based on the current language context. This can only happen
Home | Imprint | This part of the site doesn't use cookies.