diff --git a/core/modules/field/lib/Drupal/field/Plugin/views/field/Field.php b/core/modules/field/lib/Drupal/field/Plugin/views/field/Field.php index 976aa05..b0fb06e 100644 --- a/core/modules/field/lib/Drupal/field/Plugin/views/field/Field.php +++ b/core/modules/field/lib/Drupal/field/Plugin/views/field/Field.php @@ -69,6 +69,13 @@ class Field extends FieldPluginBase { public $instance; /** + * An array of formatter options. + * + * @var array + */ + protected $formatterOptions; + + /** * Overrides \Drupal\views\Plugin\views\field\FieldPluginBase::init(). */ public function init(ViewExecutable $view, DisplayPluginBase $display, array &$options = NULL) { @@ -331,7 +338,7 @@ public function buildOptionsForm(&$form, &$form_state) { parent::buildOptionsForm($form, $form_state); $field = $this->field_info; - $formatters = _field_view_formatter_options($field['type']); + $formatters = $this->formatterOptions($field['type']); $column_names = array_keys($field['columns']); // If this is a multiple value field, add its options. @@ -861,4 +868,35 @@ function field_langcode(EntityInterface $entity) { } } + /** + * Returns an array of formatter options for a field type. + * + * Borrowed from field_ui. + * + * @param string + * (optional) The field type to get options for. + * + * @return array + * An array of formatter options. + */ + protected function formatterOptions($field_type = NULL) { + if (!isset($this->formatterOptions)) { + $field_types = field_info_field_types(); + $this->formatterOptions = array(); + foreach (field_info_formatter_types() as $name => $formatter) { + foreach ($formatter['field_types'] as $formatter_field_type) { + // Check that the field type exists. + if (isset($field_types[$formatter_field_type])) { + $this->formatterOptions[$formatter_field_type][$name] = $formatter['label']; + } + } + } + } + + if ($field_type) { + return !empty($this->formatterOptions[$field_type]) ? $this->formatterOptions[$field_type] : array(); + } + return $options; + } + } diff --git a/core/modules/views/views.module b/core/modules/views/views.module index 31c47ff..b05f804 100644 --- a/core/modules/views/views.module +++ b/core/modules/views/views.module @@ -1753,33 +1753,6 @@ function views_handler_field_custom_pre_render_move_text($form) { } /** - * Helper function: Return an array of formatter options for a field type. - * - * Borrowed from field_ui. - */ -function _field_view_formatter_options($field_type = NULL) { - $options = &drupal_static(__FUNCTION__); - - if (!isset($options)) { - $field_types = field_info_field_types(); - $options = array(); - foreach (field_info_formatter_types() as $name => $formatter) { - foreach ($formatter['field_types'] as $formatter_field_type) { - // Check that the field type exists. - if (isset($field_types[$formatter_field_type])) { - $options[$formatter_field_type][$name] = $formatter['label']; - } - } - } - } - - if ($field_type) { - return !empty($options[$field_type]) ? $options[$field_type] : array(); - } - return $options; -} - -/** * Adds one to each key of the array. * * For example array(0 => 'foo') would be array(1 => 'foo').