Chris@0: themeManager = $theme_manager; Chris@0: $this->themeHandler = $theme_handler; Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { Chris@0: return new static( Chris@0: $configuration, Chris@0: $plugin_id, Chris@0: $plugin_definition, Chris@0: $container->get('theme.manager'), Chris@0: $container->get('theme_handler') Chris@0: ); Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function defaultConfiguration() { Chris@0: return ['theme' => ''] + parent::defaultConfiguration(); Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function buildConfigurationForm(array $form, FormStateInterface $form_state) { Chris@0: $form['theme'] = [ Chris@0: '#type' => 'select', Chris@0: '#title' => $this->t('Theme'), Chris@0: '#default_value' => $this->configuration['theme'], Chris@0: '#options' => array_map(function ($theme_info) { Chris@0: return $theme_info->info['name']; Chris@0: }, $this->themeHandler->listInfo()), Chris@0: ]; Chris@0: return parent::buildConfigurationForm($form, $form_state); Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function submitConfigurationForm(array &$form, FormStateInterface $form_state) { Chris@0: $this->configuration['theme'] = $form_state->getValue('theme'); Chris@0: parent::submitConfigurationForm($form, $form_state); Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function evaluate() { Chris@0: if (!$this->configuration['theme']) { Chris@0: return TRUE; Chris@0: } Chris@0: Chris@0: return $this->themeManager->getActiveTheme()->getName() == $this->configuration['theme']; Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function summary() { Chris@0: if ($this->isNegated()) { Chris@0: return $this->t('The current theme is not @theme', ['@theme' => $this->configuration['theme']]); Chris@0: } Chris@0: Chris@0: return $this->t('The current theme is @theme', ['@theme' => $this->configuration['theme']]); Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function getCacheContexts() { Chris@0: $contexts = parent::getCacheContexts(); Chris@0: $contexts[] = 'theme'; Chris@0: return $contexts; Chris@0: } Chris@0: Chris@0: }