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


PHP FieldDefinitionInterface::getLabel方法代码示例

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


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

示例3: formMultipleElements

 /**
  * Special handling to create form elements for multiple values.
  *
  * Handles generic features for multiple fields:
  * - number of widgets
  * - AHAH-'add more' button
  * - table display and drag-n-drop value reordering
  */
 protected function formMultipleElements(FieldItemListInterface $items, array &$form, FormStateInterface $form_state)
 {
     $field_name = $this->fieldDefinition->getName();
     $cardinality = $this->fieldDefinition->getFieldStorageDefinition()->getCardinality();
     $parents = $form['#parents'];
     // Determine the number of widgets to display.
     switch ($cardinality) {
         case FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED:
             $field_state = static::getWidgetState($parents, $field_name, $form_state);
             $max = $field_state['items_count'];
             $is_multiple = TRUE;
             break;
         default:
             $max = $cardinality - 1;
             $is_multiple = $cardinality > 1;
             break;
     }
     $title = $this->fieldDefinition->getLabel();
     $description = FieldFilteredMarkup::create(\Drupal::token()->replace($this->fieldDefinition->getDescription()));
     $elements = array();
     for ($delta = 0; $delta <= $max; $delta++) {
         // Add a new empty item if it doesn't exist yet at this delta.
         if (!isset($items[$delta])) {
             $items->appendItem();
         }
         // For multiple fields, title and description are handled by the wrapping
         // table.
         if ($is_multiple) {
             $element = ['#title' => $this->t('@title (value @number)', ['@title' => $title, '@number' => $delta + 1]), '#title_display' => 'invisible', '#description' => ''];
         } else {
             $element = ['#title' => $title, '#title_display' => 'before', '#description' => $description];
         }
         $element = $this->formSingleElement($items, $delta, $element, $form, $form_state);
         if ($element) {
             // Input field for the delta (drag-n-drop reordering).
             if ($is_multiple) {
                 // We name the element '_weight' to avoid clashing with elements
                 // defined by widget.
                 $element['_weight'] = array('#type' => 'weight', '#title' => $this->t('Weight for row @number', array('@number' => $delta + 1)), '#title_display' => 'invisible', '#delta' => $max, '#default_value' => $items[$delta]->_weight ?: $delta, '#weight' => 100);
             }
             $elements[$delta] = $element;
         }
     }
     if ($elements) {
         $elements += array('#theme' => 'field_multiple_value_form', '#field_name' => $field_name, '#cardinality' => $cardinality, '#cardinality_multiple' => $this->fieldDefinition->getFieldStorageDefinition()->isMultiple(), '#required' => $this->fieldDefinition->isRequired(), '#title' => $title, '#description' => $description, '#max_delta' => $max);
         // Add 'add more' button, if not working with a programmed form.
         if ($cardinality == FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED && !$form_state->isProgrammed()) {
             $id_prefix = implode('-', array_merge($parents, array($field_name)));
             $wrapper_id = Html::getUniqueId($id_prefix . '-add-more-wrapper');
             $elements['#prefix'] = '<div id="' . $wrapper_id . '">';
             $elements['#suffix'] = '</div>';
             $elements['add_more'] = array('#type' => 'submit', '#name' => strtr($id_prefix, '-', '_') . '_add_more', '#value' => t('Add another item'), '#attributes' => array('class' => array('field-add-more-submit')), '#limit_validation_errors' => array(array_merge($parents, array($field_name))), '#submit' => array(array(get_class($this), 'addMoreSubmit')), '#ajax' => array('callback' => array(get_class($this), 'addMoreAjax'), 'wrapper' => $wrapper_id, 'effect' => 'fade'));
         }
     }
     return $elements;
 }
开发者ID:ddrozdik,项目名称:dmaps,代码行数:64,代码来源:WidgetBase.php

示例4: initializeView

 /**
  * Initializes a view.
  *
  * @param string|null $match
  *   (Optional) Text to match the label against. Defaults to NULL.
  * @param string $match_operator
  *   (Optional) The operation the matching should be done with. Defaults
  *   to "CONTAINS".
  * @param int $limit
  *   Limit the query to a given number of items. Defaults to 0, which
  *   indicates no limiting.
  * @param array|null $ids
  *   Array of entity IDs. Defaults to NULL.
  *
  * @return bool
  *   Return TRUE if the view was initialized, FALSE otherwise.
  */
 protected function initializeView($match = NULL, $match_operator = 'CONTAINS', $limit = 0, $ids = NULL)
 {
     $handler_settings = $this->fieldDefinition->getSetting('handler_settings');
     $view_name = $handler_settings['view']['view_name'];
     $display_name = $handler_settings['view']['display_name'];
     // Check that the view is valid and the display still exists.
     $this->view = Views::getView($view_name);
     if (!$this->view || !$this->view->access($display_name)) {
         drupal_set_message(t('The reference view %view_name used in the %field_name field cannot be found.', array('%view_name' => $view_name, '%field_name' => $this->fieldDefinition->getLabel())), 'warning');
         return FALSE;
     }
     $this->view->setDisplay($display_name);
     // Pass options to the display handler to make them available later.
     $entity_reference_options = array('match' => $match, 'match_operator' => $match_operator, 'limit' => $limit, 'ids' => $ids);
     $this->view->displayHandlers->get($display_name)->setOption('entity_reference_options', $entity_reference_options);
     return TRUE;
 }
开发者ID:alnutile,项目名称:drunatra,代码行数:34,代码来源:ViewsSelection.php

示例5: getLabel

 /**
  * {@inheritdoc}
  */
 public function getLabel()
 {
     return $this->fieldDefinition->getLabel();
 }
开发者ID:Tawreh,项目名称:mtg,代码行数:7,代码来源:FieldTargetDefinition.php

示例6: buildFieldRow

 /**
  * Builds the table row structure for a single field.
  *
  * @param \Drupal\Core\Field\FieldDefinitionInterface $field_definition
  *   The field definition.
  * @param array $form
  *   An associative array containing the structure of the form.
  * @param \Drupal\Core\Form\FormStateInterface $form_state
  *   The current state of the form.
  *
  * @return array
  *   A table row array.
  */
 protected function buildFieldRow(FieldDefinitionInterface $field_definition, array $form, FormStateInterface $form_state)
 {
     $field_name = $field_definition->getName();
     $display_options = $this->entity->getComponent($field_name);
     $label = $field_definition->getLabel();
     // Disable fields without any applicable plugins.
     if (empty($this->getApplicablePluginOptions($field_definition))) {
         $this->entity->removeComponent($field_name)->save();
         $display_options = $this->entity->getComponent($field_name);
     }
     $regions = array_keys($this->getRegions());
     $field_row = array('#attributes' => array('class' => array('draggable', 'tabledrag-leaf')), '#row_type' => 'field', '#region_callback' => array($this, 'getRowRegion'), '#js_settings' => array('rowHandler' => 'field', 'defaultPlugin' => $this->getDefaultPlugin($field_definition->getType())), 'human_name' => array('#plain_text' => $label), 'weight' => array('#type' => 'textfield', '#title' => $this->t('Weight for @title', array('@title' => $label)), '#title_display' => 'invisible', '#default_value' => $display_options ? $display_options['weight'] : '0', '#size' => 3, '#attributes' => array('class' => array('field-weight'))), 'parent_wrapper' => array('parent' => array('#type' => 'select', '#title' => $this->t('Label display for @title', array('@title' => $label)), '#title_display' => 'invisible', '#options' => array_combine($regions, $regions), '#empty_value' => '', '#attributes' => array('class' => array('js-field-parent', 'field-parent')), '#parents' => array('fields', $field_name, 'parent')), 'hidden_name' => array('#type' => 'hidden', '#default_value' => $field_name, '#attributes' => array('class' => array('field-name')))));
     $field_row['plugin'] = array('type' => array('#type' => 'select', '#title' => $this->t('Plugin for @title', array('@title' => $label)), '#title_display' => 'invisible', '#options' => $this->getPluginOptions($field_definition), '#default_value' => $display_options ? $display_options['type'] : 'hidden', '#parents' => array('fields', $field_name, 'type'), '#attributes' => array('class' => array('field-plugin-type'))), 'settings_edit_form' => array());
     // Get the corresponding plugin object.
     $plugin = $this->entity->getRenderer($field_name);
     // Base button element for the various plugin settings actions.
     $base_button = array('#submit' => array('::multistepSubmit'), '#ajax' => array('callback' => '::multistepAjax', 'wrapper' => 'field-display-overview-wrapper', 'effect' => 'fade'), '#field_name' => $field_name);
     if ($form_state->get('plugin_settings_edit') == $field_name) {
         // We are currently editing this field's plugin settings. Display the
         // settings form and submit buttons.
         $field_row['plugin']['settings_edit_form'] = array();
         if ($plugin) {
             // Generate the settings form and allow other modules to alter it.
             $settings_form = $plugin->settingsForm($form, $form_state);
             $third_party_settings_form = $this->thirdPartySettingsForm($plugin, $field_definition, $form, $form_state);
             if ($settings_form || $third_party_settings_form) {
                 $field_row['plugin']['#cell_attributes'] = array('colspan' => 3);
                 $field_row['plugin']['settings_edit_form'] = array('#type' => 'container', '#attributes' => array('class' => array('field-plugin-settings-edit-form')), '#parents' => array('fields', $field_name, 'settings_edit_form'), 'label' => array('#markup' => $this->t('Plugin settings')), 'settings' => $settings_form, 'third_party_settings' => $third_party_settings_form, 'actions' => array('#type' => 'actions', 'save_settings' => $base_button + array('#type' => 'submit', '#button_type' => 'primary', '#name' => $field_name . '_plugin_settings_update', '#value' => $this->t('Update'), '#op' => 'update'), 'cancel_settings' => $base_button + array('#type' => 'submit', '#name' => $field_name . '_plugin_settings_cancel', '#value' => $this->t('Cancel'), '#op' => 'cancel', '#limit_validation_errors' => array(array('fields', $field_name, 'type')))));
                 $field_row['#attributes']['class'][] = 'field-plugin-settings-editing';
             }
         }
     } else {
         $field_row['settings_summary'] = array();
         $field_row['settings_edit'] = array();
         if ($plugin) {
             // Display a summary of the current plugin settings, and (if the
             // summary is not empty) a button to edit them.
             $summary = $plugin->settingsSummary();
             // Allow other modules to alter the summary.
             $this->alterSettingsSummary($summary, $plugin, $field_definition);
             if (!empty($summary)) {
                 $field_row['settings_summary'] = array('#type' => 'inline_template', '#template' => '<div class="field-plugin-summary">{{ summary|safe_join("<br />") }}</div>', '#context' => array('summary' => $summary), '#cell_attributes' => array('class' => array('field-plugin-summary-cell')));
             }
             // Check selected plugin settings to display edit link or not.
             $settings_form = $plugin->settingsForm($form, $form_state);
             $third_party_settings_form = $this->thirdPartySettingsForm($plugin, $field_definition, $form, $form_state);
             if (!empty($settings_form) || !empty($third_party_settings_form)) {
                 $field_row['settings_edit'] = $base_button + array('#type' => 'image_button', '#name' => $field_name . '_settings_edit', '#src' => 'core/misc/icons/787878/cog.svg', '#attributes' => array('class' => array('field-plugin-settings-edit'), 'alt' => $this->t('Edit')), '#op' => 'edit', '#limit_validation_errors' => array(array('fields', $field_name, 'type')), '#prefix' => '<div class="field-plugin-settings-edit-wrapper">', '#suffix' => '</div>');
             }
         }
     }
     return $field_row;
 }
开发者ID:Greg-Boggs,项目名称:electric-dev,代码行数:66,代码来源:EntityDisplayFormBase.php

示例7: mapSingleFieldViewsData

 /**
  * Provides the views data for a given data type and schema field.
  *
  * @param string $table
  *   The table of the field to handle.
  * @param string $field_name
  *   The machine name of the field being processed.
  * @param string $field_type
  *   The type of field being handled.
  * @param string $column_name
  *   For fields containing multiple columns, the column name being processed.
  * @param string $column_type
  *   Within the field, the column type being handled.
  * @param bool $first
  *   TRUE if this is the first column within the field.
  * @param \Drupal\Core\Field\FieldDefinitionInterface $field_definition
  *   The field definition.
  *
  * @return array
  *   The modified views data field definition.
  */
 protected function mapSingleFieldViewsData($table, $field_name, $field_type, $column_name, $column_type, $first, FieldDefinitionInterface $field_definition)
 {
     $views_field = array();
     // Provide a nicer, less verbose label for the first column within a field.
     // @todo Introduce concept of the "main" column for a field, rather than
     //   assuming the first one is the main column.
     if ($first) {
         $views_field['title'] = $field_definition->getLabel();
     } else {
         $views_field['title'] = $field_definition->getLabel() . " ({$column_name})";
     }
     if ($description = $field_definition->getDescription()) {
         $views_field['help'] = $description;
     }
     // Set up the field, sort, argument, and filters, based on
     // the column and/or field data type.
     // @todo Allow field types to customize this.
     // @see https://www.drupal.org/node/2337515
     switch ($field_type) {
         // Special case a few field types.
         case 'timestamp':
         case 'created':
         case 'changed':
             $views_field['field']['id'] = 'date';
             $views_field['argument']['id'] = 'date';
             $views_field['filter']['id'] = 'date';
             $views_field['sort']['id'] = 'date';
             break;
         case 'language':
             $views_field['field']['id'] = 'field';
             $views_field['argument']['id'] = 'language';
             $views_field['filter']['id'] = 'language';
             $views_field['sort']['id'] = 'standard';
             break;
         case 'boolean':
             $views_field['field']['id'] = 'field';
             $views_field['argument']['id'] = 'numeric';
             $views_field['filter']['id'] = 'boolean';
             $views_field['sort']['id'] = 'standard';
             break;
         case 'uri':
             // Let's render URIs as URIs by default, not links.
             $views_field['field']['id'] = 'field';
             $views_field['field']['default_formatter'] = 'string';
             $views_field['argument']['id'] = 'string';
             $views_field['filter']['id'] = 'string';
             $views_field['sort']['id'] = 'standard';
             break;
         case 'text':
         case 'text_with_summary':
             // Treat these three long text fields the same.
             $field_type = 'text_long';
             // Intentional fall-through here to the default processing!
         // Intentional fall-through here to the default processing!
         default:
             // For most fields, the field type is generic enough to just use
             // the column type to determine the filters etc.
             switch ($column_type) {
                 case 'int':
                 case 'integer':
                 case 'smallint':
                 case 'tinyint':
                 case 'mediumint':
                 case 'float':
                 case 'double':
                 case 'decimal':
                     $views_field['field']['id'] = 'field';
                     $views_field['argument']['id'] = 'numeric';
                     $views_field['filter']['id'] = 'numeric';
                     $views_field['sort']['id'] = 'standard';
                     break;
                 case 'char':
                 case 'string':
                 case 'varchar':
                 case 'tinytext':
                 case 'text':
                 case 'mediumtext':
                 case 'longtext':
                     $views_field['field']['id'] = 'field';
//.........这里部分代码省略.........
开发者ID:brstde,项目名称:gap1,代码行数:101,代码来源:EntityViewsData.php

示例8: settingsForm

 /**
  * {@inheritdoc}
  */
 public static function settingsForm(FieldDefinitionInterface $field_definition)
 {
     $entity_manager = \Drupal::entityManager();
     $entity_type_id = $field_definition->getSetting('target_type');
     $selection_handler_settings = $field_definition->getSetting('handler_settings') ?: array();
     $entity_type = $entity_manager->getDefinition($entity_type_id);
     $bundles = $entity_manager->getBundleInfo($entity_type_id);
     // Merge-in default values.
     $selection_handler_settings += array('target_bundles' => array(), 'sort' => array('field' => '_none'), 'auto_create' => FALSE);
     if ($entity_type->hasKey('bundle')) {
         $bundle_options = array();
         foreach ($bundles as $bundle_name => $bundle_info) {
             $bundle_options[$bundle_name] = $bundle_info['label'];
         }
         $target_bundles_title = t('Bundles');
         // Default core entity types with sensible labels.
         if ($entity_type_id == 'node') {
             $target_bundles_title = t('Content types');
         } elseif ($entity_type_id == 'taxonomy_term') {
             $target_bundles_title = t('Vocabularies');
         }
         $form['target_bundles'] = array('#type' => 'checkboxes', '#title' => $target_bundles_title, '#options' => $bundle_options, '#default_value' => !empty($selection_handler_settings['target_bundles']) ? $selection_handler_settings['target_bundles'] : array(), '#required' => TRUE, '#size' => 6, '#multiple' => TRUE, '#element_validate' => array('_entity_reference_element_validate_filter'));
     } else {
         $form['target_bundles'] = array('#type' => 'value', '#value' => array());
     }
     if ($entity_type->isSubclassOf('\\Drupal\\Core\\Entity\\FieldableEntityInterface')) {
         $fields = array();
         foreach (array_keys($bundles) as $bundle) {
             $bundle_fields = array_filter($entity_manager->getFieldDefinitions($entity_type_id, $bundle), function ($field_definition) {
                 return !$field_definition->isComputed();
             });
             foreach ($bundle_fields as $field_name => $field_definition) {
                 /* @var \Drupal\Core\Field\FieldDefinitionInterface $field_definition */
                 $columns = $field_definition->getFieldStorageDefinition()->getColumns();
                 // If there is more than one column, display them all, otherwise just
                 // display the field label.
                 // @todo: Use property labels instead of the column name.
                 if (count($columns) > 1) {
                     foreach ($columns as $column_name => $column_info) {
                         $fields[$field_name . '.' . $column_name] = t('@label (@column)', array('@label' => $field_definition->getLabel(), '@column' => $column_name));
                     }
                 } else {
                     $fields[$field_name] = t('@label', array('@label' => $field_definition->getLabel()));
                 }
             }
         }
         $form['sort']['field'] = array('#type' => 'select', '#title' => t('Sort by'), '#options' => array('_none' => t('- None -')) + $fields, '#ajax' => TRUE, '#limit_validation_errors' => array(), '#default_value' => $selection_handler_settings['sort']['field']);
         $form['sort']['settings'] = array('#type' => 'container', '#attributes' => array('class' => array('entity_reference-settings')), '#process' => array('_entity_reference_form_process_merge_parent'));
         if ($selection_handler_settings['sort']['field'] != '_none') {
             // Merge-in default values.
             $selection_handler_settings['sort'] += array('direction' => 'ASC');
             $form['sort']['settings']['direction'] = array('#type' => 'select', '#title' => t('Sort direction'), '#required' => TRUE, '#options' => array('ASC' => t('Ascending'), 'DESC' => t('Descending')), '#default_value' => $selection_handler_settings['sort']['direction']);
         }
     }
     return $form;
 }
开发者ID:davidsoloman,项目名称:drupalconsole.com,代码行数:59,代码来源:SelectionBase.php

示例9: getLabel

 /**
  * {@inheritdoc}
  */
 public function getLabel($property = 'value')
 {
     return $this->field->getLabel();
 }
开发者ID:jasonruyle,项目名称:crm_core,代码行数:7,代码来源:FieldHandlerBase.php

示例10: buildFieldRow

 /**
  * Builds the table row structure for a single field.
  *
  * @param \Drupal\Core\Field\FieldDefinitionInterface $field_definition
  *   The field definition.
  * @param \Drupal\Core\Entity\Display\EntityDisplayInterface $entity_display
  *   The entity display.
  * @param array $form
  *   An associative array containing the structure of the form.
  * @param array $form_state
  *   A reference to a keyed array containing the current state of the form.
  *
  * @return array
  *   A table row array.
  */
 protected function buildFieldRow(FieldDefinitionInterface $field_definition, EntityDisplayInterface $entity_display, array $form, array &$form_state)
 {
     $field_name = $field_definition->getName();
     $display_options = $entity_display->getComponent($field_name);
     $label = $field_definition->getLabel();
     $regions = array_keys($this->getRegions());
     $field_row = array('#attributes' => array('class' => array('draggable', 'tabledrag-leaf')), '#row_type' => 'field', '#region_callback' => array($this, 'getRowRegion'), '#js_settings' => array('rowHandler' => 'field', 'defaultPlugin' => $this->getDefaultPlugin($field_definition->getType())), 'human_name' => array('#markup' => String::checkPlain($label)), 'weight' => array('#type' => 'textfield', '#title' => $this->t('Weight for @title', array('@title' => $label)), '#title_display' => 'invisible', '#default_value' => $display_options ? $display_options['weight'] : '0', '#size' => 3, '#attributes' => array('class' => array('field-weight'))), 'parent_wrapper' => array('parent' => array('#type' => 'select', '#title' => $this->t('Label display for @title', array('@title' => $label)), '#title_display' => 'invisible', '#options' => array_combine($regions, $regions), '#empty_value' => '', '#attributes' => array('class' => array('field-parent')), '#parents' => array('fields', $field_name, 'parent')), 'hidden_name' => array('#type' => 'hidden', '#default_value' => $field_name, '#attributes' => array('class' => array('field-name')))));
     $field_row['plugin'] = array('type' => array('#type' => 'select', '#title' => $this->t('Plugin for @title', array('@title' => $label)), '#title_display' => 'invisible', '#options' => $this->getPluginOptions($field_definition->getType()), '#default_value' => $display_options ? $display_options['type'] : 'hidden', '#parents' => array('fields', $field_name, 'type'), '#attributes' => array('class' => array('field-plugin-type'))), 'settings_edit_form' => array());
     // Check the currently selected plugin, and merge persisted values for its
     // settings.
     if (isset($form_state['values']['fields'][$field_name]['type'])) {
         $display_options['type'] = $form_state['values']['fields'][$field_name]['type'];
     }
     if (isset($form_state['plugin_settings'][$field_name]['settings'])) {
         $display_options['settings'] = $form_state['plugin_settings'][$field_name]['settings'];
     }
     if (isset($form_state['plugin_settings'][$field_name]['third_party_settings'])) {
         $display_options['third_party_settings'] = $form_state['plugin_settings'][$field_name]['third_party_settings'];
     }
     // Get the corresponding plugin object.
     $plugin = $this->getPlugin($field_definition, $display_options);
     // Base button element for the various plugin settings actions.
     $base_button = array('#submit' => array(array($this, 'multistepSubmit')), '#ajax' => array('callback' => array($this, 'multistepAjax'), 'wrapper' => 'field-display-overview-wrapper', 'effect' => 'fade'), '#field_name' => $field_name);
     if ($form_state['plugin_settings_edit'] == $field_name) {
         // We are currently editing this field's plugin settings. Display the
         // settings form and submit buttons.
         $field_row['plugin']['settings_edit_form'] = array();
         if ($plugin) {
             // Generate the settings form and allow other modules to alter it.
             $settings_form = $plugin->settingsForm($form, $form_state);
             $third_party_settings_form = $this->thirdPartySettingsForm($plugin, $field_definition, $form, $form_state);
             if ($settings_form || $third_party_settings_form) {
                 $field_row['plugin']['#cell_attributes'] = array('colspan' => 3);
                 $field_row['plugin']['settings_edit_form'] = array('#type' => 'container', '#attributes' => array('class' => array('field-plugin-settings-edit-form')), '#parents' => array('fields', $field_name, 'settings_edit_form'), 'label' => array('#markup' => $this->t('Plugin settings')), 'settings' => $settings_form, 'third_party_settings' => $third_party_settings_form, 'actions' => array('#type' => 'actions', 'save_settings' => $base_button + array('#type' => 'submit', '#button_type' => 'primary', '#name' => $field_name . '_plugin_settings_update', '#value' => $this->t('Update'), '#op' => 'update'), 'cancel_settings' => $base_button + array('#type' => 'submit', '#name' => $field_name . '_plugin_settings_cancel', '#value' => $this->t('Cancel'), '#op' => 'cancel', '#limit_validation_errors' => array(array('fields', $field_name, 'type')))));
                 $field_row['#attributes']['class'][] = 'field-plugin-settings-editing';
             }
         }
     } else {
         $field_row['settings_summary'] = array();
         $field_row['settings_edit'] = array();
         if ($plugin) {
             // Display a summary of the current plugin settings, and (if the
             // summary is not empty) a button to edit them.
             $summary = $plugin->settingsSummary();
             // Allow other modules to alter the summary.
             $this->alterSettingsSummary($summary, $plugin, $field_definition);
             if (!empty($summary)) {
                 $summary_escaped = '';
                 $separator = '';
                 foreach ($summary as $summary_item) {
                     $summary_escaped .= $separator . SafeMarkup::escape($summary_item);
                     $separator = '<br />';
                 }
                 $field_row['settings_summary'] = array('#markup' => SafeMarkup::set('<div class="field-plugin-summary">' . $summary_escaped . '</div>'), '#cell_attributes' => array('class' => array('field-plugin-summary-cell')));
             }
             // Check selected plugin settings to display edit link or not.
             $settings_form = $plugin->settingsForm($form, $form_state);
             $third_party_settings_form = $this->thirdPartySettingsForm($plugin, $field_definition, $form, $form_state);
             if (!empty($settings_form) || !empty($third_party_settings_form)) {
                 $field_row['settings_edit'] = $base_button + array('#type' => 'image_button', '#name' => $field_name . '_settings_edit', '#src' => 'core/misc/configure-dark.png', '#attributes' => array('class' => array('field-plugin-settings-edit'), 'alt' => $this->t('Edit')), '#op' => 'edit', '#limit_validation_errors' => array(array('fields', $field_name, 'type')), '#prefix' => '<div class="field-plugin-settings-edit-wrapper">', '#suffix' => '</div>');
             }
         }
     }
     return $field_row;
 }
开发者ID:alnutile,项目名称:drunatra,代码行数:80,代码来源:DisplayOverviewBase.php

示例11: view

 /**
  * {@inheritdoc}
  */
 public function view(FieldItemListInterface $items)
 {
     $elements = $this->viewElements($items);
     // 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());
         $elements = array_merge($info, $elements);
     }
     return $elements;
 }
开发者ID:nstielau,项目名称:drops-8,代码行数:17,代码来源:FormatterBase.php


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