• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP Field\FieldItemListInterface类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: viewElements

 /**
  * {@inheritdoc}
  */
 public function viewElements(FieldItemListInterface $items)
 {
     $element = array();
     $entity = $items->getEntity();
     $settings = $this->getSettings();
     foreach ($items as $delta => $item) {
         // By default use the full URL as the link text.
         $url = $this->buildUrl($item);
         $link_title = $url->toString();
         // If the link text field value is available, use it for the text.
         if (empty($settings['url_only']) && !empty($item->title)) {
             // Unsanitized token replacement here because $options['html'] is FALSE
             // by default in l().
             $link_title = \Drupal::token()->replace($item->title, array($entity->getEntityTypeId() => $entity), array('sanitize' => FALSE, 'clear' => TRUE));
         }
         // The link_separate formatter has two titles; the link text (as in the
         // field values) and the URL itself. If there is no link text value,
         // $link_title defaults to the URL, so it needs to be unset.
         // The URL version may need to be trimmed as well.
         if (empty($item->title)) {
             $link_title = NULL;
         }
         $url_title = $url->toString();
         if (!empty($settings['trim_length'])) {
             $link_title = truncate_utf8($link_title, $settings['trim_length'], FALSE, TRUE);
             $url_title = truncate_utf8($url_title, $settings['trim_length'], FALSE, TRUE);
         }
         $element[$delta] = array('#theme' => 'link_formatter_link_separate', '#title' => $link_title, '#url_title' => $url_title, '#url' => $url);
     }
     return $element;
 }
开发者ID:alnutile,项目名称:drunatra,代码行数:34,代码来源:LinkSeparateFormatter.php


示例2: formElement

 /**
  * {@inheritdoc}
  */
 public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state)
 {
     $OriginalValue = '';
     if (($node = \Drupal::routeMatch()->getParameter('node')) && $node instanceof \Drupal\node\NodeInterface) {
         $FiledsView = $items->view();
         $LangCode = $items->getLangcode();
         $FieldName = $FiledsView['#field_name'];
         $node = (array) $node;
         $arrayValues = array_values($node);
         if (isset($arrayValues[0]['langcode']['x-default']) && $arrayValues[0]['langcode']['x-default'] != $LangCode) {
             if ($FieldName != 'title') {
                 if (isset($arrayValues[0][$FieldName]['x-default'][0]['value'])) {
                     $OriginalValue = $arrayValues[0][$FieldName]['x-default'][0]['value'];
                 }
             } else {
                 if (isset($arrayValues[0][$FieldName]['x-default'])) {
                     $OriginalValue = $arrayValues[0][$FieldName]['x-default'];
                 }
             }
             $Title = $OriginalValue;
             $OriginalValue = Unicode::truncate($OriginalValue, 200, TRUE);
             $OriginalValue = '<div class="original_text" title="' . $Title . '"><span class="original">ORIGINAL: </span>' . $OriginalValue . '</div>';
         }
     }
     $element['value'] = $element + array('#type' => 'textfield', '#default_value' => isset($items[$delta]->value) ? $items[$delta]->value : NULL, '#size' => $this->getSetting('size'), '#placeholder' => $this->getSetting('placeholder'), '#maxlength' => $this->getFieldSetting('max_length'), '#attributes' => array('class' => array('text-full')), '#suffix' => $OriginalValue);
     return $element;
 }
开发者ID:brstde,项目名称:gap1,代码行数:30,代码来源:StringTextfieldWidget.php


示例3: formElement

 /**
  * {@inheritdoc}
  */
 public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state)
 {
     $field_settings = $this->getFieldSettings();
     // The field settings include defaults for the field type. However, this
     // widget is a base class for other widgets (e.g., ImageWidget) that may act
     // on field types without these expected settings.
     $field_settings += array('display_default' => NULL, 'display_field' => NULL, 'description_field' => NULL);
     $cardinality = $this->fieldDefinition->getFieldStorageDefinition()->getCardinality();
     $defaults = array('fids' => array(), 'display' => (bool) $field_settings['display_default'], 'description' => '');
     // Essentially we use the managed_file type, extended with some
     // enhancements.
     $element_info = $this->elementInfo->getInfo('embridge_asset');
     $element += array('#type' => 'embridge_asset', '#upload_location' => $items[$delta]->getUploadLocation(), '#upload_validators' => $items[$delta]->getUploadValidators(), '#value_callback' => array(get_class($this), 'value'), '#process' => array_merge($element_info['#process'], array(array(get_class($this), 'process'))), '#progress_indicator' => $this->getSetting('progress_indicator'), '#extended' => TRUE, '#entity_type' => $items->getEntity()->getEntityTypeId(), '#field_name' => $this->fieldDefinition->getName(), '#field_config' => $this->fieldDefinition->id(), '#allow_search' => $field_settings['allow_search'], '#display_field' => (bool) $field_settings['display_field'], '#display_default' => $field_settings['display_default'], '#description_field' => $field_settings['description_field'], '#cardinality' => $cardinality, '#catalog_id' => $field_settings['catalog_id'], '#library_id' => $field_settings['library_id']);
     $element['#weight'] = $delta;
     // Field stores FID value in a single mode, so we need to transform it for
     // form element to recognize it correctly.
     if (!isset($items[$delta]->fids) && isset($items[$delta]->target_id)) {
         $items[$delta]->fids = array($items[$delta]->target_id);
     }
     $element['#default_value'] = $items[$delta]->getValue() + $defaults;
     $default_fids = $element['#extended'] ? $element['#default_value']['fids'] : $element['#default_value'];
     if (empty($default_fids)) {
         $file_upload_help = array('#theme' => 'file_upload_help', '#description' => $element['#description'], '#upload_validators' => $element['#upload_validators'], '#cardinality' => $cardinality);
         $this->alterFileUploadHelpParameters($file_upload_help);
         $element['#description'] = \Drupal::service('renderer')->renderPlain($file_upload_help);
         $element['#multiple'] = $cardinality != 1 ? TRUE : FALSE;
         if ($cardinality != 1 && $cardinality != -1) {
             $element['#element_validate'] = array(array(get_class($this), 'validateMultipleCount'));
         }
     }
     return $element;
 }
开发者ID:acbramley,项目名称:embridge,代码行数:35,代码来源:EmbridgeAssetWidget.php


示例4: viewElements

 /**
  * {@inheritdoc}
  */
 public function viewElements(FieldItemListInterface $items, $langcode)
 {
     $element = array();
     $settings = $this->getSettings();
     $items_array = array();
     foreach ($items as $item) {
         $items_array[] = $item;
     }
     // Merge defaults from the formatters and ensure proper ordering.
     $this->prepareFormatters($this->fieldDefinition->getType(), $settings['formatters']);
     // Loop through each formatter in order.
     foreach ($settings['formatters'] as $name => $options) {
         // Run any unrendered items through the formatter.
         $formatter_items = array_diff_key($items_array, $element);
         $formatter_instance = $this->getFormatter($options);
         $formatter_instance->prepareView(array($items->getEntity()->id() => $items));
         if ($result = $formatter_instance->viewElements($items, $langcode)) {
             // Only add visible content from the formatter's render array result
             // that matches an unseen delta.
             $visible_deltas = Element::getVisibleChildren($result);
             $visible_deltas = array_intersect($visible_deltas, array_keys($formatter_items));
             $element += array_intersect_key($result, array_flip($visible_deltas));
             // If running this formatter completed the output for all items, then
             // there is no need to loop through the rest of the formatters.
             if (count($element) == count($items_array)) {
                 break;
             }
         }
     }
     // Ensure the resulting elements are ordered properly by delta.
     ksort($element);
     return $element;
 }
开发者ID:DrupalTV,项目名称:DrupalTV,代码行数:36,代码来源:FallbackFormatter.php


示例5: viewElements

 /**
  * {@inheritdoc}
  */
 public function viewElements(FieldItemListInterface $items)
 {
     $element = array();
     $entity = $items->getEntity();
     $settings = $this->getSettings();
     foreach ($items as $delta => $item) {
         // By default use the full URL as the link text.
         $url = $this->buildUrl($item);
         $link_title = $url->toString();
         // If the title field value is available, use it for the link text.
         if (empty($settings['url_only']) && !empty($item->title)) {
             // Unsanitized token replacement here because $options['html'] is FALSE
             // by default in l().
             $link_title = \Drupal::token()->replace($item->title, array($entity->getEntityTypeId() => $entity), array('sanitize' => FALSE, 'clear' => TRUE));
         }
         // Trim the link text to the desired length.
         if (!empty($settings['trim_length'])) {
             $link_title = truncate_utf8($link_title, $settings['trim_length'], FALSE, TRUE);
         }
         if (!empty($settings['url_only']) && !empty($settings['url_plain'])) {
             $element[$delta] = array('#markup' => String::checkPlain($link_title));
         } else {
             $element[$delta] = array('#type' => 'link', '#title' => $link_title, '#options' => $url->getOptions());
             if ($url->isExternal()) {
                 $element[$delta]['#href'] = $url->getPath();
             } else {
                 $element[$delta]['#route_name'] = $url->getRouteName();
                 $element[$delta]['#route_parameters'] = $url->getRouteParameters();
             }
         }
     }
     return $element;
 }
开发者ID:alnutile,项目名称:drunatra,代码行数:36,代码来源:LinkFormatter.php


示例6: viewElements

 /**
  * {@inheritdoc}
  *
  * TODO: Use $langcode.
  */
 public function viewElements(FieldItemListInterface $items, $langcode)
 {
     $element = array();
     $settings = $this->getFieldSettings();
     $count = 0;
     // TODO: Is there a better way to get an accurate count of the
     // items from the FieldItemList that doesn't count blank items?
     // Possibly \Countable->count()?
     $storage = \Drupal::entityTypeManager()->getStorage('field_collection_item');
     foreach ($items as $delta => $item) {
         if ($item->value !== NULL) {
             $count++;
             $field_collection_item = $storage->loadRevision($item->revision_id);
             if ($field_collection_item->isDefaultRevision()) {
                 $links = \Drupal::l($this->fieldDefinition->getName() . ' ' . $delta, Url::FromRoute('entity.field_collection_item.canonical', array('field_collection_item' => $item->value)));
                 $links .= ' ' . $this->getEditLinks($item);
             } else {
                 $links = \Drupal::l($this->fieldDefinition->getName() . ' ' . $delta, Url::FromRoute('field_collection_item.revision_show', ['field_collection_item' => $item->value, 'field_collection_item_revision' => $item->revision_id]));
             }
             $element[$delta] = array('#markup' => $links);
         }
     }
     $cardinality = $this->fieldDefinition->getFieldStorageDefinition()->getCardinality();
     if ($cardinality == -1 || $count < $cardinality) {
         $element['#suffix'] = '<ul class="action-links action-links-field-collection-add"><li>';
         $element['#suffix'] .= $this->getAddLink($items->getEntity());
         $element['#suffix'] .= '</li></ul>';
     }
     return $element;
 }
开发者ID:darrylri,项目名称:protovbmwmo,代码行数:35,代码来源:FieldCollectionListFormatter.php


示例7: getValueFromProperty

 /**
  * {@inheritdoc}
  */
 public function getValueFromProperty(FieldItemListInterface $property, $delta = 0)
 {
     if ($property->getValue() && $property->getFieldDefinition()->getCardinality() == 1) {
         return $property->referencedEntities()[0];
     }
     return $property->referencedEntities();
 }
开发者ID:jeroenos,项目名称:jeroenos_d8.mypressonline.com,代码行数:10,代码来源:EntityReferenceTypeResolver.php


示例8: viewElements

 /**
  * {@inheritdoc}
  */
 public function viewElements(FieldItemListInterface $items, $langcode = NULL)
 {
     $elements = array();
     // This field should be on a comment.
     // Get the entity type of the entity this comment is attached to.
     $entityType = $items->getEntity()->get('entity_type')->value;
     foreach ($items as $delta => $item) {
         if (!empty($item->right_rid)) {
             $storage = \Drupal::entityManager()->getStorage($entityType);
             $right_revision = $storage->loadRevision($item->right_rid);
             $entity = $storage->load($right_revision->id());
             if (!empty($item->left_rid)) {
                 // We have a pair of revisions
                 $left_revision = $storage->loadRevision($item->left_rid);
                 $plugin = $this->diffLayoutManager->createInstance('changes');
                 $elements[$delta] = $plugin->build($left_revision, $right_revision, $entity);
             } else {
                 // We have just a single revision, the original of this entity.
                 // Only link to it if it is not the current revision.
                 if ($item->right_rid !== $entity->getRevisionId()) {
                     // Trigger exclusion of interactive items like on preview.
                     $right_revision->in_preview = TRUE;
                     $view_builder = \Drupal::entityTypeManager()->getViewBuilder($entityType);
                     $original = $view_builder->view($right_revision);
                     $elements[$delta] = ['#type' => 'details', '#title' => 'Original version'];
                     $elements[$delta]['original'] = $original;
                 }
             }
         }
     }
     return $elements;
 }
开发者ID:shrimala,项目名称:ahsweb,代码行数:35,代码来源:changesFormatter.php


示例9: extractFormValues

 /**
  * {@inheritdoc}
  */
 public function extractFormValues(FieldItemListInterface $items, array $form, FormStateInterface $form_state)
 {
     if ($this->isDefaultValueWidget($form_state)) {
         $items->filterEmptyItems();
         return;
     }
     $field_name = $this->fieldDefinition->getName();
     $path = array_merge($form['#parents'], array($field_name));
     $submitted_values = $form_state->getValue($path);
     $values = [];
     foreach ($items as $delta => $value) {
         $this->setIefId(sha1($items->getName() . '-ief-single-' . $delta));
         /** @var \Drupal\Core\Entity\EntityInterface $entity */
         if (!($entity = $form_state->get(['inline_entity_form', $this->getIefId(), 'entity']))) {
             return;
         }
         $values[$submitted_values[$delta]['_weight']] = ['entity' => $entity];
     }
     // Sort items base on weights.
     ksort($values);
     $values = array_values($values);
     // Let the widget massage the submitted values.
     $values = $this->massageFormValues($values, $form, $form_state);
     // Assign the values and remove the empty ones.
     $items->setValue($values);
     $items->filterEmptyItems();
     // Put delta mapping in $form_state, so that flagErrors() can use it.
     $field_name = $this->fieldDefinition->getName();
     $field_state = WidgetBase::getWidgetState($form['#parents'], $field_name, $form_state);
     foreach ($items as $delta => $item) {
         $field_state['original_deltas'][$delta] = isset($item->_original_delta) ? $item->_original_delta : $delta;
         unset($item->_original_delta, $item->_weight);
     }
     WidgetBase::setWidgetState($form['#parents'], $field_name, $form_state, $field_state);
 }
开发者ID:atif-shaikh,项目名称:DCX-Profile,代码行数:38,代码来源:InlineEntityFormSimple.php


示例10: formElement

 /**
  * {@inheritdoc}
  */
 public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state)
 {
     $referenced_entities = $items->referencedEntities();
     $element = parent::formElement($items, $delta, $element, $form, $form_state);
     // If this is an existing (not new item).
     if ($delta < count($referenced_entities)) {
         // Mark element as being existing, not new item.
         // Top level of the returned element must be called 'target_id',
         // so we cannot create a container.
         // Autocomplete element does some fancy processing to handle empty strings,
         // so we must use an autocomplete element not a hidden or textfield element.
         // But #states[#visible] does not seem to have an option to always hide.,
         // and autocomplete elements don't seem to accept #attributes, so we must
         // use #prefix and #suffix to add a class so that we can hide it.
         $element['#prefix'] = '<div class="er-enhanced-existing">';
         $element['#suffix'] = '</div>';
         if ($this->getSetting('preview')) {
             // Add preview.
             $element['#prefix'] = '<div class="er-enhanced-existing er-enhanced-previewing">';
             $element['#attached']['library'][] = 'ahs_er_enhanced/preview';
             $entityTypeName = $referenced_entities[$delta]->getEntityType()->id();
             $view_builder = \Drupal::entityTypeManager()->getViewBuilder($entityTypeName);
             $preview = $view_builder->view($referenced_entities[$delta], $this->getSetting('preview_view_mode'));
             $element['preview_container'] = ['#type' => 'container', '#attributes' => ['class' => ['er-enhanced-preview']], 'preview' => $preview];
             // Add a remove link to the preview.
             $element['remove'] = ['#markup' => '<a class="er-enhanced-remove" href="">' . t('Remove') . '</a>'];
             $element['#attached']['library'][] = 'ahs_er_enhanced/remove';
         }
     } else {
         $element['#prefix'] = '<div class="er-enhanced-new">';
         $element['#suffix'] = '</div>';
     }
     return $element;
 }
开发者ID:shrimala,项目名称:ahsweb,代码行数:37,代码来源:EntityReferenceAutocompleteEnhancedWidget.php


示例11: formElement

 /**
  * {@inheritdoc}
  */
 public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state)
 {
     // Shows the "default fields" in the edit-type-field page, AND edit-fields on the article-edit-page
     /** @var \Drupal\iframe\Plugin\Field\FieldType\IframeItem $item */
     $item = $items[$delta];
     $field_settings = $this->getFieldSettings();
     $settings = $this->getSettings();
     $settings += $field_settings;
     $entity = $items->getEntity();
     # pre fill with other attributes, (! last chance here !)
     if (TRUE) {
         # $entity->isNew() ?
         foreach (self::defaultSettings() as $dkey => $dval) {
             $ddval = isset($item->{$dkey}) ? $item->{$dkey} : (isset($settings[$dkey]) ? $settings[$dkey] : NULL);
             $element[$dkey] = array('#type' => 'value', '#value' => is_null($ddval) ? NULL : (string) $ddval);
         }
     }
     $title = isset($item->title) ? $item->title : (!empty($settings['title']) ? $settings['title'] : '');
     $element['title'] = array('#type' => 'textfield', '#title' => t('IFrame Title'), '#placeholder' => '', '#default_value' => $title, '#size' => 80, '#maxlength' => 1024, '#weight' => 2);
     $url = isset($item->url) && !empty($item->url) ? $item->url : (!empty($settings['url']) ? $settings['url'] : '');
     $element['url'] = array('#type' => 'textfield', '#title' => t('IFrame URL'), '#placeholder' => 'http://', '#default_value' => $url, '#size' => 80, '#maxlength' => 1024, '#weight' => 1);
     $width = isset($item->width) && !empty($item->width) ? $item->width : (isset($settings['width']) ? $settings['width'] : NULL);
     $element['width'] = array('#title' => t('width of an iframe'), '#type' => 'textfield', '#default_value' => $width, '#description' => t('iframes need fix width and height, only numbers are allowed.'), '#maxlength' => 4, '#size' => 4, '#weight' => 3, '#required' => TRUE);
     $height = isset($item->height) && !empty($item->height) ? $item->height : (isset($settings['height']) ? $settings['height'] : NULL);
     $element['height'] = array('#type' => 'textfield', '#title' => t('height of an iframe'), '#default_value' => $height, '#description' => t('iframes need fix width and height, only numbers are allowed.'), '#maxlength' => 4, '#size' => 4, '#weight' => 4, '#required' => TRUE);
     if ($settings['expose_class']) {
         $element['class'] = array('#type' => 'textfield', '#title' => t('Additional CSS Class'), '#default_value' => isset($item->class) ? $item->class : NULL, '#description' => t('When output, this iframe will have this class attribute. Multiple classes should be separated by spaces.'), '#weight' => 5);
     }
     #$element['#title'] = 'IIfframe';
     return $element;
 }
开发者ID:justincletus,项目名称:webdrupalpro,代码行数:34,代码来源:IframeWidgetBase.php


示例12: generateFieldMetadata

 /**
  * {@inheritdoc}
  */
 public function generateFieldMetadata(FieldItemListInterface $items, $view_mode)
 {
     $entity = $items->getEntity();
     $field_name = $items->getFieldDefinition()->getName();
     // Early-return if user does not have access.
     $access = $this->accessChecker->accessEditEntityField($entity, $field_name);
     if (!$access) {
         return array('access' => FALSE);
     }
     // Early-return if no editor is available.
     $formatter_id = EntityViewDisplay::collectRenderDisplay($entity, $view_mode)->getRenderer($field_name)->getPluginId();
     $editor_id = $this->editorSelector->getEditor($formatter_id, $items);
     if (!isset($editor_id)) {
         return array('access' => FALSE);
     }
     // Gather metadata, allow the editor to add additional metadata of its own.
     $label = $items->getFieldDefinition()->getLabel();
     $editor = $this->editorManager->createInstance($editor_id);
     $metadata = array('label' => String::checkPlain($label), 'access' => TRUE, 'editor' => $editor_id, 'aria' => t('Entity @type @id, field @field', array('@type' => $entity->getEntityTypeId(), '@id' => $entity->id(), '@field' => $label)));
     $custom_metadata = $editor->getMetadata($items);
     if (count($custom_metadata)) {
         $metadata['custom'] = $custom_metadata;
     }
     return $metadata;
 }
开发者ID:davidsoloman,项目名称:drupalconsole.com,代码行数:28,代码来源:MetadataGenerator.php


示例13: viewElements

 /**
  * {@inheritdoc}
  */
 public function viewElements(FieldItemListInterface $items, $langcode)
 {
     $element = [];
     if ($items->status == 1 && $this->currentUser->hasPermission('view disqus comments')) {
         $element[] = ['#type' => 'disqus', '#url' => $items->getEntity()->toUrl('canonical', ['absolute' => TRUE])->toString(), '#title' => (string) $items->getEntity()->label(), '#identifier' => $items->identifier ?: "{$items->getEntity()->getEntityTypeId()}/{$items->getEntity()->id()}"];
     }
     return $element;
 }
开发者ID:MGApcDev,项目名称:MGApcDevCom,代码行数:11,代码来源:DisqusFormatter.php


示例14: generateIds

 /**
  * Generates unique ids for the field items.
  *
  * @param \Drupal\Core\Field\FieldItemListInterface $items
  *  The field items.
  * @return array
  *  Array of ids keyed by field item delta.
  */
 protected function generateIds(FieldItemListInterface $items)
 {
     $entity = $items->getEntity();
     $ids = array();
     foreach ($items as $delta => $item) {
         $ids[$delta] = implode('_', array($entity->getEntityTypeId(), $entity->bundle(), $entity->id(), $items->getFieldDefinition()->getName(), $delta));
     }
     return $ids;
 }
开发者ID:blakefrederick,项目名称:sas-backend,代码行数:17,代码来源:FieldTimerJsFormatterBase.php


示例15: viewElements

 /**
  * {@inheritdoc}
  */
 public function viewElements(FieldItemListInterface $items)
 {
     $elements = array();
     $entity = $items->getEntity();
     foreach ($items as $item) {
         $entity->rss_elements[] = array('key' => 'category', 'value' => $item->entity->label(), 'attributes' => array('domain' => $item->target_id ? url('taxonomy/term/' . $item->target_id, array('absolute' => TRUE)) : ''));
     }
     return $elements;
 }
开发者ID:anatalsceo,项目名称:en-classe,代码行数:12,代码来源:EntityReferenceTaxonomyTermRssFormatter.php


示例16: viewElements

 /**
  * {@inheritdoc}
  */
 public function viewElements(FieldItemListInterface $items)
 {
     $entity = $items->getEntity();
     // Add the first file as an enclosure to the RSS item. RSS allows only one
     // enclosure per item. See: http://en.wikipedia.org/wiki/RSS_enclosure
     foreach ($this->getEntitiesToView($items) as $delta => $file) {
         $entity->rss_elements[] = array('key' => 'enclosure', 'attributes' => array('url' => file_create_url($file->getFileUri()), 'length' => $file->getSize(), 'type' => $file->getMimeType()));
     }
 }
开发者ID:Nikola-xiii,项目名称:d8intranet,代码行数:12,代码来源:RSSEnclosureFormatter.php


示例17: viewElements

 /**
  * {@inheritdoc}
  */
 public function viewElements(FieldItemListInterface $items, $langcode)
 {
     $parent_entity = $items->getEntity();
     $elements = array();
     foreach ($this->getEntitiesToView($items, $langcode) as $delta => $entity) {
         $parent_entity->rss_elements[] = array('key' => 'category', 'value' => $entity->label(), 'attributes' => array('domain' => $entity->id() ? \Drupal::url('entity.taxonomy_term.canonical', ['taxonomy_term' => $entity->id()], array('absolute' => TRUE)) : ''));
     }
     return $elements;
 }
开发者ID:ddrozdik,项目名称:dmaps,代码行数:12,代码来源:EntityReferenceTaxonomyTermRssFormatter.php


示例18: 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


示例19: viewElements

 /**
  * {@inheritdoc}
  */
 public function viewElements(FieldItemListInterface $items, $langcode)
 {
     $element = array();
     $settings = $this->getSettings();
     foreach ($items as $delta => $item) {
         $element[$delta] = array('#theme' => 'youtube_video', '#video_id' => $item->video_id, '#entity_title' => $items->getEntity()->label(), '#settings' => $settings);
     }
     return $element;
 }
开发者ID:neeravbm,项目名称:unify-d8,代码行数:12,代码来源:YouTubeFormatter.php


示例20: formElement

 /**
  * {@inheritdoc}
  */
 public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state)
 {
     /** @var \Drupal\plugin\Plugin\Field\FieldType\PluginCollectionItemInterface $item */
     $item = $items[$delta];
     /** @var \Drupal\plugin\PluginType\PluginTypeInterface $plugin_type */
     $plugin_type = $item->getPluginType();
     $element = ['#delta' => $delta, '#field_definition' => $this->fieldDefinition, '#element_validate' => [[get_class(), 'validateFormElement']], '#plugin_type_id' => $plugin_type->getId(), '#plugin_selector_id' => $this->pluginDefinition['plugin_selector_id'], '#process' => [[get_class(), 'processFormElement']], '#selected_plugin' => $items->isEmpty() ? NULL : $items->get($delta)->getContainedPluginInstance()];
     $element['plugin_selector'] = static::getPluginSelector($form_state, $element)->buildSelectorForm([], $form_state);
     return $element;
 }
开发者ID:nishantkumar155,项目名称:drupal8.crackle,代码行数:13,代码来源:PluginSelector.php



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP Field\FieldStorageDefinitionInterface类代码示例发布时间:2022-05-23
下一篇:
PHP Field\FieldItemBase类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap