You are here

class LingotekFilterManager in Lingotek Translation 3.4.x

Same name and namespace in other branches
  1. 8.2 src/LingotekFilterManager.php \Drupal\lingotek\LingotekFilterManager
  2. 4.0.x src/LingotekFilterManager.php \Drupal\lingotek\LingotekFilterManager
  3. 3.0.x src/LingotekFilterManager.php \Drupal\lingotek\LingotekFilterManager
  4. 3.1.x src/LingotekFilterManager.php \Drupal\lingotek\LingotekFilterManager
  5. 3.2.x src/LingotekFilterManager.php \Drupal\lingotek\LingotekFilterManager
  6. 3.3.x src/LingotekFilterManager.php \Drupal\lingotek\LingotekFilterManager
  7. 3.5.x src/LingotekFilterManager.php \Drupal\lingotek\LingotekFilterManager
  8. 3.6.x src/LingotekFilterManager.php \Drupal\lingotek\LingotekFilterManager
  9. 3.7.x src/LingotekFilterManager.php \Drupal\lingotek\LingotekFilterManager
  10. 3.8.x src/LingotekFilterManager.php \Drupal\lingotek\LingotekFilterManager

Service for managing Lingotek Filters.

@package Drupal\lingotek

Hierarchy

Expanded class hierarchy of LingotekFilterManager

1 file declares its use of LingotekFilterManager
LingotekFilterManagerUnitTest.php in tests/src/Unit/LingotekFilterManagerUnitTest.php
1 string reference to 'LingotekFilterManager'
lingotek.services.yml in ./lingotek.services.yml
lingotek.services.yml
1 service uses LingotekFilterManager
lingotek.filter_manager in ./lingotek.services.yml
Drupal\lingotek\LingotekFilterManager

File

src/LingotekFilterManager.php, line 12

Namespace

Drupal\lingotek
View source
class LingotekFilterManager implements LingotekFilterManagerInterface {

  /**
   * The config factory.
   *
   * @var \Drupal\Core\Config\ConfigFactoryInterface
   */
  protected $configFactory;

  /**
   * Constructs a new LingotekFilterManager.
   *
   * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
   *   The config factory.
   */
  public function __construct(ConfigFactoryInterface $config_factory) {
    $this->configFactory = $config_factory;
  }

  /**
   * {@inheritdoc}
   */
  public function getLocallyAvailableFilters() {
    $filters = $this->configFactory
      ->get('lingotek.settings')
      ->get('account.resources.filter');
    $filters['project_default'] = 'Project Default';
    $filters['drupal_default'] = 'Drupal Default';
    return $filters;
  }

  /**
   * {@inheritdoc}
   */
  public function getDefaultFilter() {
    $filter = $this->configFactory
      ->get('lingotek.settings')
      ->get('default.filter');
    $filters = $this
      ->getLocallyAvailableFilters();
    if (!isset($filters[$filter])) {
      $filter = NULL;
    }
    return $filter;
  }

  /**
   * {@inheritdoc}
   */
  public function getDefaultSubfilter() {
    $filter = $this->configFactory
      ->get('lingotek.settings')
      ->get('default.subfilter');
    $filters = $this
      ->getLocallyAvailableFilters();
    if (!isset($filters[$filter])) {
      $filter = NULL;
    }
    return $filter;
  }

  /**
   * {@inheritdoc}
   */
  public function getDefaultFilterLabel() {
    $label = '';
    $filter = $this
      ->getDefaultFilter();
    $filters = $this
      ->getLocallyAvailableFilters();
    if (isset($filters[$filter])) {
      $label = $filters[$filter];
    }
    return $label;
  }

  /**
   * {@inheritdoc}
   */
  public function getDefaultSubfilterLabel() {
    $label = '';
    $filter = $this
      ->getDefaultSubfilter();
    $filters = $this
      ->getLocallyAvailableFilters();
    if (isset($filters[$filter])) {
      $label = $filters[$filter];
    }
    return $label;
  }

  /**
   * {@inheritdoc}
   */
  public function getFilterId(LingotekFilterProviderInterface $profile = NULL) {
    $defaults = new LingotekDefaultFilterProvider();
    $defaultFilter = $defaults
      ->getFilter();
    $filter = NULL;
    $settingsFilter = $this
      ->getDefaultFilter();
    if ($profile !== NULL && ($profileFilter = $profile
      ->getFilter())) {
      switch ($profileFilter) {
        case 'project_default':
          $filter = NULL;
          break;
        case 'drupal_default':
          $filter = $defaultFilter;
          break;
        case 'default':
          $filter = $this
            ->chooseAppropriateFilterID($settingsFilter, $defaultFilter);
          break;
        default:
          $filter = $profileFilter;
          break;
      }
    }
    else {
      $filter = $this
        ->chooseAppropriateFilterID($settingsFilter, $defaultFilter);
    }
    return $filter;
  }

  /**
   * {@inheritdoc}
   */
  public function getSubfilterId(LingotekFilterProviderInterface $profile = NULL) {
    $defaults = new LingotekDefaultFilterProvider();
    $defaultFilter = $defaults
      ->getSubfilter();
    $filter = NULL;
    $settingsFilter = $this
      ->getDefaultSubfilter();
    if ($profile !== NULL && ($profileFilter = $profile
      ->getSubfilter())) {
      switch ($profileFilter) {
        case 'project_default':
          $filter = NULL;
          break;
        case 'drupal_default':
          $filter = $defaultFilter;
          break;
        case 'default':
          $filter = $this
            ->chooseAppropriateFilterID($settingsFilter, $defaultFilter);
          break;
        default:
          $filter = $profileFilter;
          break;
      }
    }
    else {
      $filter = $this
        ->chooseAppropriateFilterID($settingsFilter, $defaultFilter);
    }
    return $filter;
  }

  /**
   * Helper used to choose the appropriate filter ID based on the one listed in settings.
   *
   * @param string $settingsFilter
   *   Either 'project_default', 'drupal_default' or the filter ID.
   * @param string $drupalDefaultFilterID
   *   The Drupal default filter ID.
   *
   * @return string|null
   *   The appropriate filter ID or NULL if project default is to be used.
   */
  protected function chooseAppropriateFilterID($settingsFilter, $drupalDefaultFilterID) {
    $filter = $settingsFilter;
    switch ($settingsFilter) {
      case 'project_default':
        $filter = NULL;
        break;
      case 'drupal_default':
        $filter = $drupalDefaultFilterID;
        break;
    }
    return $filter;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
LingotekFilterManager::$configFactory protected property The config factory.
LingotekFilterManager::chooseAppropriateFilterID protected function Helper used to choose the appropriate filter ID based on the one listed in settings.
LingotekFilterManager::getDefaultFilter public function Get the default filter ID. Overrides LingotekFilterManagerInterface::getDefaultFilter
LingotekFilterManager::getDefaultFilterLabel public function Get the default filter label. Overrides LingotekFilterManagerInterface::getDefaultFilterLabel
LingotekFilterManager::getDefaultSubfilter public function Get the default subfilter ID. Overrides LingotekFilterManagerInterface::getDefaultSubfilter
LingotekFilterManager::getDefaultSubfilterLabel public function Get the default filter label. Overrides LingotekFilterManagerInterface::getDefaultSubfilterLabel
LingotekFilterManager::getFilterId public function Gets the filter that should be applied. Overrides LingotekFilterManagerInterface::getFilterId
LingotekFilterManager::getLocallyAvailableFilters public function Get all the locally available filters. Overrides LingotekFilterManagerInterface::getLocallyAvailableFilters
LingotekFilterManager::getSubfilterId public function Gets the subfilter that should be applied. Overrides LingotekFilterManagerInterface::getSubfilterId
LingotekFilterManager::__construct public function Constructs a new LingotekFilterManager.