本文整理汇总了PHP中Drupal\Core\Entity\EntityInterface::id方法的典型用法代码示例。如果您正苦于以下问题:PHP EntityInterface::id方法的具体用法?PHP EntityInterface::id怎么用?PHP EntityInterface::id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Drupal\Core\Entity\EntityInterface
的用法示例。
在下文中一共展示了EntityInterface::id方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: checkAccess
/**
* {@inheritdoc}
*
* When the $operation is 'add' then the $entity is of type 'profile_type',
* otherwise $entity is of type 'profile'.
*/
protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account)
{
$account = $this->prepareUser($account);
$user_page = \Drupal::request()->attributes->get('user');
// Some times, operation edit is called update.
// Use edit in any case.
if ($operation == 'update') {
$operation = 'edit';
}
// Check that if profile type has require roles, the user the profile is
// being added to has any of the required roles.
if ($entity->getEntityTypeId() == 'profile') {
$profile_roles = ProfileType::load($entity->bundle())->getRoles();
$user_roles = $entity->getOwner()->getRoles(TRUE);
if (!empty(array_filter($profile_roles)) && !array_intersect($user_roles, $profile_roles)) {
return AccessResult::forbidden();
}
} elseif ($entity->getEntityTypeId() == 'profile_type') {
$profile_roles = $entity->getRoles();
$user_roles = User::load($user_page->id())->getRoles(TRUE);
if (!empty(array_filter($profile_roles)) && !array_intersect($user_roles, $profile_roles)) {
return AccessResult::forbidden();
}
}
if ($account->hasPermission('bypass profile access')) {
return AccessResult::allowed()->cachePerPermissions();
} elseif ($operation == 'add' && ($user_page->id() == $account->id() && $account->hasPermission($operation . ' own ' . $entity->id() . ' profile') || $account->hasPermission($operation . ' any ' . $entity->id() . ' profile')) || $operation != 'add' && ($entity->getOwnerId() == $account->id() && $account->hasPermission($operation . ' own ' . $entity->getType() . ' profile') || $account->hasPermission($operation . ' any ' . $entity->getType() . ' profile'))) {
return AccessResult::allowed()->cachePerPermissions();
} else {
return AccessResult::forbidden()->cachePerPermissions();
}
}
示例2: buildRow
/**
* {@inheritdoc}
*/
public function buildRow(EntityInterface $entity)
{
/* @var $entity \Drupal\content_entity_example\Entity\OnlineMessage */
$row['id'] = $entity->id();
$row['name'] = $this->l($entity->label(), new Url('entity.online_message.edit_form', array('online_message' => $entity->id())));
return $row + parent::buildRow($entity);
}
示例3: getLabelAndConfig
/**
* Renders the Metatag defaults lable plus its configuration.
*
* @param EntityInterface $entity
* The Metatag defaults entity.
* @return
* Render array for a table cell.
*/
public function getLabelAndConfig(EntityInterface $entity)
{
$output = '<div>';
$prefix = '';
$inherits = '';
if ($entity->id() != 'global') {
$prefix = '<div class="indentation"></div>';
$inherits .= 'Global';
}
if (strpos($entity->id(), '__') !== FALSE) {
$prefix .= '<div class="indentation"></div>';
list($entity_label, $bundle_label) = explode(': ', $entity->get('label'));
$inherits .= ', ' . $entity_label;
}
$output .= '<div>
<p>Inherits meta tags from: ' . $inherits . '</p>
</div>';
$tags = $entity->get('tags');
if (count($tags)) {
$output .= '<table>
<tbody>';
foreach ($tags as $tag_id => $tag_value) {
$output .= '<tr><td>' . $tag_id . ':</td><td>' . $tag_value . '</td></tr>';
}
$output .= '</tbody></table>';
}
$output .= '</div></div>';
return array('data' => array('#type' => 'details', '#prefix' => $prefix, '#title' => $this->getLabel($entity), 'config' => array('#markup' => $output)));
}
示例4: buildRow
/**
* {@inheritdoc}
*/
public function buildRow(EntityInterface $entity)
{
/* @var $entity \Drupal\drupal8_entity\Entity\Drupal8EntityItem */
$row['id'] = $entity->id();
$row['name'] = $this->l($entity->label(), new Url('entity.drupal8_entity_item.edit_form', array('drupal8_entity_item' => $entity->id())));
return $row + parent::buildRow($entity);
}
示例5: buildRow
/**
* {@inheritdoc}
*/
public function buildRow(EntityInterface $entity)
{
/* @var $entity \Drupal\drupalbristol_sponsors\Entity\SponsorEntity */
$row['id'] = $entity->id();
$row['name'] = $this->l($entity->label(), new Url('entity.sponsor.edit_form', array('sponsor' => $entity->id())));
return $row + parent::buildRow($entity);
}
示例6: buildRow
/**
* {@inheritdoc}
*/
public function buildRow(EntityInterface $entity)
{
/* @var $entity \Drupal\custom_page\Entity\CustomPage */
$row['id'] = $entity->id();
$row['name'] = $this->l($entity->label(), new Url('entity.custom_page.canonical', array('custom_page' => $entity->id())));
$row['uuid'] = $entity->uuid();
return $row + parent::buildRow($entity);
}
示例7: buildRow
/**
* {@inheritdoc}
*/
public function buildRow(EntityInterface $entity)
{
/* @var $entity \Drupal\component\Entity\Component */
$row['id'] = $entity->id();
$row['name'] = $this->l($entity->label(), new Url('entity.component.canonical', array('component' => $entity->id())));
$row['uuid'] = $entity->uuid();
return $row + parent::buildRow($entity);
}
示例8: alterBuild
/**
* {@inheritdoc}
*/
protected function alterBuild(array &$build, EntityInterface $entity, EntityViewDisplayInterface $display, $view_mode)
{
$entity_type_id = $entity->getEntityTypeId();
if ($entity instanceof ContentEntityInterface && $entity->isDefaultRevision() || !$entity->getEntityType()->isRevisionable()) {
$build['#contextual_links'][$entity_type_id] = ['route_parameters' => [$entity_type_id => $entity->id()]];
} else {
$build['#contextual_links'][$entity_type_id . '_revision'] = ['route_parameters' => [$entity_type_id => $entity->id(), $entity_type_id . '_revision' => $entity->getRevisionId()]];
}
}
示例9: buildRow
/**
* {@inheritdoc}
*/
public function buildRow(EntityInterface $entity)
{
if ($entity->isLocked()) {
$row['id'] = $this->t('@entity_id (locked)', array('@entity_id' => $entity->id()));
} else {
$row['id'] = $entity->id();
}
$row['label'] = $this->getLabel($entity);
$row['pattern'] = $this->dateFormatter->format(REQUEST_TIME, $entity->id());
return $row + parent::buildRow($entity);
}
示例10: checkAccess
/**
* {@inheritdoc}
*/
protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account)
{
switch ($operation) {
case 'delete':
if ($entity->id() == RoleInterface::ANONYMOUS_ID || $entity->id() == RoleInterface::AUTHENTICATED_ID) {
return AccessResult::forbidden();
}
default:
return parent::checkAccess($entity, $operation, $account);
}
}
示例11: checkAccess
/**
* {@inheritdoc}
*/
protected function checkAccess(EntityInterface $entity, $operation, $langcode, AccountInterface $account)
{
switch ($operation) {
case 'delete':
if ($entity->id() == DRUPAL_ANONYMOUS_RID || $entity->id() == DRUPAL_AUTHENTICATED_RID) {
return FALSE;
}
default:
return parent::checkAccess($entity, $operation, $langcode, $account);
}
}
示例12: checkAccess
/**
* {@inheritdoc}
*/
public function checkAccess(EntityInterface $entity, $operation, $langcode, AccountInterface $account)
{
if ($operation == 'view') {
// Do not allow access personal category via site-wide route.
return $account->hasPermission('access site-wide contact form') && $entity->id() !== 'personal';
} elseif ($operation == 'delete' || $operation == 'update') {
// Do not allow the 'personal' category to be deleted, as it's used for
// the personal contact form.
return $account->hasPermission('administer contact forms') && $entity->id() !== 'personal';
}
return parent::checkAccess($entity, $operation, $langcode, $account);
}
示例13: checkAccess
/**
* {@inheritdoc}
*/
protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account)
{
if ($operation == 'view') {
// Do not allow access personal form via site-wide route.
return AccessResult::allowedIf($account->hasPermission('access site-wide contact form') && $entity->id() !== 'personal')->cachePerPermissions();
} elseif ($operation == 'delete' || $operation == 'update') {
// Do not allow the 'personal' form to be deleted, as it's used for
// the personal contact form.
return AccessResult::allowedIf($account->hasPermission('administer contact forms') && $entity->id() !== 'personal')->cachePerPermissions();
}
return parent::checkAccess($entity, $operation, $account);
}
示例14: viewAccess
/**
* Check view access.
*
* See EntityAccessControllerInterface::view() for parameters.
*/
protected function viewAccess(EntityInterface $entity, $langcode, AccountInterface $account)
{
// Never allow access to view the anonymous user account.
if ($entity->id()) {
// Admins can view all, users can view own profiles at all times.
if ($account->id() == $entity->id() || $account->hasPermission('administer users')) {
return TRUE;
} elseif ($account->hasPermission('access user profiles')) {
// Only allow view access if the account is active.
return $entity->status->value;
}
}
return FALSE;
}
示例15: buildRow
/**
* {@inheritdoc}
*/
public function buildRow(EntityInterface $entity)
{
/* @var $entity \Drupal\checkstyle\Entity\CheckstyleIssue */
$row['id'] = $this->l($entity->id(), new Url('entity.checkstyle_issue.edit_form', array('checkstyle_issue' => $entity->id())));
/** @var EntityReferenceFieldItemList $ref_field */
$ref_field = $entity->get('issue_type');
/** @var Node $ref_entity */
$ref_entity = Node::load($ref_field->get(0)->getValue()['target_id']);
#krumo($ref_entity->get('issue_type')->getValue()[0]['value']);
#krumo( $ref_entity->get('title'));
# @todo find decent way of displaying this stuff
$row['issue_type'] = $ref_entity->get('issue_type')->getValue()[0]['value'];
return $row + parent::buildRow($entity);
}