diff --git a/js/per_user_block.js b/js/per_user_block.js index 88798cd..16c858c 100644 --- a/js/per_user_block.js +++ b/js/per_user_block.js @@ -12,7 +12,7 @@ return; } - $("#edit-per-user-block").drupalSetSummary(function (context) { + $("#edit-third-party-settings-per-user-block").drupalSetSummary(function (context) { return $(context).find('input[type="radio"]:checked + label').text(); }); } diff --git a/per_user_block.module b/per_user_block.module index 3d9b553..e3dc13c 100644 --- a/per_user_block.module +++ b/per_user_block.module @@ -32,12 +32,12 @@ function per_user_block_form_block_form_alter(&$form, FormStateInterface $form_s /** @var \Drupal\block\Entity\Block $block */ $block = $form_state->getFormObject()->getEntity(); - $form['per_user_block'] = array( + $form['third_party_settings']['per_user_block'] = array( '#type' => 'details', '#title' => 'Per User', '#group' => 'visibility_tabs', ); - $form['per_user_block']['visibility'] = array( + $form['third_party_settings']['per_user_block']['visibility'] = array( '#type' => 'radios', '#title' => t('Customizable per user'), '#description' => t('Allow individual users to customize the visibility of this block in their account settings.'), @@ -49,18 +49,6 @@ function per_user_block_form_block_form_alter(&$form, FormStateInterface $form_s ), ); $form['#attached']['library'][] = 'per_user_block/per_user_block'; - $form['actions']['submit']['#submit'][] = 'per_user_block_block_form_submit'; -} - -/** - * Form submit callback. - */ -function per_user_block_block_form_submit(&$form, FormStateInterface $form_state) { - /** @var \Drupal\block\Entity\Block $block */ - $block = $form_state->getFormObject()->getEntity(); - $visibility = $form_state->getValue(['per_user_block', 'visibility']); - $block->setThirdPartySetting('per_user_block', 'visibility', $visibility); - $block->save(); } /** @@ -106,7 +94,7 @@ function per_user_block_form_user_form_alter(&$form, FormStateInterface $form_st '#options' => $options, '#default_value' => $default_values, ); -// $form['actions']['submit']['#submit'][] = 'per_user_block_user_form_submit'; + $form['actions']['submit']['#submit'][] = 'per_user_block_user_form_submit'; } /** diff --git a/src/Tests/PerUserBlockOptionTest.php b/src/Tests/PerUserBlockOptionTest.php index a85184f..f5dd328 100644 --- a/src/Tests/PerUserBlockOptionTest.php +++ b/src/Tests/PerUserBlockOptionTest.php @@ -62,12 +62,12 @@ class PerUserBlockOptionTest extends WebTestBase { // Get the Block manage page and ensure the settings exist. $block_path = 'admin/structure/block/manage/' . $block_id; $this->drupalGet($block_path); - $element = $this->xpath('//details[@id=:id]/*', array(':id' => 'edit-per-user-block')); + $element = $this->xpath('//details[@id=:id]/*', array(':id' => 'edit-third-party-settings-per-user-block')); $this->assertTrue(!empty($element), 'Per user block visibility settings exist.'); // Change the value to disabled and validate it was saved. $edit = array(); - $edit['per_user_block[visibility]'] = PER_USER_BLOCK_CUSTOM_DISABLED; + $edit['third_party_settings[per_user_block][visibility]'] = PER_USER_BLOCK_CUSTOM_DISABLED; $this->drupalPostForm($block_path, $edit, 'Save block'); $block = Block::load($block->id());