Commit ed23b897 authored by catch's avatar catch
Browse files

Issue #3412283 by mathilde_dumond, acbramley, Berdir, smustgrave, BramDriesen,...

Issue #3412283 by mathilde_dumond, acbramley, Berdir, smustgrave, BramDriesen, larowlan: Editing a block_content entity no longer redirects to the overview

(cherry picked from commit b46fb5e6)
parent a9b2d321
Loading
Loading
Loading
Loading
Loading
+12 −14
Original line number Diff line number Diff line
@@ -108,9 +108,8 @@ public function save(array $form, FormStateInterface $form_state) {
    if ($block->id()) {
      $form_state->setValue('id', $block->id());
      $form_state->set('id', $block->id());
      if ($insert) {
      $theme = $block->getTheme();
        if ($theme) {
      if ($insert && $theme) {
        $form_state->setRedirect(
          'block.admin_add',
          [
@@ -123,7 +122,6 @@ public function save(array $form, FormStateInterface $form_state) {
        $form_state->setRedirectUrl($block->toUrl('collection'));
      }
    }
    }
    else {
      // In the unlikely case something went wrong on save, the block will be
      // rebuilt and block form redisplayed.
+25 −12
Original line number Diff line number Diff line
@@ -2,6 +2,7 @@

namespace Drupal\Tests\block_content\Functional;

use Drupal\block_content\BlockContentInterface;
use Drupal\block_content\Entity\BlockContent;
use Drupal\Core\Database\Database;

@@ -67,10 +68,7 @@ public function testBlockContentCreation() {
    $this->assertSession()->fieldNotExists('settings[view_mode]');

    // Check that the block exists in the database.
    $blocks = \Drupal::entityTypeManager()
      ->getStorage('block_content')
      ->loadByProperties(['info' => $edit['info[0][value]']]);
    $block = reset($blocks);
    $block = $this->getBlockByLabel($edit['info[0][value]']);
    $this->assertNotEmpty($block, 'Content Block found in database.');
  }

@@ -133,10 +131,7 @@ public function testBlockContentCreationMultipleViewModes() {
    $this->assertSession()->fieldValueEquals('settings[view_mode]', 'test_view_mode');

    // Check that the block exists in the database.
    $blocks = \Drupal::entityTypeManager()
      ->getStorage('block_content')
      ->loadByProperties(['info' => $edit['info[0][value]']]);
    $block = reset($blocks);
    $block = $this->getBlockByLabel($edit['info[0][value]']);
    $this->assertNotEmpty($block, 'Content Block found in database.');
  }

@@ -175,6 +170,14 @@ public function testBlockContentFormSubmitHandlers() {
    $this->assertSession()->pageTextContains('basic ' . $edit['info[0][value]'] . ' has been created.');
    $this->assertSession()->addressEquals('/admin/content/block');

    // Check that the user is redirected to the block library on edit.
    $block = $this->getBlockByLabel($edit['info[0][value]']);
    $this->drupalGet($block->toUrl('edit-form'));
    $this->submitForm([
      'info[0][value]' => 'Test Block Updated',
    ], 'Save');
    $this->assertSession()->addressEquals('admin/content/block');

    // Test with user who doesn't have permission to place a block.
    $this->drupalLogin($this->drupalCreateUser(['administer block content']));
    $this->drupalGet('block/add/basic');
@@ -200,10 +203,7 @@ public function testDefaultBlockContentCreation() {
    $this->assertSession()->pageTextContains('basic ' . $edit['info[0][value]'] . ' has been created.');

    // Check that the block exists in the database.
    $blocks = \Drupal::entityTypeManager()
      ->getStorage('block_content')
      ->loadByProperties(['info' => $edit['info[0][value]']]);
    $block = reset($blocks);
    $block = $this->getBlockByLabel($edit['info[0][value]']);
    $this->assertNotEmpty($block, 'Default Content Block found in database.');
  }

@@ -316,4 +316,17 @@ public function testConfigDependencies() {
    $this->assertEquals($block_placement_id, $block_placement->id(), "The block placement config entity has a dependency on the block content entity.");
  }

  /**
   * Load a block based on the label.
   */
  private function getBlockByLabel(string $label): ?BlockContentInterface {
    $blocks = \Drupal::entityTypeManager()
      ->getStorage('block_content')
      ->loadByProperties(['info' => $label]);
    if (empty($blocks)) {
      return NULL;
    }
    return reset($blocks);
  }

}