Same name and namespace in other branches
  1. 8.9.x core/modules/block/src/BlockPluginCollection.php \Drupal\block\BlockPluginCollection::initializePlugin()
  2. 9 core/modules/block/src/BlockPluginCollection.php \Drupal\block\BlockPluginCollection::initializePlugin()

Initializes and stores a plugin.

Parameters

string $instance_id: The ID of the plugin instance to initialize.

Overrides DefaultSingleLazyPluginCollection::initializePlugin

File

core/modules/block/src/BlockPluginCollection.php, line 51

Class

BlockPluginCollection
Provides a collection of block plugins.

Namespace

Drupal\block

Code

protected function initializePlugin($instance_id) {
  if (!$instance_id) {
    throw new PluginException("The block '{$this->blockId}' did not specify a plugin.");
  }
  try {
    parent::initializePlugin($instance_id);
  } catch (PluginException $e) {
    $module = $this->configuration['provider'];

    // Ignore blocks belonging to uninstalled modules, but re-throw valid
    // exceptions when the module is installed and the plugin is
    // misconfigured.
    if (!$module || \Drupal::moduleHandler()
      ->moduleExists($module)) {
      throw $e;
    }
  }
}