You are here

class HiddenLanguageManager in Hidden Language 2.x

Class HiddenLanguageManager.

@package Drupal\hidden_language

Hierarchy

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'
hidden_language.services.yml in ./hidden_language.services.yml
hidden_language.services.yml
1 service uses HiddenLanguageManager
hidden_language.hidden_language_manager in ./hidden_language.services.yml
Drupal\hidden_language\HiddenLanguageManager

File

src/HiddenLanguageManager.php, line 13

Namespace

Drupal\hidden_language
View 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

Namesort descending Modifiers Type Description Overrides
HiddenLanguageManager::$configFactory protected property Drupal\Core\Config\ConfigFactory.
HiddenLanguageManager::$hiddenLanguageSettings protected property The hidden_language.settings.
HiddenLanguageManager::$pathValidator protected property Drupal\Core\Path\PathValidator.
HiddenLanguageManager::encodeArray public function Returns json encode array.
HiddenLanguageManager::getPathsException public function Get array of path url exception configuration.
HiddenLanguageManager::getRoutesException public function Get array of route name exception configuration.
HiddenLanguageManager::isPathException public function Check if url exists in the exception list.
HiddenLanguageManager::isRouteExcecption public function Check if url route name existis in the exception list.
HiddenLanguageManager::isUrlException public function Verify if $url is an exception on the hidden language config.
HiddenLanguageManager::__construct public function Constructor.