l10n_server-2.x-dev/l10n_groups/src/L10nGroupManager.php

l10n_groups/src/L10nGroupManager.php
<?php

namespace Drupal\l10n_groups;

use Drupal\Core\Entity\EntityTypeManagerInterface;

/**
 * Various methods to managed translation groups.
 */
class L10nGroupManager {

  /**
   * Entity type manager service.
   *
   * @var \Drupal\Core\Entity\EntityTypeManagerInterface
   */
  protected $entityTypeManager;

  /**
   * Constructor.
   *
   * @param Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
   *   Entity type manager service.
   */
  public function __construct(EntityTypeManagerInterface $entity_type_manager) {
    $this->entityTypeManager = $entity_type_manager;
  }

  /**
   * Get a list of all translation groups.
   */
  public function getGroups() {
    $indexed_groups = [];
    $groups = $this->entityTypeManager
      ->getStorage('group')
      ->loadByProperties(['type' => 'translation']);

    foreach ($groups as $group) {
      if ($langcode = $group->field_translation_language->target_id) {
        $indexed_groups[$langcode] = $group;
      }
    }

    return $indexed_groups;
  }

}

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc