Commit 8cc0c638 authored by alexpott's avatar alexpott
Browse files

Issue #1912504 by damiankloip, dawehner, amateescu: Remove...

Issue #1912504 by damiankloip, dawehner, amateescu: Remove _field_view_formatter_options() from Views as it duplicates FormatterPluginManager::getOptions().
parent 27bd89be
......@@ -9,11 +9,13 @@
use Drupal\Core\Language\Language;
use Drupal\Core\Entity\EntityInterface;
use Drupal\field\Plugin\Type\Formatter\FormatterPluginManager;
use Drupal\views\ViewExecutable;
use Drupal\views\Plugin\views\display\DisplayPluginBase;
use Drupal\views\Plugin\views\field\FieldPluginBase;
use Drupal\Component\Annotation\PluginID;
use Drupal\views\Views;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* A field that displays fieldapi fields.
......@@ -74,6 +76,43 @@ class Field extends FieldPluginBase {
*/
protected $formatterOptions;
/**
* The field formatter plugin manager.
*
* @var \Drupal\field\Plugin\Type\Formatter\FormatterPluginManager
*/
protected $formatterPluginManager;
/**
* Constructs a \Drupal\field\Plugin\views\field\Field object.
*
* @param array $configuration
* A configuration array containing information about the plugin instance.
* @param string $plugin_id
* The plugin_id for the plugin instance.
* @param array $plugin_definition
* The plugin implementation definition.
* @param \Drupal\field\Plugin\Type\Formatter\FormatterPluginManager $formatter_plugin_manager
* The field formatter plugin manager.
*/
public function __construct(array $configuration, $plugin_id, array $plugin_definition, FormatterPluginManager $formatter_plugin_manager) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->formatterPluginManager = $formatter_plugin_manager;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, array $plugin_definition) {
return new static(
$configuration,
$plugin_id,
$plugin_definition,
$container->get('plugin.manager.field.formatter')
);
}
/**
* Overrides \Drupal\views\Plugin\views\field\FieldPluginBase::init().
*/
......@@ -333,11 +372,14 @@ protected function defineOptions() {
return $options;
}
/**
* {@inheritdoc}
*/
public function buildOptionsForm(&$form, &$form_state) {
parent::buildOptionsForm($form, $form_state);
$field = $this->field_info;
$formatters = $this->formatterOptions($field['type']);
$formatters = $this->formatterPluginManager->getOptions($field['type']);
$column_names = array_keys($field['columns']);
// If this is a multiple value field, add its options.
......@@ -854,37 +896,4 @@ 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;
}
}
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