Commit f6b5925d authored by alexpott's avatar alexpott

Issue #1912504 by damiankloip, dawehner: Move _field_view_formatter_options() to Field.php.

parent 8244728c
......@@ -67,6 +67,13 @@ class Field extends FieldPluginBase {
*/
public $instance;
/**
* An array of formatter options.
*
* @var array
*/
protected $formatterOptions;
/**
* Overrides \Drupal\views\Plugin\views\field\FieldPluginBase::init().
*/
......@@ -330,7 +337,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.
......@@ -847,4 +854,37 @@ function field_langcode(EntityInterface $entity) {
}
}
/**
* Returns an array of formatter options for a field type.
*
* Borrowed from field_ui.
*
* @param string $field_type
* (optional) The field type to get options for.
*
* @return array
* An array of formatter options.
*
* @see field_ui_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;
}
}
......@@ -1675,33 +1675,6 @@ function views_handler_field_custom_pre_render_move_text($form) {
return $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;
}
/**
* Set a cached item in the views cache.
*
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment