diff --git a/src/Plugin/Field/FieldWidget/BlockFieldWidget.php b/src/Plugin/Field/FieldWidget/BlockFieldWidget.php index fd2eb7b..43cd98f 100644 --- a/src/Plugin/Field/FieldWidget/BlockFieldWidget.php +++ b/src/Plugin/Field/FieldWidget/BlockFieldWidget.php @@ -73,17 +73,17 @@ class BlockFieldWidget extends WidgetBase implements ContainerFactoryPluginInter * {@inheritdoc} */ public function settingsForm(array $form, FormStateInterface $form_state) { - $elements['configuration_form'] = array( + $elements['configuration_form'] = [ '#type' => 'select', '#title' => $this->t('Configuration form'), '#description' => $this->t('How the block configuration form will be shown.'), - '#options' => array( + '#options' => [ 'full' => $this->t('Full'), 'hidden' => $this->t('Hidden'), - ), + ], '#default_value' => $this->getSetting('configuration_form'), '#required' => TRUE, - ); + ]; return $elements; } diff --git a/tests/src/Functional/WidgetTest.php b/tests/src/Functional/WidgetTest.php index 98560f6..9dfc832 100644 --- a/tests/src/Functional/WidgetTest.php +++ b/tests/src/Functional/WidgetTest.php @@ -27,58 +27,77 @@ class WidgetTest extends BrowserTestBase { ]; /** + * The test block node. + * + * @var \Drupal\node\NodeInterface + */ + protected $blockNode; + + /** * {@inheritdoc} */ public function setUp() { parent::setUp(); $this->drupalLogin($this->drupalCreateUser([ + 'access administration pages', 'access content', - 'administer nodes', 'administer content types', - 'bypass node access', 'administer node fields', + 'administer node form display', + 'administer nodes', + 'bypass node access', ])); + + $this->drupalPostForm('node/add/block_node', [ + 'title[0][value]' => 'Block field test', + 'field_block[0][plugin_id]' => 'views_block:items-block_1', + ], $this->t('Save')); + + $this->blockNode = $this->drupalGetNodeByTitle('Block field test'); } /** * Test block settings are stored correctly. */ public function testBlockSettingsAreStoredCorrectly() { - // Configuration form: full. $items = $this->createDummyNodes('item', 5); - $this->drupalPostForm('node/add/block_node', [ - 'title[0][value]' => 'Block field test', - 'field_block[0][plugin_id]' => 'views_block:items-block_1', - ], $this->t('Save')); - - $node = $this->drupalGetNodeByTitle('Block field test'); - $this->drupalGet($node->toUrl('edit-form')); + $this->drupalGet($this->blockNode->toUrl('edit-form')); $this->submitForm([ 'field_block[0][settings][override][items_per_page]' => 5, ], $this->t('Save')); - // Overridden value of 5 nodes should show. foreach ($items as $item) { $this->assertSession()->pageTextContains($item->getTitle()); } + } + + /** + * Test configuration form options. + */ + public function testConfigurationFormOptions() { + $assert = $this->assertSession(); + + // Configuration form: full (the default). + $this->drupalGet($this->blockNode->toUrl('edit-form')); + $assert->fieldExists('field_block[0][settings][label_display]'); + $assert->fieldExists('field_block[0][settings][override][items_per_page]'); + $assert->fieldExists('field_block[0][settings][views_label_checkbox]'); + $assert->fieldExists('field_block[0][settings][views_label]'); // Configuration form: hidden. - $this->drupalPostAjaxForm('admin/structure/types/manage/block_node/form-display', [], 'field_block_settings_edit'); - $this->drupalPostForm(NULL, ['fields[field_block][settings_edit_form][settings][configuration_form]' => 'hidden'], t('Update')); - $this->drupalPostForm(NULL, [], t('Save')); - - $this->drupalGet('node/6/edit'); - $this->submitForm([], $this->t('Save and keep published')); - - // Default view items_per_page value of 1 node should show. - $test_nodes = $items; - do { - $contains = count($test_nodes) == 5 ? 'pageTextContains' : 'pageTextNotContains'; - $this->assertSession()->{$contains}(array_pop($test_nodes)->getTitle()); - } - while (count($test_nodes)); + $this->drupalGet('admin/structure/types/manage/block_node/form-display'); + $this->drupalPostForm(NULL, [], 'field_block_settings_edit'); + $edit = [ + 'fields[field_block][settings_edit_form][settings][configuration_form]' => 'hidden', + ]; + $this->drupalPostForm(NULL, $edit, t('Save')); + $this->drupalGet($this->blockNode->toUrl('edit-form')); + $assert->fieldNotExists('field_block[0][settings][label_display]'); + $assert->fieldNotExists('field_block[0][settings][override][items_per_page]'); + $assert->fieldNotExists('field_block[0][settings][views_label_checkbox]'); + $assert->fieldNotExists('field_block[0][settings][views_label]'); } /**