protected function BlockPluginBag::initializePlugin

Initializes a plugin and stores the result in $this->pluginInstances.

Parameters

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

Overrides PluginBag::initializePlugin

File

drupal/core/modules/block/lib/Drupal/block/BlockPluginBag.php, line 47
Contains \Drupal\block\BlockPluginBag.

Class

BlockPluginBag
Provides a collection of block plugins.

Namespace

Drupal\block

Code

protected function initializePlugin($instance_id) {
  if (!$instance_id) {
    throw new PluginException(format_string("The block '@block' did not specify a plugin.", array(
      '@block' => $this->entity
        ->id(),
    )));
  }
  if (isset($this->pluginInstances[$instance_id])) {
    return;
  }
  $settings = $this->entity
    ->get('settings');
  try {
    $this->pluginInstances[$instance_id] = $this->manager
      ->createInstance($instance_id, $settings);
  } catch (PluginException $e) {
    $module = $settings['module'];

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