You are here

public function Webform::hasTranslations in Webform 8.5

Same name and namespace in other branches
  1. 6.x src/Entity/Webform.php \Drupal\webform\Entity\Webform::hasTranslations()

Determine if the current webform is translated.

Return value

bool TRUE if the current webform is translated.

Overrides WebformInterface::hasTranslations

File

src/Entity/Webform.php, line 744

Class

Webform
Defines the webform entity.

Namespace

Drupal\webform\Entity

Code

public function hasTranslations() {
  if (isset($this->hasTranslations)) {
    return $this->hasTranslations;
  }

  // Make sure the config translation module is enabled.
  if (!\Drupal::moduleHandler()
    ->moduleExists('config_translation')) {
    $this->hasTranslations = FALSE;
    return $this->hasTranslations;
  }

  /** @var \Drupal\locale\LocaleConfigManager $local_config_manager */
  $local_config_manager = \Drupal::service('locale.config_manager');
  $languages = \Drupal::languageManager()
    ->getLanguages();
  foreach ($languages as $langcode => $language) {
    if ($local_config_manager
      ->hasTranslation('webform.webform.' . $this
      ->id(), $langcode)) {
      $this->hasTranslations = TRUE;
      return $this->hasTranslations;
    }
  }
  $this->hasTranslations = FALSE;
  return $this->hasTranslations;
}