X-Git-Url: http://aleph1.co.uk/gitweb/?a=blobdiff_plain;ds=sidebyside;f=web%2Fmodules%2Fcontrib%2Fctools%2Fsrc%2FPlugin%2FDisplayVariant%2FBlockDisplayVariant.php;fp=web%2Fmodules%2Fcontrib%2Fctools%2Fsrc%2FPlugin%2FDisplayVariant%2FBlockDisplayVariant.php;h=32c6e86fd0f548b332a5d1afdb3caecd8fdda3ee;hb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;hp=0000000000000000000000000000000000000000;hpb=57c063afa3f66b07c4bbddc2d6129a96d90f0aad;p=yaffs-website diff --git a/web/modules/contrib/ctools/src/Plugin/DisplayVariant/BlockDisplayVariant.php b/web/modules/contrib/ctools/src/Plugin/DisplayVariant/BlockDisplayVariant.php new file mode 100644 index 000000000..32c6e86fd --- /dev/null +++ b/web/modules/contrib/ctools/src/Plugin/DisplayVariant/BlockDisplayVariant.php @@ -0,0 +1,226 @@ +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; + } + +}