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


PHP FieldDefinitionInterface::getName方法代码示例

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


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

示例1: view

 /**
  * {@inheritdoc}
  */
 public function view(FieldItemListInterface $items, $langcode = NULL)
 {
     // Default the language to the current content language.
     if (empty($langcode)) {
         $langcode = \Drupal::languageManager()->getCurrentLanguage(LanguageInterface::TYPE_CONTENT)->getId();
     }
     $elements = $this->viewElements($items, $langcode);
     // If there are actual renderable children, use #theme => field, otherwise,
     // let access cacheability metadata pass through for correct bubbling.
     if (Element::children($elements)) {
         $entity = $items->getEntity();
         $entity_type = $entity->getEntityTypeId();
         $field_name = $this->fieldDefinition->getName();
         $info = array('#theme' => 'field', '#title' => $this->fieldDefinition->getLabel(), '#label_display' => $this->label, '#view_mode' => $this->viewMode, '#language' => $items->getLangcode(), '#field_name' => $field_name, '#field_type' => $this->fieldDefinition->getType(), '#field_translatable' => $this->fieldDefinition->isTranslatable(), '#entity_type' => $entity_type, '#bundle' => $entity->bundle(), '#object' => $entity, '#items' => $items, '#formatter' => $this->getPluginId(), '#is_multiple' => $this->fieldDefinition->getFieldStorageDefinition()->isMultiple());
         $elements = array_merge($info, $elements);
     }
     return $elements;
 }
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:21,代码来源:FormatterBase.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') {
         $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:ravindrasingh22,项目名称:Drupal-8-rc,代码行数:60,代码来源:CommentAccessControlHandler.php

示例3: checkFieldAccess

 /**
  * {@inheritdoc}
  */
 protected function checkFieldAccess($operation, FieldDefinitionInterface $field_definition, AccountInterface $account, FieldItemListInterface $items = NULL)
 {
     // Fields that are not implicitly allowed to administrative users.
     $explicit_check_fields = array('pass');
     // Administrative users are allowed to edit and view all fields.
     if (!in_array($field_definition->getName(), $explicit_check_fields) && $account->hasPermission('administer users')) {
         return AccessResult::allowed()->cachePerPermissions();
     }
     // Flag to indicate if this user entity is the own user account.
     $is_own_account = $items ? $items->getEntity()->id() == $account->id() : FALSE;
     switch ($field_definition->getName()) {
         case 'name':
             // Allow view access to anyone with access to the entity. Anonymous
             // users should be able to access the username field during the
             // registration process, otherwise the username and email constraints
             // are not checked.
             if ($operation == 'view' || $items && $account->isAnonymous() && $items->getEntity()->isAnonymous()) {
                 return AccessResult::allowed()->cachePerPermissions();
             }
             // Allow edit access for the own user name if the permission is
             // satisfied.
             if ($is_own_account && $account->hasPermission('change own username')) {
                 return AccessResult::allowed()->cachePerPermissions()->cachePerUser();
             } else {
                 return AccessResult::forbidden();
             }
         case 'preferred_langcode':
         case 'preferred_admin_langcode':
         case 'timezone':
         case 'mail':
             // Allow view access to own mail address and other personalization
             // settings.
             if ($operation == 'view') {
                 return $is_own_account ? AccessResult::allowed()->cachePerUser() : AccessResult::forbidden();
             }
             // Anyone that can edit the user can also edit this field.
             return AccessResult::allowed()->cachePerPermissions();
         case 'pass':
             // Allow editing the password, but not viewing it.
             return $operation == 'edit' ? AccessResult::allowed() : AccessResult::forbidden();
         case 'created':
             // Allow viewing the created date, but not editing it.
             return $operation == 'view' ? AccessResult::allowed() : AccessResult::forbidden();
         case 'roles':
         case 'status':
         case 'access':
         case 'login':
         case 'init':
             return AccessResult::forbidden();
     }
     return parent::checkFieldAccess($operation, $field_definition, $account, $items);
 }
开发者ID:sojo,项目名称:d8_friendsofsilence,代码行数:55,代码来源:UserAccessControlHandler.php

示例4: view

 /**
  * {@inheritdoc}
  */
 public function view(FieldItemListInterface $items)
 {
     $addition = array();
     $elements = $this->viewElements($items);
     if ($elements) {
         $entity = $items->getEntity();
         $entity_type = $entity->getEntityTypeId();
         $field_name = $this->fieldDefinition->getName();
         $info = array('#theme' => 'field', '#title' => $this->fieldDefinition->getLabel(), '#label_display' => $this->label, '#view_mode' => $this->viewMode, '#language' => $items->getLangcode(), '#field_name' => $field_name, '#field_type' => $this->fieldDefinition->getType(), '#field_translatable' => $this->fieldDefinition->isTranslatable(), '#entity_type' => $entity_type, '#bundle' => $entity->bundle(), '#object' => $entity, '#items' => $items, '#formatter' => $this->getPluginId());
         $addition = array_merge($info, $elements);
     }
     return $addition;
 }
开发者ID:davidsoloman,项目名称:drupalconsole.com,代码行数:16,代码来源:FormatterBase.php

示例5: checkFieldAccess

 /**
  * {@inheritdoc}
  */
 protected function checkFieldAccess($operation, FieldDefinitionInterface $field_definition, AccountInterface $account, FieldItemListInterface $items = NULL)
 {
     // No user can edit the status of a file. Prevents saving a new file as
     // persistent before even validating it.
     if ($field_definition->getName() === 'status' && $operation === 'edit') {
         return AccessResult::forbidden();
     }
     return parent::checkFieldAccess($operation, $field_definition, $account, $items);
 }
开发者ID:eigentor,项目名称:tommiblog,代码行数:12,代码来源:FileAccessControlHandler.php

示例6: flagErrors

 /**
  * {@inheritdoc}
  */
 public function flagErrors(FieldItemListInterface $items, ConstraintViolationListInterface $violations, array $form, FormStateInterface $form_state)
 {
     $field_name = $this->fieldDefinition->getName();
     $field_state = static::getWidgetState($form['#parents'], $field_name, $form_state);
     if ($violations->count()) {
         $form_builder = \Drupal::formBuilder();
         // Locate the correct element in the the form.
         $element = NestedArray::getValue($form_state['complete_form'], $field_state['array_parents']);
         // Do not report entity-level validation errors if Form API errors have
         // already been reported for the field.
         // @todo Field validation should not be run on fields with FAPI errors to
         //   begin with. See https://drupal.org/node/2070429.
         $element_path = implode('][', $element['#parents']);
         if ($reported_errors = $form_state->getErrors()) {
             foreach (array_keys($reported_errors) as $error_path) {
                 if (strpos($error_path, $element_path) === 0) {
                     return;
                 }
             }
         }
         // Only set errors if the element is accessible.
         if (!isset($element['#access']) || $element['#access']) {
             $handles_multiple = $this->handlesMultipleValues();
             $violations_by_delta = array();
             foreach ($violations as $violation) {
                 // Separate violations by delta.
                 $property_path = explode('.', $violation->getPropertyPath());
                 $delta = array_shift($property_path);
                 // Violations at the ItemList level are not associated to any delta,
                 // we file them under $delta NULL.
                 $delta = is_numeric($delta) ? $delta : NULL;
                 $violations_by_delta[$delta][] = $violation;
                 $violation->arrayPropertyPath = $property_path;
             }
             /** @var \Symfony\Component\Validator\ConstraintViolationInterface[] $delta_violations */
             foreach ($violations_by_delta as $delta => $delta_violations) {
                 // Pass violations to the main element:
                 // - if this is a multiple-value widget,
                 // - or if the violations are at the ItemList level.
                 if ($handles_multiple || $delta === NULL) {
                     $delta_element = $element;
                 } else {
                     $original_delta = $field_state['original_deltas'][$delta];
                     $delta_element = $element[$original_delta];
                 }
                 foreach ($delta_violations as $violation) {
                     // @todo: Pass $violation->arrayPropertyPath as property path.
                     $error_element = $this->errorElement($delta_element, $violation, $form, $form_state);
                     if ($error_element !== FALSE) {
                         $form_state->setError($error_element, $violation->getMessage());
                     }
                 }
             }
         }
     }
 }
开发者ID:anatalsceo,项目名称:en-classe,代码行数:59,代码来源:WidgetBase.php

示例7: isApplicable

 /**
  * {@inheritdoc}
  */
 public static function isApplicable(FieldDefinitionInterface $field_definition)
 {
     $entity_form_display = entity_get_form_display($field_definition->getTargetEntityTypeId(), $field_definition->getTargetBundle(), 'default');
     $widget = $entity_form_display->getRenderer($field_definition->getName());
     $widget_id = $widget->getBaseId();
     if ($field_definition->isList() && $widget_id == 'video_upload') {
         return TRUE;
     }
     return FALSE;
 }
开发者ID:kallehauge,项目名称:iamkallehauge.com,代码行数:13,代码来源:VideoPlayerListFormatter.php

示例8: checkFieldAccess

 /**
  * {@inheritdoc}
  */
 protected function checkFieldAccess($operation, FieldDefinitionInterface $field_definition, AccountInterface $account, FieldItemListInterface $items = NULL)
 {
     /** @var \Drupal\comment\CommentInterface $entity */
     $entity = $items->getEntity();
     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('changed', '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();
         }
         $commented_entity = $entity->getCommentedEntity();
         $anonymous_contact = $commented_entity->get($entity->getFieldName())->getFieldDefinition()->getSetting('anonymous_contact');
         // 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)) {
             $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'))->cachePerRole()->cacheUntilEntityChanges($entity)->cacheUntilEntityChanges($field_definition->getConfig($commented_entity->bundle()))->cacheUntilEntityChanges($commented_entity);
             return $admin_access->orIf($anonymous_access);
         }
     }
     if ($operation == 'view') {
         // 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')->cachePerRole();
         $anonymous_access = AccessResult::allowedIf($account->hasPermission('access comments') && $entity->isPublished() && !in_array($field_definition->getName(), array('mail', 'hostname'), TRUE))->cacheUntilEntityChanges($entity)->cachePerRole();
         return $admin_access->orIf($anonymous_access);
     }
     return parent::checkFieldAccess($operation, $field_definition, $account, $items);
 }
开发者ID:davidsoloman,项目名称:drupalconsole.com,代码行数:40,代码来源:CommentAccessControlHandler.php

示例9: createPayment

 /**
  * {@inheritdoc}
  */
 public function createPayment(FieldDefinitionInterface $field_definition)
 {
     /** @var \Drupal\payment\Entity\PaymentInterface $payment */
     $payment = $this->entityManager->getStorage('payment')->create(['bundle' => 'payment_reference']);
     /** @var \Drupal\payment_reference\Plugin\Payment\Type\PaymentReference $payment_type */
     $payment_type = $payment->getPaymentType();
     $payment_type->setEntityTypeId($field_definition->getFieldStorageDefinition()->getTargetEntityTypeId());
     $payment_type->setBundle($field_definition->getTargetBundle());
     $payment_type->setFieldName($field_definition->getName());
     $payment->setCurrencyCode($field_definition->getSetting('currency_code'));
     foreach ($field_definition->getSetting('line_items_data') as $line_item_data) {
         $line_item = $this->paymentLineItemManager->createInstance($line_item_data['plugin_id'], $line_item_data['plugin_configuration']);
         $payment->setLineItem($line_item);
     }
     return $payment;
 }
开发者ID:nishantkumar155,项目名称:drupal8.crackle,代码行数:19,代码来源:PaymentFactory.php

示例10: match

 /**
  * {@inheritdoc}
  */
 public function match(ContactInterface $contact, $property = 'value')
 {
     $ids = array();
     $field = $this->field->getName();
     $needle = $contact->get($field)->{$property};
     if (!empty($needle)) {
         $this->query->condition('type', $contact->bundle());
         if ($contact->id()) {
             $this->query->condition('contact_id', $contact->id(), '<>');
         }
         if ($field instanceof FieldConfigInterface) {
             $field .= '.' . $property;
         }
         $this->query->condition($field, $needle, $this->getOperator($property));
         $ids = $this->query->execute();
     }
     // Get the score for this field/propery.
     $score = array($this->field->getName() . '.' . $property => $this->getScore($property));
     // Returning an array holding the score as value and the contact id as key.
     return array_fill_keys($ids, $score);
 }
开发者ID:jasonruyle,项目名称:crm_core,代码行数:24,代码来源:FieldHandlerBase.php

示例11: buildForm

 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state, FieldDefinitionInterface $field_config = NULL, $delta = 0)
 {
     $input = $form_state->getUserInput();
     // Store field information in $form_state.
     if (!static::getModalState($form_state)) {
         $field_state = array('page' => 1);
         static::setModalState($form_state, $field_state);
     }
     // Store for ajax commands.
     $form['delta'] = ['#type' => 'value', '#value' => $delta];
     // Get the field settings for filtering and validating files.
     if ($field_config) {
         $form['field_name'] = ['#type' => 'value', '#value' => $field_config->getName()];
         $field_settings = $field_config->getSettings();
         $extensions = $field_settings['file_extensions'];
         $catalog_id = $field_settings['catalog_id'];
     } else {
         // If we are coming from the ckeditor image dialog, we don't have field
         // config, look for extensions in the query string instead.
         // TODO: Think of a better way to do this.
         $query = \Drupal::request()->query->all();
         $extensions = $query['extensions'];
         $catalog_id = $query['catalog_id'];
     }
     $operation_options = ['startswith' => $this->t('Starts with'), 'matches' => $this->t('Matches')];
     $form['filters'] = ['#type' => 'container', '#attributes' => ['class' => ['search-form']], 'title' => ['#markup' => '<span class="search-title">' . $this->t('Search by filename') . '</span>']];
     $form['filters']['filename_op'] = array('#type' => 'select', '#title' => $this->t('Operation'), '#options' => $operation_options, '#default_value' => !empty($input['filename_op']) ? $input['filename_op'] : '');
     $form['filters']['filename'] = array('#type' => 'textfield', '#title' => $this->t('Search by filename'), '#size' => 20, '#default_value' => !empty($input['filename']) ? $input['filename'] : '');
     $ajax_settings = ['callback' => [$this, 'searchAjax'], 'wrapper' => self::AJAX_WRAPPER_ID, 'effect' => 'fade', 'progress' => ['type' => 'throbber']];
     $form['filters']['search'] = ['#type' => 'submit', '#submit' => [[$this, 'searchSubmit']], '#ajax' => $ajax_settings, '#value' => $this->t('Search'), '#attributes' => array('class' => array('embridge-ajax-search-submit'))];
     $filters = [];
     $filters[] = ['field' => 'fileformat', 'operator' => 'matches', 'value' => $this->massageExtensionSetting($extensions)];
     // Static list of known search filters from EMDB.
     // TODO: Make this configurable.
     $known_search_filters = ['libraries', 'assettype', 'fileformat'];
     // Add filename filter as this always exists.
     if (!empty($input['filename_op'])) {
         $filters[] = ['field' => 'name', 'operator' => $input['filename_op'], 'value' => $input['filename']];
     }
     // Add user chosen filters.
     foreach ($known_search_filters as $filter_id) {
         if (empty($input[$filter_id])) {
             continue;
         }
         $filters[] = ['field' => $filter_id, 'operator' => 'matches', 'value' => $input[$filter_id]];
     }
     // Execute a search.
     $modal_state = static::getModalState($form_state);
     $page = $modal_state['page'];
     $search_response = $this->getSearchResults($page, $filters);
     $title = $this->t('More search options');
     $form['filters']['extra_filters'] = ['#markup' => '<div class="moreOptions"><a href="#options" data-toggle="collapse">' . $title . '</a><div id="options" class="collapse">'];
     // Add filters from search response.
     if (!empty($search_response['filteroptions'])) {
         foreach ($search_response['filteroptions'] as $filter) {
             if (!in_array($filter['id'], $known_search_filters)) {
                 continue;
             }
             // "Empty" option.
             $filter_options = [$this->t('-- Select --')];
             // Add each option to the list.
             foreach ($filter['children'] as $option) {
                 $filter_options[$option['id']] = $this->t('@name (@count)', ['@name' => $option['name'], '@count' => $option['count']]);
             }
             $form['filters']['extra_filters'][$filter['id']] = ['#type' => 'select', '#title' => $this->t('@name', ['@name' => $filter['name']]), '#options' => $filter_options, '#default_value' => !empty($input[$filter['id']]) ? $input[$filter['id']] : ''];
         }
     }
     $form['filters']['close_extra_filters'] = ['#markup' => '</div></div>'];
     if (!empty($search_response['results'])) {
         $form['search_results'] = ['#theme' => 'embridge_search_results', '#results' => $this->formatSearchResults($search_response, $this->assetHelper, $catalog_id)];
     } else {
         $form['search_results'] = ['#type' => 'markup', '#markup' => $this->t('<p>No files found, please adjust your filters and try again.</p>')];
     }
     // Add "previous page" pager.
     $form['pagination'] = ['#type' => 'container', '#attributes' => ['class' => ['pagination']]];
     $form['pagination']['page_previous'] = ['#type' => 'submit', '#value' => $this->t('Previous page'), '#submit' => [[$this, 'previousPageSubmit']], '#ajax' => array('callback' => [$this, 'searchAjax'], 'wrapper' => self::AJAX_WRAPPER_ID, 'effect' => 'fade'), '#disabled' => !($page > 1)];
     // Add "next page" pager.
     $form['pagination']['page_next'] = ['#type' => 'submit', '#value' => $this->t('Next page'), '#submit' => [[$this, 'nextPageSubmit']], '#ajax' => array('callback' => [$this, 'searchAjax'], 'wrapper' => self::AJAX_WRAPPER_ID, 'effect' => 'fade'), '#disabled' => !($search_response['response']['pages'] > $search_response['response']['page'])];
     $form['result_chosen'] = ['#type' => 'hidden', '#value' => !empty($input['result_chosen']) ? $input['result_chosen'] : ''];
     $form['actions'] = ['#type' => 'actions'];
     $form['actions']['submit'] = ['#type' => 'submit', '#value' => $this->t('Select'), '#submit' => array(), '#ajax' => array('callback' => [$this, 'selectItemAjax'], 'event' => 'click'), '#attributes' => array('class' => array('embridge-ajax-select-file', 'hidden-button'))];
     $form['#attached']['library'][] = 'embridge/embridge.lib';
     $form['#prefix'] = '<div id="' . self::AJAX_WRAPPER_ID . '"><div id="' . self::MESSAGE_WRAPPER_ID . '"></div>';
     $form['#sufix'] = '</div>';
     return $form;
 }
开发者ID:acbramley,项目名称:embridge,代码行数:89,代码来源:EmbridgeSearchForm.php

示例12: isApplicable

 /**
  * {@inheritdoc}
  */
 public static function isApplicable(FieldDefinitionInterface $field_definition)
 {
     return $field_definition->getName() != 'deny_applicable';
 }
开发者ID:318io,项目名称:318-io,代码行数:7,代码来源:TestFieldApplicableFormatter.php

示例13: hook_entity_field_access

/**
 * Control access to fields.
 *
 * This hook is invoked from
 * \Drupal\Core\Entity\EntityAccessController::fieldAccess() to let modules
 * grant or deny operations on fields.
 *
 * @param string $operation
 *   The operation to be performed. See
 *   \Drupal\Core\Access\AccessibleInterface::access() for possible values.
 * @param \Drupal\Core\Field\FieldDefinitionInterface $field_definition
 *   The field definition.
 * @param \Drupal\Core\Session\AccountInterface $account
 *   The user account to check.
 * @param \Drupal\Core\Field\FieldItemListInterface $items
 *   (optional) The entity field object on which the operation is to be
 *   performed.
 *
 * @return bool|null
 *   TRUE if access should be allowed, FALSE if access should be denied and NULL
 *   if the implementation has no opinion.
 */
function hook_entity_field_access($operation, \Drupal\Core\Field\FieldDefinitionInterface $field_definition, \Drupal\Core\Session\AccountInterface $account, \Drupal\Core\Field\FieldItemListInterface $items = NULL)
{
    if ($field_definition->getName() == 'field_of_interest' && $operation == 'edit') {
        return $account->hasPermission('update field of interest');
    }
}
开发者ID:anatalsceo,项目名称:en-classe,代码行数:28,代码来源:entity.api.php

示例14: isApplicable

 /**
  * {@inheritdoc}
  */
 public static function isApplicable(FieldDefinitionInterface $field_definition)
 {
     $has_cart = \Drupal::moduleHandler()->moduleExists('commerce_cart');
     $entity_type = $field_definition->getTargetEntityTypeId();
     $field_name = $field_definition->getName();
     return $has_cart && $entity_type == 'commerce_product' && $field_name == 'variations';
 }
开发者ID:alexburrows,项目名称:cream-2.x,代码行数:10,代码来源:AddToCartFormatter.php

示例15: isApplicable

 /**
  * {@inheritdoc}
  */
 public static function isApplicable(FieldDefinitionInterface $field_definition)
 {
     $entity_type = $field_definition->getTargetEntityTypeId();
     $field_name = $field_definition->getName();
     return $entity_type == 'commerce_order' && $field_name == 'line_items';
 }
开发者ID:alexburrows,项目名称:cream-2.x,代码行数:9,代码来源:LineItemTable.php


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