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

8.0.x
Alex Pott 2013-05-27 12:46:26 -07:00
parent 8244728c92
commit f6b5925da7
2 changed files with 41 additions and 28 deletions

View File

@ -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 @@ class Field extends FieldPluginBase {
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 @@ class Field extends FieldPluginBase {
}
}
/**
* 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;
}
}

View File

@ -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.
*