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


PHP FieldItemListInterface::getFieldDefinition方法代码示例

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


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

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

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

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

示例4: formElement

 /**
  * {@inheritdoc}
  */
 public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state)
 {
     $main_widget = $element + array('#type' => 'textfield', '#default_value' => isset($items[$delta]->value) ? $items[$delta]->value : NULL, '#placeholder' => $this->getSetting('placeholder'), '#attributes' => array('class' => array('geocoder-source')));
     $element['value'] = $main_widget;
     $source_field_id = 'edit-' . str_replace('_', '-', $items->getFieldDefinition()->getName()) . '-' . $delta . '-value';
     $destination_field_id = 'edit-' . str_replace('_', '-', $this->getSetting('destination_field')) . '-wrapper';
     $google_api_key = \Drupal::config('geocoder.google')->get('api_key');
     $element['#attached'] = array('library' => array(array('system', 'jquery.ui.autocomplete')), 'js' => array('sites/all/libraries/geocoder-js/dist/geocoder.js', drupal_get_path('module', 'geocoder') . '/js/geocoderWidget.js', array('data' => array('geocoder' => array('engine' => 'google', 'api_key' => $google_api_key, 'fields' => array(array('sourceField' => $source_field_id, 'destinationField' => $destination_field_id, 'sourceType' => 'geofield')))), 'type' => 'setting')));
     return $element;
 }
开发者ID:seongbae,项目名称:drumo-distribution,代码行数:13,代码来源:GeocoderWidget.php

示例5: isCompatible

 /**
  * {@inheritdoc}
  */
 public function isCompatible(FieldItemListInterface $items)
 {
     $field_definition = $items->getFieldDefinition();
     // This editor is incompatible with multivalued fields.
     if ($field_definition->getFieldStorageDefinition()->getCardinality() != 1) {
         return FALSE;
     } elseif (in_array($field_definition->getType(), array('text', 'text_long', 'text_with_summary'), TRUE)) {
         return FALSE;
     } else {
         return TRUE;
     }
 }
开发者ID:318io,项目名称:318-io,代码行数:15,代码来源:PlainTextEditor.php

示例6: isCompatible

 /**
  * {@inheritdoc}
  *
  * @todo The processed text logic is too coupled to text fields. Figure out
  *   how to generalize to other textual field types.
  */
 public function isCompatible(FieldItemListInterface $items)
 {
     $field_definition = $items->getFieldDefinition();
     // This editor is incompatible with multivalued fields.
     if ($field_definition->getFieldStorageDefinition()->getCardinality() != 1) {
         return FALSE;
     } elseif ($field_definition->getSetting('text_processing')) {
         return FALSE;
     } else {
         return TRUE;
     }
 }
开发者ID:anatalsceo,项目名称:en-classe,代码行数:18,代码来源:PlainTextEditor.php

示例7: isCompatible

 /**
  * {@inheritdoc}
  */
 public function isCompatible(FieldItemListInterface $items)
 {
     $field_definition = $items->getFieldDefinition();
     // This editor is incompatible with multivalued fields.
     if ($field_definition->getFieldStorageDefinition()->getCardinality() != 1) {
         return FALSE;
     }
     // This editor is compatible with formatted ("rich") text fields; but only
     // if there is a currently active text format and that text format is the
     // 'full_html' text format.
     return $items[0]->format === 'full_html';
 }
开发者ID:eigentor,项目名称:tommiblog,代码行数:15,代码来源:WysiwygEditor.php

示例8: viewElements

 /**
  * {@inheritdoc}
  */
 public function viewElements(FieldItemListInterface $items, $langcode)
 {
     $element = [];
     // As the Field API only applies the "field default value" to newly created
     // entities, we'll apply the default value for existing entities.
     if ($items->count() == 0) {
         $field_default_value = $items->getFieldDefinition()->getDefaultValue($items->getEntity());
         $items->status = $field_default_value[0]['status'];
     }
     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:nB-MDSO,项目名称:mdso-d8blog,代码行数:17,代码来源:DisqusFormatter.php

示例9: isCompatible

 /**
  * {@inheritdoc}
  */
 public function isCompatible(FieldItemListInterface $items)
 {
     $field_definition = $items->getFieldDefinition();
     // This editor is incompatible with multivalued fields.
     if ($field_definition->getFieldStorageDefinition()->getCardinality() != 1) {
         return FALSE;
     } elseif ($editor = editor_load($items[0]->format)) {
         $definition = \Drupal::service('plugin.manager.editor')->getDefinition($editor->getEditor());
         if ($definition['supports_inline_editing'] === TRUE) {
             return TRUE;
         }
     }
     return FALSE;
 }
开发者ID:eigentor,项目名称:tommiblog,代码行数:17,代码来源:Editor.php

示例10: viewElements

 /**
  * {@inheritdoc}
  */
 public function viewElements(FieldItemListInterface $items, $langcode)
 {
     $elements = array();
     // Only collect allowed options if there are actually items to display.
     if ($items->count()) {
         $provider = $items->getFieldDefinition()->getFieldStorageDefinition()->getOptionsProvider('value', $items->getEntity());
         // Flatten the possible options, to support opt groups.
         $options = OptGroup::flattenOptions($provider->getPossibleOptions());
         foreach ($items as $delta => $item) {
             $value = $item->value;
             // If the stored value is in the current set of allowed values, display
             // the associated label, otherwise just display the raw value.
             $output = isset($options[$value]) ? $options[$value] : $value;
             $elements[$delta] = array('#markup' => $output, '#allowed_tags' => FieldFilteredMarkup::allowedTags());
         }
     }
     return $elements;
 }
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:21,代码来源:OptionsDefaultFormatter.php

示例11: formElement

 /**
  * {@inheritdoc}
  */
 public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state)
 {
     // Get easychart entity field values.
     $field_name = $items->getFieldDefinition()->getName();
     $entity = $items->getEntity();
     $values = $entity->get($field_name)->getValue();
     $config = \Drupal::config('easychart.settings');
     $settings = ['easychartOptions' => $config->get('options'), 'easychartTemplates' => $config->get('templates'), 'easychartPresets' => $config->get('presets')];
     // Attach settings and libraries to render array.
     $element['#attached']['drupalSettings']['easychart'] = $settings;
     $element['#attached']['library'][] = 'easychart/easychart.widget';
     $element['#attached']['library'][] = 'easychart/lib.highcharts';
     $element['#attached']['library'][] = 'easychart/lib.easycharts.full';
     $element['container'] = array('#prefix' => '<div class="easychart-wrapper clearfix entity-meta">', '#suffix' => '</div>', '#type' => 'container', '#attributes' => array('class' => array('entity-meta__header clearfix'), 'style' => array('padding:0;')));
     $element['container']['config'] = array('#description' => $this->t('The configuration options as described at http://api.highcharts.com/highcharts'), '#type' => 'hidden', '#default_value' => isset($values[$delta]['config']) ? $values[$delta]['config'] : NULL, '#attributes' => array('class' => array('easychart-config')));
     $element['container']['csv'] = array('#type' => 'hidden', '#description' => $this->t('Your chart data in CSV format'), '#default_value' => isset($values[$delta]['csv']) ? $values[$delta]['csv'] : NULL, '#attributes' => array('class' => array('easychart-csv')), '#element_validate' => array(array(get_called_class(), 'validateCSVElement')), '#csv_required' => $element['#required']);
     $element['container']['csv_url'] = array('#type' => 'hidden', '#description' => $this->t('The URL to a CSV file'), '#default_value' => isset($values[$delta]['csv_url']) ? $values[$delta]['csv_url'] : NULL, '#attributes' => array('class' => array('easychart-csv-url')));
     $element['container']['preview'] = array('#title' => $this->t('Easychart'), '#markup' => '', '#prefix' => '<div class="easychart-embed">', '#suffix' => '</div>');
     return $element;
 }
开发者ID:justincletus,项目名称:webdrupalpro,代码行数:23,代码来源:EasychartWidget.php

示例12: viewElements

 /**
  * {@inheritdoc}
  */
 public function viewElements(FieldItemListInterface $items, $langcode)
 {
     $element = array();
     // If there are no images, don't do anything else.
     if ($items->isEmpty()) {
         return array();
     }
     $entity = $items->getEntity();
     $field_instance = $items->getFieldDefinition();
     $entity_type_id = $entity->getEntityTypeId();
     $entity_id = $entity->id();
     $field_name = $field_instance->getName();
     $display_name = $this->viewMode;
     $add_js = TRUE;
     // Check for incompatible view modes - see issue #2217791
     if ($display_name == 'search_result' || $display_name == 'search_index') {
         $add_js = FALSE;
     }
     // The gallery shown in preview view will only display field data from the
     // previously saved version (that is the only version the XML generation
     // methods will have access to). Display a warning because of this.
     if (!empty($entity->in_preview)) {
         drupal_set_message(t('Juicebox galleries may not display correctly in preview mode. Any edits made to gallery data will only be visible after all changes are saved.'), 'warning', FALSE);
     }
     // Generate xml details.
     $xml_route_info = array('route_name' => 'juicebox.xml_field', 'route_parameters' => array('entityType' => $entity_type_id, 'entityId' => $entity_id, 'fieldName' => $field_name, 'displayName' => $display_name), 'options' => array('query' => $this->request->query->all()));
     // Try building the gallery and its XML.
     try {
         // Initialize the gallery.
         $gallery = $this->juicebox->newGallery($xml_route_info['route_parameters']);
         // Build the gallery.
         $this->buildGallery($gallery, $items);
         // Build field-specific contextual links.
         $contextual = $this->buildContextualLinks($xml_route_info, $entity_type_id);
         // Create a render array with the gallery markup.
         $element[0] = $this->juicebox->buildEmbed($gallery, $this->getSettings(), $xml_route_info, $add_js, $this->isPseudoInstance(), $contextual);
     } catch (\Exception $e) {
         $message = 'Exception building Juicebox embed code for field: !message in %function (line %line of %file).';
         watchdog_exception('juicebox', $e, $message);
     }
     return $element;
 }
开发者ID:rafavergara,项目名称:ddv8,代码行数:45,代码来源:JuiceboxFieldFormatter.php

示例13: viewField

 /**
  * {@inheritdoc}
  */
 public function viewField(FieldItemListInterface $items, $display_options = array())
 {
     $entity = $items->getEntity();
     $field_name = $items->getFieldDefinition()->getName();
     $display = $this->getSingleFieldDisplay($entity, $field_name, $display_options);
     $output = array();
     $build = $display->build($entity);
     if (isset($build[$field_name])) {
         $output = $build[$field_name];
     }
     return $output;
 }
开发者ID:brstde,项目名称:gap1,代码行数:15,代码来源:EntityViewBuilder.php

示例14: viewField

 /**
  * {@inheritdoc}
  */
 public function viewField(FieldItemListInterface $items, $display_options = array())
 {
     $output = array();
     $entity = $items->getEntity();
     $field_name = $items->getFieldDefinition()->getName();
     // Get the display object.
     if (is_string($display_options)) {
         $view_mode = $display_options;
         $display = EntityViewDisplay::collectRenderDisplay($entity, $view_mode);
         foreach ($entity as $name => $items) {
             if ($name != $field_name) {
                 $display->removeComponent($name);
             }
         }
     } else {
         $view_mode = '_custom';
         $display = entity_create('entity_view_display', array('targetEntityType' => $entity->getEntityTypeId(), 'bundle' => $entity->bundle(), 'mode' => $view_mode, 'status' => TRUE));
         $display->setComponent($field_name, $display_options);
     }
     $build = $display->build($entity);
     if (isset($build[$field_name])) {
         $output = $build[$field_name];
     }
     return $output;
 }
开发者ID:alnutile,项目名称:drunatra,代码行数:28,代码来源:EntityViewBuilder.php

示例15: viewElements

 /**
  * {@inheritdoc}
  */
 public function viewElements(FieldItemListInterface $items, $langcode)
 {
     $elements = array();
     $entity = $items->getEntity();
     $field_instance = $items->getFieldDefinition();
     $entity_type_id = $entity->getEntityTypeId();
     $entity_id = $entity->id();
     $field_name = $field_instance->getName();
     $display_name = $this->viewMode;
     $files = $this->getEntitiesToView($items, $langcode);
     $settings = $this->getSettings();
     // Early opt-out if the field is empty.
     if (empty($files)) {
         return $elements;
     }
     $url = NULL;
     $image_link_setting = $this->getSetting('image_link');
     // Check if the formatter involves a link.
     if ($image_link_setting == 'content') {
         $entity = $items->getEntity();
         if (!$entity->isNew()) {
             $url = $entity->urlInfo();
         }
     } elseif ($image_link_setting == 'file') {
         $link_file = TRUE;
     }
     $image_style_setting = $this->getSetting('image_style');
     // Collect cache tags to be added for each item in the field.
     $cache_tags = array();
     if (!empty($image_style_setting)) {
         $image_style = $this->imageStyleStorage->load($image_style_setting);
         $cache_tags = $image_style->getCacheTags();
     }
     foreach ($files as $delta => $file) {
         if (isset($link_file)) {
             $image_uri = $file->getFileUri();
             $url = Url::fromUri(file_create_url($image_uri));
         }
         $cache_tags = Cache::mergeTags($cache_tags, $file->getCacheTags());
         // Extract field item attributes for the theme function, and unset them
         // from the $item so that the field template does not re-render them.
         $item = $file->_referringItem;
         $item_attributes = $item->_attributes;
         unset($item->_attributes);
         $elements[$delta] = array('#theme' => 'image_jssor_formatter', '#item' => $item, '#item_attributes' => $item_attributes, '#image_style' => $image_style_setting, '#caption' => $this->getSetting('caption'), '#url' => $url, '#settings' => $settings, '#cache' => array('tags' => $cache_tags));
     }
     $container = array('#theme' => 'images_jssor_formatter', '#children' => $elements, '#settings' => $settings, '#attributes' => array('class' => array('slider'), 'id' => array('slider-dom-id-1')));
     // Attach library.
     $container['#attached']['library'][] = 'jssor/jquery.jssor.slider';
     $settings = [];
     // ID.
     // @todo generate random ?
     $settings['view_dom_id'] = '1';
     // Global settings.
     $settings['$ArrowKeyNavigation'] = TRUE;
     // Arrow navigator.
     if ($this->getSetting('arrownavigator')) {
         $settings['$ArrowNavigatorOptions'] = array('$Class' => '$JssorArrowNavigator$', '$ChanceToShow' => 1, '$AutoCenter' => 2, '$Scale' => TRUE);
     }
     // Bullet navigator.
     if ($this->getSetting('bulletnavigator')) {
         $settings['$BulletNavigatorOptions'] = array('$Class' => '$JssorBulletNavigator$', '$ChanceToShow' => 2, '$AutoCenter' => 1, '$Scale' => TRUE);
     }
     // Attach settings.
     $container['#attached']['drupalSettings']['views']['jssorViews'][] = $settings;
     return $container;
 }
开发者ID:rafavergara,项目名称:ddv8,代码行数:70,代码来源:JssorFieldFormatter.php


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