Commit 53899424 authored by webchick's avatar webchick
Browse files

Issue #2882729 by tedbow, tim.plunkett, Bojhan: In off-canvas block form hide...

Issue #2882729 by tedbow, tim.plunkett, Bojhan: In off-canvas block form hide Title input unless it will be displayed and change label to Block Title
parent ba815614
......@@ -44,7 +44,7 @@ public function form(array $form, FormStateInterface $form_state) {
}
$form['advanced_link'] = [
'#type' => 'link',
'#title' => $this->t('Advanced options'),
'#title' => $this->t('Advanced block options'),
'#url' => $this->entity->toUrl('edit-form', ['query' => $query]),
'#weight' => 1000,
];
......@@ -52,6 +52,18 @@ public function form(array $form, FormStateInterface $form_state) {
// Remove the ID and region elements.
unset($form['id'], $form['region'], $form['settings']['admin_label']);
if (isset($form['settings']['label_display']) && isset($form['settings']['label'])) {
// Only show the label input if the label will be shown on the page.
$form['settings']['label_display']['#weight'] = -100;
$form['settings']['label']['#states']['visible'] = [
':input[name="settings[label_display]"]' => ['checked' => TRUE],
];
// Relabel to "Block title" because on the front-end this may be confused
// with page title.
$form['settings']['label']['#title'] = $this->t("Block title");
$form['settings']['label_display']['#title'] = $this->t("Display block title");
}
return $form;
}
......
......@@ -16,6 +16,8 @@ class OutsideInBlockFormTest extends OutsideInJavascriptTestBase {
const TOOLBAR_EDIT_LINK_SELECTOR = '#toolbar-bar div.contextual-toolbar-tab button';
const LABEL_INPUT_SELECTOR = 'input[data-drupal-selector="edit-settings-label"]';
/**
* {@inheritdoc}
*/
......@@ -92,9 +94,15 @@ public function testBlocks($block_plugin, $new_page_text, $element_selector, $la
$this->openBlockForm($block_selector);
switch ($block_plugin) {
case 'system_powered_by_block':
// Confirm "Display Title" is not checked.
$web_assert->checkboxNotChecked('settings[label_display]');
// Confirm Title is not visible.
$this->assertEquals($this->isLabelInputVisible(), FALSE, 'Label is not visible');
$page->checkField('settings[label_display]');
$this->assertEquals($this->isLabelInputVisible(), TRUE, 'Label is visible');
// Fill out form, save the form.
$page->fillField('settings[label]', $new_page_text);
$page->checkField('settings[label_display]');
break;
case 'system_branding_block':
......@@ -195,8 +203,19 @@ protected function disableEditMode() {
*/
protected function assertOffCanvasBlockFormIsValid() {
$web_assert = $this->assertSession();
// Confirm that Block title display label has been changed.
$web_assert->elementTextContains('css', '.form-item-settings-label-display label', 'Display block title');
// Confirm Block title label is shown if checkbox is checked.
if ($this->getSession()->getPage()->find('css', 'input[name="settings[label_display]"]')->isChecked()) {
$this->assertEquals($this->isLabelInputVisible(), TRUE, 'Label is visible');
$web_assert->elementTextContains('css', '.form-item-settings-label label', 'Block title');
}
else {
$this->assertEquals($this->isLabelInputVisible(), FALSE, 'Label is not visible');
}
// Check that common block form elements exist.
$web_assert->elementExists('css', 'input[data-drupal-selector="edit-settings-label"]');
$web_assert->elementExists('css', static::LABEL_INPUT_SELECTOR);
$web_assert->elementExists('css', 'input[data-drupal-selector="edit-settings-label-display"]');
// Check that advanced block form elements do not exist.
$web_assert->elementNotExists('css', 'input[data-drupal-selector="edit-visibility-request-path-pages"]');
......@@ -469,4 +488,14 @@ public function getBlockSelector(Block $block) {
return '#block-' . $block->id();
}
/**
* Determines if the label input is visible.
*
* @return bool
* TRUE if the label is visible, FALSE if it is not.
*/
protected function isLabelInputVisible() {
return $this->getSession()->getPage()->find('css', static::LABEL_INPUT_SELECTOR)->isVisible();
}
}
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