本文整理汇总了PHP中Drupal\Core\Access\AccessResult::allowedIf方法的典型用法代码示例。如果您正苦于以下问题:PHP AccessResult::allowedIf方法的具体用法?PHP AccessResult::allowedIf怎么用?PHP AccessResult::allowedIf使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Drupal\Core\Access\AccessResult
的用法示例。
在下文中一共展示了AccessResult::allowedIf方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: checkAccess
/**
* {@inheritdoc}
*/
protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account)
{
switch ($operation) {
case 'view':
// There is no direct viewing of a menu link, but still for purposes of
// content_translation we need a generic way to check access.
return AccessResult::allowedIfHasPermission($account, 'administer menu');
case 'update':
if (!$account->hasPermission('administer menu')) {
return AccessResult::neutral()->cachePerPermissions();
} else {
// If there is a URL, this is an external link so always accessible.
$access = AccessResult::allowed()->cachePerPermissions()->addCacheableDependency($entity);
/** @var \Drupal\menu_link_content\MenuLinkContentInterface $entity */
// We allow access, but only if the link is accessible as well.
if (($url_object = $entity->getUrlObject()) && $url_object->isRouted()) {
$link_access = $this->accessManager->checkNamedRoute($url_object->getRouteName(), $url_object->getRouteParameters(), $account, TRUE);
$access = $access->andIf($link_access);
}
return $access;
}
case 'delete':
return AccessResult::allowedIf(!$entity->isNew() && $account->hasPermission('administer menu'))->cachePerPermissions()->addCacheableDependency($entity);
}
}
示例2: access
/**
* {@inheritdoc}
*/
public function access(Route $route, AccountInterface $account, Request $request)
{
$_entity_revision = $request->attributes->get('_entity_revision');
$operation = $route->getRequirement('_entity_access_revision');
list(, $operation) = explode('.', $operation, 2);
return AccessResult::allowedIf($_entity_revision && $this->checkAccess($_entity_revision, $account, $operation))->cachePerPermissions();
}
示例3: createAssetReleaseAccess
/**
* Handles access to the rdf_entity proposal form.
*
* @param \Drupal\rdf_entity\RdfEntityTypeInterface $rdf_type
* The RDF entity type for which the proposal form is built.
*
* @return \Drupal\Core\Access\AccessResult
* The access result object.
*/
public function createAssetReleaseAccess(RdfEntityTypeInterface $rdf_type)
{
if (!in_array($rdf_type->id(), ['collection', 'solution'])) {
return AccessResult::forbidden();
}
return AccessResult::allowedIf($this->currentUser()->hasPermission("propose {$rdf_type->id()} rdf entity"));
}
示例4: checkAccess
/**
* {@inheritdoc}
*/
protected function checkAccess(EntityInterface $entity, $operation, $langcode, AccountInterface $account)
{
/** @var \Drupal\user\UserInterface $entity*/
// The anonymous user's profile can neither be viewed, updated nor deleted.
if ($entity->isAnonymous()) {
return AccessResult::forbidden();
}
// Administrators can view/update/delete all user profiles.
if ($account->hasPermission('administer users')) {
return AccessResult::allowed()->cachePerRole();
}
switch ($operation) {
case 'view':
// Only allow view access if the account is active.
if ($account->hasPermission('access user profiles') && $entity->isActive()) {
return AccessResult::allowed()->cachePerRole()->cacheUntilEntityChanges($entity);
} else {
if ($account->id() == $entity->id()) {
return AccessResult::allowed()->cachePerUser();
}
}
break;
case 'update':
// Users can always edit their own account.
return AccessResult::allowedIf($account->id() == $entity->id())->cachePerUser();
case 'delete':
// Users with 'cancel account' permission can cancel their own account.
return AccessResult::allowedIf($account->id() == $entity->id() && $account->hasPermission('cancel account'))->cachePerRole()->cachePerUser();
}
// No opinion.
return AccessResult::neutral();
}
示例5: access
/**
* {@inheritdoc}
*/
public function access(Route $route, AccountInterface $account, RdfInterface $rdf_entity, $operation = 'view')
{
$graph = $route->getOption('graph_name');
$entity_type_id = $route->getOption('entity_type_id');
$storage = $this->entityManager->getStorage($entity_type_id);
if (!$storage instanceof RdfEntitySparqlStorage) {
throw new \Exception('Storage not supported.');
}
// The active graph is the published graph. It is handled by the default
// operation handler.
// @todo: getActiveGraph is not the default. We should load from settings.
$default_graph = $storage->getBundleGraphUri($rdf_entity->bundle(), 'default');
$requested_graph = $storage->getBundleGraphUri($rdf_entity->bundle(), $graph);
if ($requested_graph == $default_graph) {
return AccessResult::neutral();
}
$active_graph_type = $storage->getRequestGraphs($rdf_entity->id());
// Check if there is an entity saved in the passed graph.
$storage->setRequestGraphs($rdf_entity->id(), [$graph]);
$entity = $storage->load($rdf_entity->id());
// Restore active graph.
$storage->setRequestGraphs($rdf_entity->id(), $active_graph_type);
// @todo: When the requested graph is the only one and it is not the
// default, it is loaded in the default view, so maybe there is no need
// to also show a separate tab.
return AccessResult::allowedIf($entity && $this->checkAccess($rdf_entity, $route, $account, $operation, $graph))->cachePerPermissions()->addCacheableDependency($rdf_entity);
}
示例6: checkAccess
/**
* {@inheritdoc}
*/
protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account)
{
/** @var \Drupal\crm_core_contact\Entity\ContactType $entity */
// First check permission.
if (parent::checkAccess($entity, $operation, $account)->isForbidden()) {
return AccessResult::forbidden();
}
switch ($operation) {
case 'enable':
// Only disabled contact type can be enabled.
return AccessResult::allowedIf(!$entity->status());
case 'disable':
return AccessResult::allowedIf($entity->status());
case 'delete':
// If contact instance of this contact type exist, you can't delete it.
$results = \Drupal::entityQuery('crm_core_contact')->condition('type', $entity->id())->execute();
return AccessResult::allowedIf(empty($results));
// @todo Which is it?
// @todo Which is it?
case 'edit':
case 'update':
// If the contact type is locked, you can't edit it.
return AccessResult::allowed();
}
}
示例7: access
/**
* Checks routing access for the support_ticket revision.
*
* @param \Symfony\Component\Routing\Route $route
* The route to check against.
* @param \Drupal\Core\Session\AccountInterface $account
* The currently logged in account.
* @param int $support_ticket_revision
* (optional) The support_ticket revision ID. If not specified, but
* $support_ticket is, access is checked for that object's revision.
* @param \Drupal\support_ticket\SupportTicketInterface $support_ticket
* (optional) A support_ticket object. Used for checking access to a
* support_ticket's default revision when $support_ticket_revision is
* unspecified. Ignored when $support_ticket_revision is specified. If neither
* $support_ticket_revision nor $support_ticket are specified, then access is
* denied.
*
* @return \Drupal\Core\Access\AccessResultInterface
* The access result.
*/
public function access(Route $route, AccountInterface $account, $support_ticket_revision = NULL, SupportTicketInterface $support_ticket = NULL)
{
if ($support_ticket_revision) {
$support_ticket = $this->supportTicketStorage->loadRevision($support_ticket_revision);
}
$operation = $route->getRequirement('_access_support_ticket_revision');
return AccessResult::allowedIf($support_ticket && $this->checkAccess($support_ticket, $account, $operation))->cachePerPermissions();
}
示例8: access
/**
* Checks routing access for the node revision.
*
* @param \Symfony\Component\Routing\Route $route
* The route to check against.
* @param \Drupal\Core\Session\AccountInterface $account
* The currently logged in account.
* @param int $node_revision
* (optional) The node revision ID. If not specified, but $node is, access
* is checked for that object's revision.
* @param \Drupal\node\NodeInterface $node
* (optional) A node object. Used for checking access to a node's default
* revision when $node_revision is unspecified. Ignored when $node_revision
* is specified. If neither $node_revision nor $node are specified, then
* access is denied.
*
* @return \Drupal\Core\Access\AccessResultInterface
* The access result.
*/
public function access(Route $route, AccountInterface $account, $node_revision = NULL, NodeInterface $node = NULL)
{
if ($node_revision) {
$node = $this->nodeStorage->loadRevision($node_revision);
}
$operation = $route->getRequirement('_access_node_revision');
return AccessResult::allowedIf($node && $this->checkAccess($node, $account, $operation))->cachePerPermissions();
}
示例9: testAccess
/**
* Tests the access check method.
*
* @dataProvider providerTestAccess
* @covers ::access
*/
public function testAccess($requirements, $access, array $contexts = [])
{
$access_result = AccessResult::allowedIf($access)->addCacheContexts($contexts);
$user = $this->getMock('Drupal\\Core\\Session\\AccountInterface');
$user->expects($this->any())->method('hasPermission')->will($this->returnValueMap([['allowed', TRUE], ['denied', FALSE], ['other', FALSE]]));
$route = new Route('', [], $requirements);
$this->assertEquals($access_result, $this->accessCheck->access($route, $user));
}
示例10: access
/**
* Check to see if user accessed this page.
*
* @return \Drupal\Core\Access\AccessResultInterface
* The access result.
*/
public function access()
{
if (!isset($_SESSION['menu_test'])) {
$result = AccessResult::allowed();
} else {
$result = AccessResult::allowedIf($_SESSION['menu_test'] < 2);
}
return $result->setCacheMaxAge(0);
}
示例11: checkAccess
/**
* {@inheritdoc}
*/
protected function checkAccess(EntityInterface $entity, $operation, $langcode, AccountInterface $account)
{
switch ($operation) {
case 'delete':
return AccessResult::allowedIf($account->hasPermission('administer feeds') && !$entity->isLocked());
default:
return AccessResult::allowedIfHasPermission($account, 'administer feeds');
}
}
示例12: access
/**
* Access callback; check if the module is configured.
*
* This function does not actually check whether Mollom keys are valid for the
* site, but just if the keys have been entered.
*
* @param $permission
* An optional permission string to check with \Drupal::currentUser()->hasPermission().
*
* @return \Drupal\Core\Access\AccessResultInterface
* The access result.
*/
function access($permission = FALSE)
{
$configured = \Drupal::config('mollom.settings')->get('keys.public') && \Drupal::config('mollom.settings')->get('keys.private');
if ($configured && $permission) {
return AccessResult::allowedIfHasPermission($permission, \Drupal::currentUser());
} else {
return AccessResult::allowedIf($configured);
}
}
示例13: access
/**
* Checks that an entity is an event type.
*/
public function access(Route $route, RouteMatchInterface $route_match, AccountInterface $account)
{
if ($event = $route->getDefault('event')) {
$event = $route_match->getParameter($event);
if ($event instanceof EntityInterface) {
return AccessResult::allowedIf($this->eventManager->isEvent($event));
}
}
return AccessResult::neutral();
}
示例14: access
/**
* {@inheritdoc}
*/
public function access(Route $route, AccountInterface $account, RouteMatchInterface $route_match, $entity_revision = NULL, $_entity_revision = NULL)
{
$entity = $_entity_revision ?: $this->extractEntityFromRouteMatch($route_match);
if ($entity_revision) {
$entity = $this->entityManager->getStorage($entity->getEntityTypeId())->loadRevision($entity_revision);
}
$operation = $route->getRequirement('_entity_access_revision');
list(, $operation) = explode('.', $operation, 2);
return AccessResult::allowedIf($entity && $this->checkAccess($entity, $account, $operation))->cachePerPermissions();
}
示例15: checkCreateAccess
/**
* {@inheritdoc}
*/
protected function checkCreateAccess(AccountInterface $account, array $context, $entity_bundle = NULL) {
$access_result = AccessResult::allowedIfHasPermissions($account, ["create {$entity_bundle} entityqueue", 'manipulate all entityqueues', 'administer entityqueue'], 'OR');
if ($entity_bundle) {
$queue = EntityQueue::load($entity_bundle);
$access_result = AccessResult::allowedIf(!$queue->getHandlerPlugin()->hasAutomatedSubqueues());
}
return $access_result;
}