class HiddenLanguageManager in Hidden Language 2.x
Class HiddenLanguageManager.
@package Drupal\hidden_language
Hierarchy
- class \Drupal\hidden_language\HiddenLanguageManager
Expanded class hierarchy of HiddenLanguageManager
2 files declare their use of HiddenLanguageManager
- HiddenLanguageForm.php in Form/
HiddenLanguageForm.php - HiddenLanguageForm.php in src/
Form/ HiddenLanguageForm.php
1 string reference to 'HiddenLanguageManager'
1 service uses HiddenLanguageManager
File
- src/
HiddenLanguageManager.php, line 13
Namespace
Drupal\hidden_languageView source
class HiddenLanguageManager {
/**
* Drupal\Core\Config\ConfigFactory.
*
* @var Drupal\Core\Config\ConfigFactory
*/
protected $configFactory;
/**
* Drupal\Core\Path\PathValidator.
*
* @var Drupal\Core\Path\PathValidator
*/
protected $pathValidator;
/**
* The hidden_language.settings.
*/
protected $hiddenLanguageSettings;
/**
* Constructor.
*/
public function __construct(ConfigFactory $config_factory, PathValidator $path_validator) {
$this->configFactory = $config_factory;
$this->pathValidator = $path_validator;
$this->hiddenLanguageSettings = $this->configFactory
->getEditable('hidden_language.settings');
}
/**
* Get array of route name exception configuration.
*
* @return array
* Array of configurated routes.
*/
public function getRoutesException() {
return json_decode($this->hiddenLanguageSettings
->get('route_name'));
}
/**
* Get array of path url exception configuration.
*
* @return array
* Array of configurated paths.
*/
public function getPathsException() {
return json_decode($this->hiddenLanguageSettings
->get('path'));
}
/**
* Check if url route name existis in the exception list.
*
* @param string $url
* Url to be tested.
*
* @return bool
* True if url route name existis in exception list and False if not.
*/
public function isRouteExcecption($url) {
if (!is_array($this
->getRoutesException())) {
return FALSE;
}
$url_object = $this->pathValidator
->getUrlIfValidWithoutAccessCheck($url);
if (!$url_object) {
return FALSE;
}
$route_name = $url_object
->getRouteName();
return array_key_exists($route_name, array_flip($this
->getRoutesException()));
}
/**
* Check if url exists in the exception list.
*
* @param string $url
* Url to be tested.
*
* @return bool
* True if Url is in exception list and False if not.
*/
public function isPathException($url) {
if (!is_array($this
->getPathsException())) {
return FALSE;
}
return array_key_exists($url, array_flip($this
->getPathsException()));
}
/**
* Verify if $url is an exception on the hidden language config.
*
* @param string $url
* Url to be tested.
*
* @return bool
* True if Url is in exception list and False if not.
*/
public function isUrlException($url) {
if ($this
->isRouteExcecption($url) || $this
->isPathException($url)) {
return TRUE;
}
return FALSE;
}
/**
* Returns json encode array.
*
* @param string $config
* The name of the form element.
*
* @return array
* The states array.
*/
public function encodeArray(string $config = NULL) {
$array = explode(",", str_replace(" ", "", $config));
$array = json_encode($array);
return $array;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
HiddenLanguageManager:: |
protected | property | Drupal\Core\Config\ConfigFactory. | |
HiddenLanguageManager:: |
protected | property | The hidden_language.settings. | |
HiddenLanguageManager:: |
protected | property | Drupal\Core\Path\PathValidator. | |
HiddenLanguageManager:: |
public | function | Returns json encode array. | |
HiddenLanguageManager:: |
public | function | Get array of path url exception configuration. | |
HiddenLanguageManager:: |
public | function | Get array of route name exception configuration. | |
HiddenLanguageManager:: |
public | function | Check if url exists in the exception list. | |
HiddenLanguageManager:: |
public | function | Check if url route name existis in the exception list. | |
HiddenLanguageManager:: |
public | function | Verify if $url is an exception on the hidden language config. | |
HiddenLanguageManager:: |
public | function | Constructor. |