本文整理汇总了PHP中Drupal\Core\Entity\EntityTypeInterface::getAdminPermission方法的典型用法代码示例。如果您正苦于以下问题:PHP EntityTypeInterface::getAdminPermission方法的具体用法?PHP EntityTypeInterface::getAdminPermission怎么用?PHP EntityTypeInterface::getAdminPermission使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Drupal\Core\Entity\EntityTypeInterface
的用法示例。
在下文中一共展示了EntityTypeInterface::getAdminPermission方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: checkCreateAccess
/**
* Performs create access checks.
*
* This method is supposed to be overwritten by extending classes that
* do their own custom access checking.
*
* @param \Drupal\Core\Session\AccountInterface $account
* The user for which to check access.
* @param array $context
* An array of key-value pairs to pass additional context when needed.
* @param string|null $entity_bundle
* (optional) The bundle of the entity. Required if the entity supports
* bundles, defaults to NULL otherwise.
*
* @return bool|null
* TRUE if access was granted, FALSE if access was denied and NULL if access
* could not be determined.
*/
protected function checkCreateAccess(AccountInterface $account, array $context, $entity_bundle = NULL)
{
if ($admin_permission = $this->entityType->getAdminPermission()) {
return $account->hasPermission($admin_permission);
} else {
return NULL;
}
}
示例2: checkCreateAccess
/**
* Performs create access checks.
*
* This method is supposed to be overwritten by extending classes that
* do their own custom access checking.
*
* @param \Drupal\Core\Session\AccountInterface $account
* The user for which to check access.
* @param array $context
* An array of key-value pairs to pass additional context when needed.
* @param string|null $entity_bundle
* (optional) The bundle of the entity. Required if the entity supports
* bundles, defaults to NULL otherwise.
*
* @return \Drupal\Core\Access\AccessResultInterface
* The access result.
*/
protected function checkCreateAccess(AccountInterface $account, array $context, $entity_bundle = NULL)
{
if ($admin_permission = $this->entityType->getAdminPermission()) {
return AccessResult::allowedIfHasPermission($account, $admin_permission);
} else {
// No opinion.
return AccessResult::neutral();
}
}
示例3: getCollectionRoute
/**
* Gets the collection route.
*
* @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
* The entity type.
*
* @return \Symfony\Component\Routing\Route|null
* The generated route, if available.
*/
protected function getCollectionRoute(EntityTypeInterface $entity_type)
{
if ($entity_type->hasLinkTemplate('collection') && $entity_type->hasListBuilderClass()) {
$entity_type_id = $entity_type->id();
$route = new Route($entity_type->getLinkTemplate('collection'));
$route->setDefaults(['_entity_list' => $entity_type_id, '_title' => (string) $entity_type->getLabel()])->setRequirement('_permission', $entity_type->getAdminPermission())->setOption('_admin_route', TRUE);
return $route;
}
}
示例4: deleteMultipleFormRoute
/**
* Returns the delete multiple form route.
*
* @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
* The entity type.
*
* @return \Symfony\Component\Routing\Route|null
* The generated route, if available.
*/
protected function deleteMultipleFormRoute(EntityTypeInterface $entity_type)
{
if ($entity_type->hasLinkTemplate('delete-multiple-form')) {
$route = new Route($entity_type->getLinkTemplate('delete-multiple-form'));
$route->setDefault('_form', '\\Drupal\\entity\\Form\\DeleteMultiple');
$route->setDefault('entity_type_id', $entity_type->id());
$route->setRequirement('_permission', $entity_type->getAdminPermission());
return $route;
}
}
示例5: testAccessDelete
/**
* @covers ::checkAccess
*
* @dataProvider providerTestAccessDelete
*/
public function testAccessDelete($is_new, $is_fallback, $expected)
{
$this->entityType->getAdminPermission()->willReturn('test permission');
$page = $this->prophesize(PageInterface::class);
$page->isNew()->willReturn($is_new);
$page->isFallbackPage()->willReturn($is_fallback);
$page->uuid()->shouldBeCalled();
$page->getEntityTypeId()->shouldBeCalled();
// Ensure that the cache tag is added for the temporary conditions.
if ($is_new || $is_fallback) {
$this->setUpCacheContextsManager();
$page->getCacheTags()->willReturn(['page:1']);
$page->getCacheContexts()->willReturn([]);
$page->getCacheMaxAge()->willReturn(0);
}
$account = $this->prophesize(AccountInterface::class);
$account->hasPermission('test permission')->willReturn(TRUE);
$account->id()->shouldBeCalled();
$this->assertSame($expected, $this->pageAccess->access($page->reveal(), 'delete', NULL, $account->reveal()));
}
示例6: getSettingsFormRoute
/**
* Gets the settings form route.
*
* @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
* The entity type.
*
* @return \Symfony\Component\Routing\Route|null
* The generated route, if available.
*/
protected function getSettingsFormRoute(EntityTypeInterface $entity_type)
{
if (!$entity_type->getBundleEntityType()) {
$route = new Route("/admin/structure/{$entity_type->id()}/settings");
$route->setDefaults(['_form' => 'Drupal\\drupalbristol_sponsors\\Form\\SponsorEntitySettingsForm', '_title' => "{$entity_type->getLabel()} settings"])->setRequirement('_permission', $entity_type->getAdminPermission())->setOption('_admin_route', TRUE);
return $route;
}
}
示例7: getCollectionRoute
/**
* Gets the collection route.
*
* @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
* The entity type.
*
* @return \Symfony\Component\Routing\Route|null
* The generated route, if available.
*/
protected function getCollectionRoute(EntityTypeInterface $entity_type)
{
// If the entity type does not provide an admin permission, there is no way
// to control access, so we cannot provide a route in a sensible way.
if ($entity_type->hasLinkTemplate('collection') && $entity_type->hasListBuilderClass() && ($admin_permission = $entity_type->getAdminPermission())) {
$route = new Route($entity_type->getLinkTemplate('collection'));
$route->addDefaults(['_entity_list' => $entity_type->id(), '_title' => '@label entities', '_title_arguments' => ['@label' => $entity_type->getLabel()]])->setRequirement('_permission', $admin_permission);
return $route;
}
}
示例8: getAdminPermission
protected function getAdminPermission(EntityTypeInterface $entity_type)
{
switch ($entity_type->id()) {
case 'node':
return 'administer nodes';
default:
return $entity_type->getAdminPermission();
}
}