Commit 069902e3 authored by alexpott's avatar alexpott

Issue #2029857 by swentel, andrewmacpherson: Fixed Field plugin settings edit...

Issue #2029857 by swentel, andrewmacpherson: Fixed Field plugin settings edit button doesn't show unless there is a settings summary.
parent 0f4bacca
......@@ -35,9 +35,8 @@ public function settingsForm(array $form, array &$form_state);
/**
* Returns a short summary for the current formatter settings.
*
* If an empty result is returned, the formatter is assumed to have no
* configurable settings, and no UI will be provided to display a settings
* form.
* If an empty result is returned, a UI can still be provided to display
* a settings form in case the formatter has configurable settings.
*
* @return array()
* A short summary of the formatter settings.
......
......@@ -40,9 +40,8 @@ public function settingsForm(array $form, array &$form_state);
/**
* Returns a short summary for the current widget settings.
*
* If an empty result is returned, the widget is assumed to have no
* configurable settings, and no UI will be provided to display a settings
* form.
* If an empty result is returned, a UI can still be provided to display
* a settings form in case the widget has configurable settings.
*
* @return array
* A short summary of the widget settings.
......
<?php
/**
* @file
* Contains \Drupal\field_test\Plugin\field\formatter\TestFieldEmptySettingFormatter
*/
namespace Drupal\field_test\Plugin\field\formatter;
use Drupal\field\Annotation\FieldFormatter;
use Drupal\Core\Annotation\Translation;
use Drupal\field\Plugin\Type\Formatter\FormatterBase;
use Drupal\Core\Entity\Field\FieldItemListInterface;
/**
* Plugin implementation of the 'field_empty_setting' formatter.
*
* @FieldFormatter(
* id = "field_empty_setting",
* label = @Translation("Field empty setting"),
* field_types = {
* "test_field",
* },
* settings = {
* "field_empty_setting" = ""
* }
* )
*/
class TestFieldEmptySettingFormatter extends FormatterBase {
/**
* {@inheritdoc}
*/
public function settingsForm(array $form, array &$form_state) {
$element['field_empty_setting'] = array(
'#title' => t('Setting'),
'#type' => 'textfield',
'#size' => 20,
'#default_value' => $this->getSetting('field_empty_setting'),
'#required' => TRUE,
);
return $element;
}
/**
* {@inheritdoc}
*/
public function settingsSummary() {
$summary = array();
$setting = $this->getSetting('field_empty_setting');
if (!empty($setting)) {
$summary[] = t('Default empty setting now has a value.');
}
return $summary;
}
/**
* {@inheritdoc}
*/
public function viewElements(FieldItemListInterface $items) {
$elements = array();
if (!empty($items)) {
foreach ($items as $delta => $item) {
$elements[$delta] = array('#markup' => $this->getSetting('field_empty_setting'));
}
}
return $elements;
}
}
......@@ -355,6 +355,8 @@ protected function buildFieldRow($field_id, FieldInstanceInterface $instance, En
'#markup' => '<div class="field-plugin-summary">' . implode('<br />', $summary) . '</div>',
'#cell_attributes' => array('class' => array('field-plugin-summary-cell')),
);
}
if ($plugin->getSettings()) {
$field_row['settings_edit'] = $base_button + array(
'#type' => 'image_button',
'#name' => $field_id . '_settings_edit',
......
......@@ -93,6 +93,17 @@ function testFormatterUI() {
// Confirm that the settings are updated on the settings form.
$this->drupalPostAjaxForm(NULL, array(), "field_test_settings_edit");
$this->assertFieldByName($fieldname, 'foo');
// Test the empty setting formatter.
$edit = array('fields[field_test][type]' => 'field_empty_setting');
$this->drupalPostForm(NULL, $edit, t('Save'));
$this->assertNoText('Default empty setting now has a value.');
$this->assertFieldById('edit-fields-field-test-settings-edit');
$this->drupalPostAjaxForm(NULL, array(), "field_test_settings_edit");
$fieldname = 'fields[field_test][settings_edit_form][settings][field_empty_setting]';
$edit = array($fieldname => 'non empty setting');
$this->drupalPostAjaxForm(NULL, $edit, "field_test_plugin_settings_update");
$this->assertText('Default empty setting now has a value.');
}
/**
......
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