contextHandler = $context_handler; $this->account = $account; $this->uuidGenerator = $uuid_generator; $this->token = $token; $this->blockManager = $block_manager; $this->conditionManager = $condition_manager; parent::__construct($configuration, $plugin_id, $plugin_definition); } /** * {@inheritdoc} */ public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { return new static( $configuration, $plugin_id, $plugin_definition, $container->get('context.handler'), $container->get('current_user'), $container->get('uuid'), $container->get('token'), $container->get('plugin.manager.block'), $container->get('plugin.manager.condition') ); } /** * {@inheritdoc} */ public function defaultConfiguration() { return parent::defaultConfiguration() + [ 'blocks' => [] ]; } /** * {@inheritdoc} */ public function calculateDependencies() { foreach ($this->getBlockCollection() as $instance) { $this->calculatePluginDependencies($instance); } return $this->dependencies; } /** * {@inheritdoc} */ public function getConfiguration() { return [ 'blocks' => $this->getBlockCollection()->getConfiguration(), ] + parent::getConfiguration(); } /** * {@inheritdoc} */ public function setConfiguration(array $configuration) { // preserve the uuid. if ($this->configuration && !empty($this->configuration['uuid'])) { $configuration['uuid'] = $this->configuration['uuid']; } parent::setConfiguration($configuration); $this->getBlockCollection()->setConfiguration($this->configuration['blocks']); return $this; } /** * Gets the contexts. * * @return \Drupal\Component\Plugin\Context\ContextInterface[] * An array of set contexts, keyed by context name. */ public function getContexts() { return $this->contexts; } /** * Sets the contexts. * * @param \Drupal\Component\Plugin\Context\ContextInterface[] $contexts * An array of contexts, keyed by context name. * * @return $this */ public function setContexts(array $contexts) { $this->contexts = $contexts; return $this; } /** * {@inheritdoc} */ protected function contextHandler() { return $this->contextHandler; } /** * {@inheritdoc} */ protected function getBlockConfig() { return $this->configuration['blocks']; } /** * {@inheritdoc} */ protected function uuidGenerator() { return $this->uuidGenerator; } /** * {@inheritdoc} */ public function __sleep() { $vars = parent::__sleep(); // Gathered contexts objects should not be serialized. if (($key = array_search('contexts', $vars)) !== FALSE) { unset($vars[$key]); } // The block plugin collection should also not be serialized, ensure that // configuration is synced back. if (($key = array_search('blockPluginCollection', $vars)) !== FALSE) { if ($this->blockPluginCollection) { $this->configuration['blocks'] = $this->blockPluginCollection->getConfiguration(); } unset($vars[$key]); } return $vars; } }