You are here

public function ImportEntityManager::verifyLanguageSupportability in Acquia Content Hub 8

Verifies that the sites supports at least a language defined in the entity.

Parameters

\Drupal\acquia_contenthub\ContentHubEntityDependency $contenthub_entity_dependency: The Content Hub Entity.

Return value

bool TRUE if the site supports at least a language defined in the entity, FALSE otherwise.

1 call to ImportEntityManager::verifyLanguageSupportability()
ImportEntityManager::importRemoteEntity in src/ImportEntityManager.php
Saves a Content Hub Entity into a Drupal Entity, given its UUID.

File

src/ImportEntityManager.php, line 539

Class

ImportEntityManager
Provides a service for managing imported entities' actions.

Namespace

Drupal\acquia_contenthub

Code

public function verifyLanguageSupportability(ContentHubEntityDependency $contenthub_entity_dependency) {
  $contenthub_entity = $contenthub_entity_dependency
    ->getRawEntity();
  $entity_type = $contenthub_entity
    ->getType();
  $attributes = $contenthub_entity
    ->getAttributes();
  if ($entity_type === 'file') {
    $langcodes = array_keys($attributes['url']['value']);
  }
  elseif ($langcode = $contenthub_entity
    ->getAttribute('langcode')) {
    $langcodes = $langcode['value'];
  }
  else {
    $langcodes = array_keys($contenthub_entity
      ->getAttribute('default_langcode')['value'] ?? []);
  }
  $site_langcodes = array_keys($this->languageManager
    ->getLanguages());
  $supported_languages = array_intersect($site_langcodes, $langcodes);
  return !empty($supported_languages);
}