Commit 36cfe009 authored by bonrita's avatar bonrita Committed by Joshua Sedler
Browse files

Issue #3012844 by bonrita, Grevil: Exception when pre-added view block is deleted

parent 0c0715e9
Loading
Loading
Loading
Loading
+16 −3
Changes for src/Form/HomeboxSettingsForm.php: 16 added lines, 3 removed lines.
Original line number Diff line number Diff line
@@ -2,6 +2,7 @@

namespace Drupal\homebox\Form;

use Drupal\Component\Plugin\Exception\PluginNotFoundException;
use Drupal\Core\Block\BlockManagerInterface;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Theme\ThemeManagerInterface;
@@ -208,6 +209,7 @@ class HomeboxSettingsForm extends EntityForm {
    }

    foreach ($homebox_blocks as $block) {
      try {
        $definition = $this->blockManager->getDefinition($block['id']);
        $blocks[$block['region']][$block['id']] = [
          'label' => $definition['admin_label'],
@@ -216,6 +218,19 @@ class HomeboxSettingsForm extends EntityForm {
          'category' => $definition['category'],
          'status' => $block['status'],
        ];
      }
      catch (PluginNotFoundException $e) {
        $this->logger('homebox')->notice('A block does not exist anymore! Please go to the location of this message and remove it!');
        $this->messenger()->addError('There seems to be a broken block! Please remove it or enable the module, which provides this block.');
        $blocks[$block['region']][$block['id']] = [
          'label' => $this->t('THIS BLOCK IS BROKEN! PLEASE REMOVE IT!.'),
          'entity_id' => $block['id'],
          'entity' => NULL,
          'category' => $this->t('Broken'),
          'status' => $block['status'],
        ];
      }

      if (isset($block['weight'])) {
        $blocks[$block['region']][$block['id']]['weight'] = $block['weight'];
      }
@@ -478,8 +493,7 @@ class HomeboxSettingsForm extends EntityForm {
          ['query' => ['block-enable' => $block_id]]
        ),
      ];
    }
    else {
    } else {
      $operations['disable'] = [
        'title' => t('Disable'),
        'weight' => 40,
@@ -543,5 +557,4 @@ class HomeboxSettingsForm extends EntityForm {
    }
    return $this->theme;
  }

}