Commit 30e1599a authored by alexpott's avatar alexpott

Issue #1854868 by swentel: Let formatter summaries return arrays instead of strings.

parent 3282c154
......@@ -32,7 +32,7 @@
class DateTimeDefaultFormatter extends FormatterBase {
/**
* Implements \Drupal\field\Plugin\Type\Formatter\FormatterInterface::viewElements().
* {@inheritdoc}
*/
public function viewElements(EntityInterface $entity, $langcode, array $items) {
......@@ -93,7 +93,7 @@ function dateFormat($date) {
}
/**
* Implements \Drupal\field\Plugin\Type\Formatter\FormatterInterface::settingsForm().
* {@inheritdoc}
*/
public function settingsForm(array $form, array &$form_state) {
......@@ -119,15 +119,13 @@ public function settingsForm(array $form, array &$form_state) {
}
/**
* Implements \Drupal\field\Plugin\Type\Formatter\FormatterInterface::settingsSummary().
* {@inheritdoc}
*/
public function settingsSummary() {
$summary = array();
$date = new DrupalDateTime();
$output = array();
$output[] = t('Format: @display', array('@display' => $this->dateFormat($date, FALSE)));
return implode('<br />', $output);
$summary[] = t('Format: @display', array('@display' => $this->dateFormat($date, FALSE)));
return $summary;
}
}
......@@ -33,7 +33,7 @@
class EntityReferenceEntityFormatter extends EntityReferenceFormatterBase {
/**
* Overrides \Drupal\entity_reference\Plugin\field\formatter\EntityReferenceFormatterBase::settingsForm().
* {@inheritdoc}
*/
public function settingsForm(array $form, array &$form_state) {
$view_modes = entity_get_view_modes($this->field['settings']['target_type']);
......@@ -60,7 +60,7 @@ public function settingsForm(array $form, array &$form_state) {
}
/**
* Overrides \Drupal\field\Plugin\Type\Formatter\FormatterBase::settingsSummary().
* {@inheritdoc}
*/
public function settingsSummary() {
$summary = array();
......@@ -70,11 +70,11 @@ public function settingsSummary() {
$summary[] = t('Rendered as @mode', array('@mode' => isset($view_modes[$view_mode]['label']) ? $view_modes[$view_mode]['label'] : $view_mode));
$summary[] = $this->getSetting('links') ? t('Display links') : t('Do not display links');
return implode('<br />', $summary);
return $summary;
}
/**
* Overrides \Drupal\entity_reference\Plugin\field\formatter\EntityReferenceFormatterBase::viewElements().
* {@inheritdoc}
*/
public function viewElements(EntityInterface $entity, $langcode, array $items) {
// Remove un-accessible items.
......
......@@ -31,7 +31,7 @@
class EntityReferenceLabelFormatter extends EntityReferenceFormatterBase {
/**
* Overrides \Drupal\field\Plugin\Type\Formatter\FormatterBase::settingsForm().
* {@inheritdoc}
*/
public function settingsForm(array $form, array &$form_state) {
$elements['link'] = array(
......@@ -44,17 +44,16 @@ public function settingsForm(array $form, array &$form_state) {
}
/**
* Overrides \Drupal\field\Plugin\Type\Formatter\FormatterBase::settingsSummary().
* {@inheritdoc}
*/
public function settingsSummary() {
$summary = array();
$summary[] = $this->getSetting('link') ? t('Link to the referenced entity') : t('No link');
return implode('<br />', $summary);
return $summary;
}
/**
* Overrides \Drupal\entity_reference\Plugin\field\formatter\EntityReferenceFormatterBase::viewElements().
* {@inheritdoc}
*/
public function viewElements(EntityInterface $entity, $langcode, array $items) {
// Remove un-accessible items.
......
......@@ -78,7 +78,7 @@ public function __construct($plugin_id, array $plugin_definition, $instance, arr
}
/**
* Implements Drupal\field\Plugin\Type\Formatter\FormatterInterface::view().
* {@inheritdoc}
*/
public function view(EntityInterface $entity, $langcode, array $items) {
$field = $this->field;
......@@ -113,21 +113,21 @@ public function view(EntityInterface $entity, $langcode, array $items) {
}
/**
* Implements Drupal\field\Plugin\Type\Formatter\FormatterInterface::settingsForm().
* {@inheritdoc}
*/
public function settingsForm(array $form, array &$form_state) {
return array();
}
/**
* Implements Drupal\field\Plugin\Type\Formatter\FormatterInterface::settingsSummary().
* {@inheritdoc}
*/
public function settingsSummary() {
return '';
return array();
}
/**
* Implements Drupal\field\Plugin\Type\Formatter\FormatterInterface::prepareView().
* {@inheritdoc}
*/
public function prepareView(array $entities, $langcode, array &$items) { }
......
......@@ -2,7 +2,7 @@
/**
* @file
* Definition of Drupal\field\Plugin\Type\Formatter\FormatterInterface.
* Contains \Drupal\field\Plugin\Type\Formatter\FormatterInterface.
*/
namespace Drupal\field\Plugin\Type\Formatter;
......@@ -40,8 +40,8 @@ public function settingsForm(array $form, array &$form_state);
* configurable settings, and no UI will be provided to display a settings
* form.
*
* @return string
* A short summary of the formatter settings..
* @return array()
* A short summary of the formatter settings.
*/
public function settingsSummary();
......
......@@ -276,7 +276,8 @@ function field_test_field_formatter_settings_form_alter(&$element, &$form_state,
* Implements hook_field_formatter_settings_summary_alter().
*/
function field_test_field_formatter_settings_summary_alter(&$summary, $context) {
$summary .= '<br />field_test_field_formatter_settings_summary_alter';
$summary[] = 'field_test_field_formatter_settings_summary_alter';
return $summary;
}
/**
......
......@@ -2,7 +2,7 @@
/**
* @file
* Definition of Drupal\field_test\Plugin\field\formatter\TestFieldDefaultFormatter.
* Contains \Drupal\field_test\Plugin\field\formatter\TestFieldDefaultFormatter.
*/
namespace Drupal\field_test\Plugin\field\formatter;
......@@ -31,7 +31,7 @@
class TestFieldDefaultFormatter extends FormatterBase {
/**
* Implements Drupal\field\Plugin\Type\Formatter\FormatterInterface::settingsForm().
* {@inheritdoc}
*/
public function settingsForm(array $form, array &$form_state) {
$element['test_formatter_setting'] = array(
......@@ -45,14 +45,16 @@ public function settingsForm(array $form, array &$form_state) {
}
/**
* Implements Drupal\field\Plugin\Type\Formatter\FormatterInterface::settingsForm().
* {@inheritdoc}
*/
public function settingsSummary() {
return t('@setting: @value', array('@setting' => 'test_formatter_setting', '@value' => $this->getSetting('test_formatter_setting')));
$summary = array();
$summary[] = t('@setting: @value', array('@setting' => 'test_formatter_setting', '@value' => $this->getSetting('test_formatter_setting')));
return $summary;
}
/**
* Implements Drupal\field\Plugin\Type\Formatter\FormatterInterface::viewElements().
* {@inheritdoc}
*/
public function viewElements(EntityInterface $entity, $langcode, array $items) {
$elements = array();
......
......@@ -2,7 +2,7 @@
/**
* @file
* Definition of Drupal\field_test\Plugin\field\formatter\TestFieldMultipleFormatter.
* Contains \Drupal\field_test\Plugin\field\formatter\TestFieldMultipleFormatter.
*/
namespace Drupal\field_test\Plugin\field\formatter;
......@@ -31,7 +31,7 @@
class TestFieldMultipleFormatter extends FormatterBase {
/**
* Implements Drupal\field\Plugin\Type\Formatter\FormatterInterface::settingsForm().
* {@inheritdoc}
*/
public function settingsForm(array $form, array &$form_state) {
$element['test_formatter_setting_multiple'] = array(
......@@ -45,14 +45,16 @@ public function settingsForm(array $form, array &$form_state) {
}
/**
* Implements Drupal\field\Plugin\Type\Formatter\FormatterInterface::settingsForm().
* {@inheritdoc}
*/
public function settingsSummary() {
return t('@setting: @value', array('@setting' => 'test_formatter_setting_multiple', '@value' => $this->getSetting('test_formatter_setting_multiple')));
$summary = array();
$summary[] = t('@setting: @value', array('@setting' => 'test_formatter_setting_multiple', '@value' => $this->getSetting('test_formatter_setting_multiple')));
return $summary;
}
/**
* Implements Drupal\field\Plugin\Type\Formatter\FormatterInterface::viewElements().
* {@inheritdoc}
*/
public function viewElements(EntityInterface $entity, $langcode, array $items) {
$elements = array();
......
......@@ -2,7 +2,7 @@
/**
* @file
* Definition of Drupal\field_test\Plugin\field\formatter\TestFieldPrepareViewFormatter.
* Contains \Drupal\field_test\Plugin\field\formatter\TestFieldPrepareViewFormatter.
*/
namespace Drupal\field_test\Plugin\field\formatter;
......@@ -31,7 +31,7 @@
class TestFieldPrepareViewFormatter extends FormatterBase {
/**
* Implements Drupal\field\Plugin\Type\Formatter\FormatterInterface::settingsForm().
* {@inheritdoc}
*/
public function settingsForm(array $form, array &$form_state) {
$element['test_formatter_setting_additional'] = array(
......@@ -45,14 +45,16 @@ public function settingsForm(array $form, array &$form_state) {
}
/**
* Implements Drupal\field\Plugin\Type\Formatter\FormatterInterface::settingsForm().
* {@inheritdoc}
*/
public function settingsSummary() {
return t('@setting: @value', array('@setting' => 'test_formatter_setting_additional', '@value' => $this->getSetting('test_formatter_setting_additional')));
$summary = array();
$summary[] = t('@setting: @value', array('@setting' => 'test_formatter_setting_additional', '@value' => $this->getSetting('test_formatter_setting_additional')));
return $summary;
}
/**
* Implements Drupal\field\Plugin\Type\Formatter\FormatterInterface::prepareView().
* {@inheritdoc}
*/
public function prepareView(array $entities, $langcode, array &$items) {
foreach ($items as $id => $item) {
......@@ -66,7 +68,7 @@ public function prepareView(array $entities, $langcode, array &$items) {
}
/**
* Implements Drupal\field\Plugin\Type\Formatter\FormatterInterface::viewElements().
* {@inheritdoc}
*/
public function viewElements(EntityInterface $entity, $langcode, array $items) {
$elements = array();
......
......@@ -93,10 +93,10 @@ function hook_field_instance_settings_form($field, $instance, $form_state) {
}
/**
* Alter the formatter settings form.
* Alters the formatter settings form.
*
* @param $element
* Form array as returned by hook_field_formatter_settings_form().
* Form array.
* @param $form_state
* The form state of the (entire) configuration form.
* @param $context
......@@ -106,6 +106,8 @@ function hook_field_instance_settings_form($field, $instance, $form_state) {
* - instance: The instance structure being configured.
* - view_mode: The view mode being configured.
* - form: The (entire) configuration form array.
*
* @see \Drupal\field_ui\DisplayOverView.
*/
function hook_field_formatter_settings_form_alter(&$element, &$form_state, $context) {
// Add a 'mysetting' checkbox to the settings form for 'foo_field' fields.
......@@ -119,23 +121,25 @@ function hook_field_formatter_settings_form_alter(&$element, &$form_state, $cont
}
/**
* Alter the field formatter settings summary.
* Alters the field formatter settings summary.
*
* @param $summary
* The summary as returned by hook_field_formatter_settings_summary().
* The summary.
* @param $context
* An associative array with the following elements:
* - formatter: The formatter object.
* - field: The field structure being configured.
* - instance: The instance structure being configured.
* - view_mode: The view mode being configured.
*
* @see \Drupal\field_ui\DisplayOverView.
*/
function hook_field_formatter_settings_summary_alter(&$summary, $context) {
// Append a message to the summary when an instance of foo_field has
// mysetting set to TRUE for the current view mode.
if ($context['field']['type'] == 'foo_field') {
if ($context['formatter']->getSetting('mysetting')) {
$summary .= '<br />' . t('My setting enabled.');
$summary[] = t('My setting enabled.');
}
}
}
......
......@@ -265,9 +265,9 @@ public function buildForm(array $form, array &$form_state, $entity_type = NULL,
);
drupal_alter('field_formatter_settings_summary', $summary, $context);
if ($summary) {
if (!empty($summary)) {
$table[$name]['settings_summary'] = array(
'#markup' => '<div class="field-formatter-summary">' . $summary . '</div>',
'#markup' => '<div class="field-formatter-summary">' . implode('<br />', $summary) . '</div>',
'#cell_attributes' => array('class' => array('field-formatter-summary-cell')),
);
$table[$name]['settings_edit'] = $base_button + array(
......
......@@ -31,7 +31,7 @@
class ImageFormatter extends FormatterBase {
/**
* Implements \Drupal\field\Plugin\Type\Formatter\FormatterInterface::settingsForm().
* {@inheritdoc}
*/
public function settingsForm(array $form, array &$form_state) {
$image_styles = image_style_options(FALSE);
......@@ -59,7 +59,7 @@ public function settingsForm(array $form, array &$form_state) {
}
/**
* Implements \Drupal\field\Plugin\Type\Formatter\FormatterInterface::settingsSummary().
* {@inheritdoc}
*/
public function settingsSummary() {
$summary = array();
......@@ -87,11 +87,11 @@ public function settingsSummary() {
$summary[] = $link_types[$image_link_setting];
}
return implode('<br />', $summary);
return $summary;
}
/**
* Implements \Drupal\field\Plugin\Type\Formatter\FormatterInterface::viewElements().
* {@inheritdoc}
*/
public function viewElements(EntityInterface $entity, $langcode, array $items) {
$elements = array();
......
......@@ -109,7 +109,7 @@ public function settingsSummary() {
$summary[] = t('Open link in new window');
}
return implode('<br />', $summary);
return $summary;
}
/**
......
......@@ -2,7 +2,7 @@
/**
* @file
* Definition of Drupal\number\Plugin\field\formatter\DefaultNumberFormatter.
* Contains \Drupal\number\Plugin\field\formatter\DefaultNumberFormatter.
*/
namespace Drupal\number\Plugin\field\formatter;
......@@ -18,7 +18,7 @@
abstract class DefaultNumberFormatter extends FormatterBase {
/**
* Implements Drupal\field\Plugin\Type\Formatter\FormatterInterface::settingsForm().
* {@inheritdoc}
*/
public function settingsForm(array $form, array &$form_state) {
$options = array(
......@@ -48,7 +48,7 @@ public function settingsForm(array $form, array &$form_state) {
}
/**
* Implements Drupal\field\Plugin\Type\Formatter\FormatterInterface::settingsForm().
* {@inheritdoc}
*/
public function settingsSummary() {
$summary = array();
......@@ -58,11 +58,11 @@ public function settingsSummary() {
$summary[] = t('Display with prefix and suffix.');
}
return implode('<br />', $summary);
return $summary;
}
/**
* Implements Drupal\field\Plugin\Type\Formatter\FormatterInterface::viewElements().
* {@inheritdoc}
*/
public function viewElements(EntityInterface $entity, $langcode, array $items) {
$elements = array();
......
......@@ -2,7 +2,7 @@
/**
* @file
* Definition of Drupal\picture\Plugin\field\formatter\PictureFormatter.
* Contains \Drupal\picture\Plugin\field\formatter\PictureFormatter.
*/
namespace Drupal\picture\Plugin\field\formatter;
......@@ -32,7 +32,7 @@
class PictureFormatter extends FormatterBase {
/**
* Implements Drupal\field\Plugin\Type\Formatter\FormatterInterface::settingsForm().
* {@inheritdoc}
*/
public function settingsForm(array $form, array &$form_state) {
$picture_options = array();
......@@ -78,7 +78,7 @@ public function settingsForm(array $form, array &$form_state) {
}
/**
* Implements Drupal\field\Plugin\Type\Formatter\FormatterInterface::settingsForm().
* {@inheritdoc}
*/
public function settingsSummary() {
$summary = array();
......@@ -109,11 +109,11 @@ public function settingsSummary() {
$summary[] = t('Select a picture mapping.');
}
return implode('<br />', $summary);
return $summary;
}
/**
* Implements Drupal\field\Plugin\Type\Formatter\FormatterInterface::viewElements().
* {@inheritdoc}
*/
public function viewElements(EntityInterface $entity, $langcode, array $items) {
$elements = array();
......
......@@ -30,7 +30,7 @@
class TelephoneLinkFormatter extends FormatterBase {
/**
* Implements \Drupal\field\Plugin\Type\Formatter\FormatterInterface::settingsForm().
* {@inheritdoc}
*/
public function settingsForm(array $form, array &$form_state) {
$elements['title'] = array(
......@@ -43,23 +43,24 @@ public function settingsForm(array $form, array &$form_state) {
}
/**
* Implements \Drupal\field\Plugin\Type\Formatter\FormatterInterface::settingsSummary().
* {@inheritdoc}
*/
public function settingsSummary() {
$summary = array();
$settings = $this->getSettings();
if (!empty($settings['title'])) {
$summary = t('Link using text: @title', array('@title' => $settings['title']));
$summary[] = t('Link using text: @title', array('@title' => $settings['title']));
}
else {
$summary = t('Link using provided telephone number.');
$summary[] = t('Link using provided telephone number.');
}
return $summary;
}
/**
* Implements \Drupal\field\Plugin\Type\Formatter\FormatterInterface::prepareView().
* {@inheritdoc}
*/
public function prepareView(array $entities, $langcode, array &$items) {
$settings = $this->getSettings();
......@@ -79,7 +80,7 @@ public function prepareView(array $entities, $langcode, array &$items) {
}
/**
* Implements \Drupal\field\Plugin\Type\Formatter\FormatterInterface::viewElements().
* {@inheritdoc}
*/
public function viewElements(EntityInterface $entity, $langcode, array $items) {
$element = array();
......
......@@ -3,7 +3,7 @@
/**
* @file
*
* Definition of Drupal\text\Plugin\field\formatter\TextTrimmedFormatter.
* Contains \Drupal\text\Plugin\field\formatter\TextTrimmedFormatter.
*/
namespace Drupal\text\Plugin\field\formatter;
......@@ -40,7 +40,7 @@
class TextTrimmedFormatter extends FormatterBase {
/**
* Implements Drupal\field\Plugin\Type\Formatter\FormatterInterface::settingsForm().
* {@inheritdoc}
*/
public function settingsForm(array $form, array &$form_state) {
$element['trim_length'] = array(
......@@ -54,16 +54,16 @@ public function settingsForm(array $form, array &$form_state) {
}
/**
* Implements Drupal\field\Plugin\Type\Formatter\FormatterInterface::settingsSummary().
* {@inheritdoc}
*/
public function settingsSummary() {
return t('Trim length: @trim_length', array(
'@trim_length' => $this->getSetting('trim_length'),
));
$summary = array();
$summary[] = t('Trim length: @trim_length', array('@trim_length' => $this->getSetting('trim_length')));
return $summary;
}
/**
* Implements Drupal\field\Plugin\Type\Formatter\FormatterInterface::viewElements().
* {@inheritdoc}
*/
public function viewElements(EntityInterface $entity, $langcode, array $items) {
$elements = array();
......
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