Unverified Commit 1c40f14e authored by alexpott's avatar alexpott

Issue #3029669 by tim.plunkett, K3vin_nl, mpdonadio: Layout Builder must...

Issue #3029669 by tim.plunkett, K3vin_nl, mpdonadio: Layout Builder must adjust #states for formatters written expecting to be used by the Field UI
parent e1838d02
......@@ -15,6 +15,7 @@
use Drupal\Core\Field\FormatterInterface;
use Drupal\Core\Field\FormatterPluginManager;
use Drupal\Core\Form\EnforcedResponseException;
use Drupal\Core\Form\FormHelper;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Plugin\ContextAwarePluginInterface;
......@@ -281,6 +282,7 @@ public function formatterSettingsProcessCallback(array &$element, FormStateInter
$element['settings_wrapper']['settings']['#parents'] = array_merge($element['#parents'], ['settings']);
$element['settings_wrapper']['third_party_settings'] = $this->thirdPartySettingsForm($formatter, $this->getFieldDefinition(), $complete_form, $form_state);
$element['settings_wrapper']['third_party_settings']['#parents'] = array_merge($element['#parents'], ['third_party_settings']);
FormHelper::rewriteStatesSelector($element['settings_wrapper'], "fields[$this->fieldName][settings_edit_form]", 'settings[formatter]');
// Store the array parents for our element so that we can retrieve the
// formatter settings in our AJAX callback.
......
......@@ -56,7 +56,7 @@ protected function setUp() {
/**
* Tests configuring a field block for a user field.
*/
public function testFieldBlock() {
public function testUserFieldBlock() {
$page = $this->getSession()->getPage();
$assert_session = $this->assertSession();
......@@ -126,4 +126,29 @@ public function testFieldBlock() {
$assert_session->pageTextContains('Sunday, November 19, 1978 - 16:00');
}
/**
* Tests configuring a field block that uses #states.
*/
public function testStatesFieldBlock() {
$page = $this->getSession()->getPage();
$timestamp_field_storage = FieldStorageConfig::create([
'field_name' => 'field_timestamp',
'entity_type' => 'user',
'type' => 'timestamp',
]);
$timestamp_field_storage->save();
$timestamp_field = FieldConfig::create([
'field_storage' => $timestamp_field_storage,
'bundle' => 'user',
'label' => 'Timestamp',
]);
$timestamp_field->save();
$this->drupalGet('admin/structure/block/add/field_block_test%3Auser%3Auser%3Afield_timestamp/classy');
$this->assertFalse($page->findField('settings[formatter][settings][custom_date_format]')->isVisible(), 'Custom date format is not visible');
$page->selectFieldOption('settings[formatter][settings][date_format]', 'custom');
$this->assertTrue($page->findField('settings[formatter][settings][custom_date_format]')->isVisible(), 'Custom date format is visible');
}
}
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