LingotekFilterManager.php in Lingotek Translation 3.3.x
File
src/LingotekFilterManager.php
View source
<?php
namespace Drupal\lingotek;
use Drupal\Core\Config\ConfigFactoryInterface;
class LingotekFilterManager implements LingotekFilterManagerInterface {
protected $configFactory;
public function __construct(ConfigFactoryInterface $config_factory) {
$this->configFactory = $config_factory;
}
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;
}
public function getDefaultFilter() {
$filter = $this->configFactory
->get('lingotek.settings')
->get('default.filter');
$filters = $this
->getLocallyAvailableFilters();
if (!isset($filters[$filter])) {
$filter = NULL;
}
return $filter;
}
public function getDefaultSubfilter() {
$filter = $this->configFactory
->get('lingotek.settings')
->get('default.subfilter');
$filters = $this
->getLocallyAvailableFilters();
if (!isset($filters[$filter])) {
$filter = NULL;
}
return $filter;
}
public function getDefaultFilterLabel() {
$label = '';
$filter = $this
->getDefaultFilter();
$filters = $this
->getLocallyAvailableFilters();
if (isset($filters[$filter])) {
$label = $filters[$filter];
}
return $label;
}
public function getDefaultSubfilterLabel() {
$label = '';
$filter = $this
->getDefaultSubfilter();
$filters = $this
->getLocallyAvailableFilters();
if (isset($filters[$filter])) {
$label = $filters[$filter];
}
return $label;
}
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;
}
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;
}
protected function chooseAppropriateFilterID($settingsFilter, $drupalDefaultFilterID) {
$filter = $settingsFilter;
switch ($settingsFilter) {
case 'project_default':
$filter = NULL;
break;
case 'drupal_default':
$filter = $drupalDefaultFilterID;
break;
}
return $filter;
}
}