Access.php in Open Social 8.9
Same filename and directory in other branches
- 8 modules/custom/social_language/src/Access.php
- 8.2 modules/custom/social_language/src/Access.php
- 8.3 modules/custom/social_language/src/Access.php
- 8.4 modules/custom/social_language/src/Access.php
- 8.5 modules/custom/social_language/src/Access.php
- 8.6 modules/custom/social_language/src/Access.php
- 8.7 modules/custom/social_language/src/Access.php
- 8.8 modules/custom/social_language/src/Access.php
- 10.3.x modules/custom/social_language/src/Access.php
- 10.0.x modules/custom/social_language/src/Access.php
- 10.1.x modules/custom/social_language/src/Access.php
- 10.2.x modules/custom/social_language/src/Access.php
Namespace
Drupal\social_languageFile
modules/custom/social_language/src/Access.phpView source
<?php
namespace Drupal\social_language;
use Drupal\Core\Access\AccessResult;
use Drupal\Core\Language\LanguageManagerInterface;
use Drupal\Core\Routing\Access\AccessInterface;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Session\AccountInterface;
/**
* Class Access.
*
* @package Drupal\social_language
*/
class Access implements AccessInterface {
/**
* The language manager.
*
* @var \Drupal\Core\Language\LanguageManagerInterface
*/
protected $languageManager;
/**
* Constructs a Access object.
*
* @param \Drupal\Core\Language\LanguageManagerInterface $language_manager
* The language manager service.
*/
public function __construct(LanguageManagerInterface $language_manager) {
$this->languageManager = $language_manager;
}
/**
* Checks access to the overview based on permissions and translatability.
*
* @param \Drupal\Core\Routing\RouteMatchInterface $route_match
* The route_match to check against.
* @param \Drupal\Core\Session\AccountInterface $account
* The account to check access for.
* @param string $permission
* (optional) The permission.
*
* @codingStandardsIgnoreStart until https://www.drupal.org/project/coder/issues/3013953 is fixed
* @return \Drupal\Core\Access\AccessResult
* Whether to grant or deny access.
* @codingStandardsIgnoreEnd
*/
public function access(RouteMatchInterface $route_match, AccountInterface $account, $permission = NULL) {
if (count($this->languageManager
->getLanguages()) > 1) {
if (!empty($permission)) {
return AccessResult::allowedIfHasPermission($account, $permission);
}
else {
return AccessResult::allowed();
}
}
return AccessResult::forbidden();
}
}