function BlockVariantTrait::addBlock

Same name in other branches
  1. 4.0.x src/Plugin/BlockVariantTrait.php \Drupal\ctools\Plugin\BlockVariantTrait::addBlock()

See also

\Drupal\ctools\Plugin\BlockVariantInterface::addBlock()

File

src/Plugin/BlockVariantTrait.php, line 49

Class

BlockVariantTrait
Provides methods for \Drupal\ctools\Plugin\BlockVariantInterface.

Namespace

Drupal\ctools\Plugin

Code

public function addBlock(array $configuration) {
    $configuration['uuid'] = $this->uuidGenerator()
        ->generate();
    $this->getBlockCollection()
        ->addInstanceId($configuration['uuid'], $configuration);
    $block = $this->getBlock($configuration['uuid']);
    // Allow modules to react to the change.
    $event = new BlockVariantEvent($block, $this);
    $this->eventDispatcher()
        ->dispatch($event, BlockVariantEvents::ADD_BLOCK);
    return $configuration['uuid'];
}