当前位置: 首页>>代码示例>>PHP>>正文


PHP FieldDefinitionInterface::getConfig方法代码示例

本文整理汇总了PHP中Drupal\Core\Field\FieldDefinitionInterface::getConfig方法的典型用法代码示例。如果您正苦于以下问题:PHP FieldDefinitionInterface::getConfig方法的具体用法?PHP FieldDefinitionInterface::getConfig怎么用?PHP FieldDefinitionInterface::getConfig使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Drupal\Core\Field\FieldDefinitionInterface的用法示例。


在下文中一共展示了FieldDefinitionInterface::getConfig方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: checkFieldAccess

 /**
  * {@inheritdoc}
  */
 protected function checkFieldAccess($operation, FieldDefinitionInterface $field_definition, AccountInterface $account, FieldItemListInterface $items = NULL)
 {
     if ($operation == 'edit') {
         // Only users with the "administer comments" permission can edit
         // administrative fields.
         $administrative_fields = array('uid', 'status', 'created', 'date');
         if (in_array($field_definition->getName(), $administrative_fields, TRUE)) {
             return AccessResult::allowedIfHasPermission($account, 'administer comments');
         }
         // No user can change read-only fields.
         $read_only_fields = array('hostname', 'uuid', 'cid', 'thread', 'comment_type', 'pid', 'entity_id', 'entity_type', 'field_name');
         if (in_array($field_definition->getName(), $read_only_fields, TRUE)) {
             return AccessResult::forbidden();
         }
         // If the field is configured to accept anonymous contact details - admins
         // can edit name, homepage and mail. Anonymous users can also fill in the
         // fields on comment creation.
         if (in_array($field_definition->getName(), ['name', 'mail', 'homepage'], TRUE)) {
             if (!$items) {
                 // We cannot make a decision about access to edit these fields if we
                 // don't have any items and therefore cannot determine the Comment
                 // entity. In this case we err on the side of caution and prevent edit
                 // access.
                 return AccessResult::forbidden();
             }
             /** @var \Drupal\comment\CommentInterface $entity */
             $entity = $items->getEntity();
             $commented_entity = $entity->getCommentedEntity();
             $anonymous_contact = $commented_entity->get($entity->getFieldName())->getFieldDefinition()->getSetting('anonymous');
             $admin_access = AccessResult::allowedIfHasPermission($account, 'administer comments');
             $anonymous_access = AccessResult::allowedIf($entity->isNew() && $account->isAnonymous() && $anonymous_contact != COMMENT_ANONYMOUS_MAYNOT_CONTACT && $account->hasPermission('post comments'))->cachePerPermissions()->cacheUntilEntityChanges($entity)->cacheUntilEntityChanges($field_definition->getConfig($commented_entity->bundle()))->cacheUntilEntityChanges($commented_entity);
             return $admin_access->orIf($anonymous_access);
         }
     }
     if ($operation == 'view') {
         $entity = $items ? $items->getEntity() : NULL;
         // Admins can view any fields except hostname, other users need both the
         // "access comments" permission and for the comment to be published. The
         // mail field is hidden from non-admins.
         $admin_access = AccessResult::allowedIf($account->hasPermission('administer comments') && $field_definition->getName() != 'hostname')->cachePerPermissions();
         $anonymous_access = AccessResult::allowedIf($account->hasPermission('access comments') && (!$entity || $entity->isPublished()) && !in_array($field_definition->getName(), array('mail', 'hostname'), TRUE))->cachePerPermissions();
         if ($entity) {
             $anonymous_access->cacheUntilEntityChanges($entity);
         }
         return $admin_access->orIf($anonymous_access);
     }
     return parent::checkFieldAccess($operation, $field_definition, $account, $items);
 }
开发者ID:brstde,项目名称:gap1,代码行数:51,代码来源:CommentAccessControlHandler.php

示例2: checkFieldAccess

 /**
  * {@inheritdoc}
  */
 protected function checkFieldAccess($operation, FieldDefinitionInterface $field_definition, AccountInterface $account, FieldItemListInterface $items = NULL)
 {
     if ($operation == 'edit') {
         // Only users with the "administer comments" permission can edit
         // administrative fields.
         $administrative_fields = array('uid', 'status', 'created', 'date');
         if (in_array($field_definition->getName(), $administrative_fields, TRUE)) {
             return AccessResult::allowedIfHasPermission($account, 'administer comments');
         }
         // No user can change read-only fields.
         $read_only_fields = array('hostname', 'changed', 'cid', 'thread');
         // These fields can be edited during comment creation.
         $create_only_fields = ['comment_type', 'uuid', 'entity_id', 'entity_type', 'field_name', 'pid'];
         if ($items && ($entity = $items->getEntity()) && $entity->isNew() && in_array($field_definition->getName(), $create_only_fields, TRUE)) {
             // We are creating a new comment, user can edit create only fields.
             return AccessResult::allowedIfHasPermission($account, 'post comments')->addCacheableDependency($entity);
         }
         // We are editing an existing comment - create only fields are now read
         // only.
         $read_only_fields = array_merge($read_only_fields, $create_only_fields);
         if (in_array($field_definition->getName(), $read_only_fields, TRUE)) {
             return AccessResult::forbidden();
         }
         // If the field is configured to accept anonymous contact details - admins
         // can edit name, homepage and mail. Anonymous users can also fill in the
         // fields on comment creation.
         if (in_array($field_definition->getName(), ['name', 'mail', 'homepage'], TRUE)) {
             if (!$items) {
                 // We cannot make a decision about access to edit these fields if we
                 // don't have any items and therefore cannot determine the Comment
                 // entity. In this case we err on the side of caution and prevent edit
                 // access.
                 return AccessResult::forbidden();
             }
             /** @var \Drupal\comment\CommentInterface $entity */
             $entity = $items->getEntity();
             $commented_entity = $entity->getCommentedEntity();
             $anonymous_contact = $commented_entity->get($entity->getFieldName())->getFieldDefinition()->getSetting('anonymous');
             $admin_access = AccessResult::allowedIfHasPermission($account, 'administer comments');
             $anonymous_access = AccessResult::allowedIf($entity->isNew() && $account->isAnonymous() && $anonymous_contact != COMMENT_ANONYMOUS_MAYNOT_CONTACT && $account->hasPermission('post comments'))->cachePerPermissions()->cacheUntilEntityChanges($entity)->cacheUntilEntityChanges($field_definition->getConfig($commented_entity->bundle()))->cacheUntilEntityChanges($commented_entity);
             return $admin_access->orIf($anonymous_access);
         }
     }
     if ($operation == 'view') {
         // Nobody has access to the hostname.
         if ($field_definition->getName() == 'hostname') {
             return AccessResult::forbidden();
         }
         // The mail field is hidden from non-admins.
         if ($field_definition->getName() == 'mail') {
             return AccessResult::allowedIfHasPermission($account, 'administer comments');
         }
     }
     return parent::checkFieldAccess($operation, $field_definition, $account, $items);
 }
开发者ID:ddrozdik,项目名称:dmaps,代码行数:58,代码来源:CommentAccessControlHandler.php


注:本文中的Drupal\Core\Field\FieldDefinitionInterface::getConfig方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。