Issue #2787529 by Chi, rpayanm, quietone, tobiasb, Ankit.Gupta, smustgrave, larowlan, borisson_, alexpott, ameymudras: Missing configuration schema for current_theme condition plugin
(cherry picked from commit c9e52a8c49
)
merge-requests/3090/head
parent
c26201e48b
commit
2c0f59196c
core/modules/system
config/schema
tests
modules/condition_test
config
install
src/Functional/Condition
|
@ -350,3 +350,10 @@ condition.plugin.request_path:
|
|||
mapping:
|
||||
pages:
|
||||
type: string
|
||||
|
||||
condition.plugin.current_theme:
|
||||
type: condition.plugin
|
||||
mapping:
|
||||
theme:
|
||||
type: string
|
||||
label: Theme
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
# This setting is only used to check if configuration schema exists for these
|
||||
# condition plugins.
|
||||
visibility:
|
||||
current_theme:
|
||||
id: current_theme
|
||||
theme: stable
|
||||
negate: false
|
||||
context_mapping: { }
|
||||
request_path:
|
||||
id: request_path
|
||||
pages: /user
|
||||
negate: false
|
||||
context_mapping: { }
|
|
@ -0,0 +1,10 @@
|
|||
condition_test.settings:
|
||||
type: config_object
|
||||
label: 'Settings'
|
||||
mapping:
|
||||
visibility:
|
||||
type: sequence
|
||||
label: Visibility conditions
|
||||
sequence:
|
||||
type: condition.plugin.[id]
|
||||
label: Visibility condition
|
|
@ -5,12 +5,15 @@ namespace Drupal\condition_test;
|
|||
use Drupal\Core\Form\FormInterface;
|
||||
use Drupal\Core\Condition\ConditionManager;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
use Drupal\Core\Form\SubformState;
|
||||
use Drupal\Core\StringTranslation\StringTranslationTrait;
|
||||
use Drupal\node\Entity\Node;
|
||||
|
||||
/**
|
||||
* Routing controller class for condition_test testing of condition forms.
|
||||
*/
|
||||
class FormController implements FormInterface {
|
||||
use StringTranslationTrait;
|
||||
|
||||
/**
|
||||
* The condition plugin we will be working with.
|
||||
|
@ -19,6 +22,13 @@ class FormController implements FormInterface {
|
|||
*/
|
||||
protected $condition;
|
||||
|
||||
/**
|
||||
* The condition plugin current_theme.
|
||||
*
|
||||
* @var \Drupal\Core\Condition\ConditionInterface
|
||||
*/
|
||||
protected $condition_current_theme;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
@ -32,16 +42,25 @@ class FormController implements FormInterface {
|
|||
public function __construct() {
|
||||
$manager = new ConditionManager(\Drupal::service('container.namespaces'), \Drupal::cache('discovery'), \Drupal::moduleHandler());
|
||||
$this->condition = $manager->createInstance('entity_bundle:node');
|
||||
$this->condition_current_theme = $manager->createInstance('current_theme');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildForm(array $form, FormStateInterface $form_state) {
|
||||
$form = $this->condition->buildConfigurationForm($form, $form_state);
|
||||
$form['#tree'] = TRUE;
|
||||
$form['entity_bundle'] = [];
|
||||
$subformState = SubformState::createForSubform($form['entity_bundle'], $form, $form_state);
|
||||
$form['entity_bundle'] = $this->condition->buildConfigurationForm($form['entity_bundle'], $subformState);
|
||||
|
||||
$form['current_theme'] = [];
|
||||
$subformState = SubformState::createForSubform($form['current_theme'], $form, $form_state);
|
||||
$form['current_theme'] = $this->condition_current_theme->buildConfigurationForm($form['current_theme'], $subformState);
|
||||
|
||||
$form['actions']['submit'] = [
|
||||
'#type' => 'submit',
|
||||
'#value' => t('Submit'),
|
||||
'#value' => $this->t('Submit'),
|
||||
];
|
||||
return $form;
|
||||
}
|
||||
|
@ -50,14 +69,19 @@ class FormController implements FormInterface {
|
|||
* Implements \Drupal\Core\Form\FormInterface::validateForm().
|
||||
*/
|
||||
public function validateForm(array &$form, FormStateInterface $form_state) {
|
||||
$this->condition->validateConfigurationForm($form, $form_state);
|
||||
$subformState = SubformState::createForSubform($form['entity_bundle'], $form, $form_state);
|
||||
$this->condition->validateConfigurationForm($form['entity_bundle'], $subformState);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function submitForm(array &$form, FormStateInterface $form_state) {
|
||||
$this->condition->submitConfigurationForm($form, $form_state);
|
||||
$subformState = SubformState::createForSubform($form['entity_bundle'], $form, $form_state);
|
||||
$this->condition->submitConfigurationForm($form['entity_bundle'], $subformState);
|
||||
$subformState = SubformState::createForSubform($form['current_theme'], $form, $form_state);
|
||||
|
||||
$this->condition_current_theme->submitConfigurationForm($form['current_theme'], $subformState);
|
||||
$config = $this->condition->getConfig();
|
||||
foreach ($config['bundles'] as $bundle) {
|
||||
\Drupal::messenger()->addStatus('Bundle: ' . $bundle);
|
||||
|
@ -66,7 +90,10 @@ class FormController implements FormInterface {
|
|||
$article = Node::load(1);
|
||||
$this->condition->setContextValue('node', $article);
|
||||
if ($this->condition->execute()) {
|
||||
\Drupal::messenger()->addStatus(t('Executed successfully.'));
|
||||
\Drupal::messenger()->addStatus($this->t('Executed successfully.'));
|
||||
}
|
||||
if ($this->condition_current_theme->execute()) {
|
||||
\Drupal::messenger()->addStatus($this->condition_current_theme->summary());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -37,13 +37,21 @@ class ConditionFormTest extends BrowserTestBase {
|
|||
$article->save();
|
||||
|
||||
$this->drupalGet('condition_test');
|
||||
$this->assertSession()->fieldExists('bundles[article]');
|
||||
$this->assertSession()->fieldExists('bundles[page]');
|
||||
$this->submitForm(['bundles[page]' => 'page', 'bundles[article]' => 'article'], 'Submit');
|
||||
$this->assertSession()->fieldExists('entity_bundle[bundles][article]');
|
||||
$this->assertSession()->fieldExists('entity_bundle[bundles][page]');
|
||||
$this->submitForm(['entity_bundle[bundles][page]' => 'page', 'entity_bundle[bundles][article]' => 'article'], 'Submit');
|
||||
// @see \Drupal\condition_test\FormController::submitForm()
|
||||
$this->assertSession()->pageTextContains('Bundle: page');
|
||||
$this->assertSession()->pageTextContains('Bundle: article');
|
||||
$this->assertSession()->pageTextContains('Executed successfully.');
|
||||
|
||||
$this->assertSession()->pageTextContains('The current theme is stark');
|
||||
/** @var \Drupal\Core\Extension\ThemeInstallerInterface $theme_installer */
|
||||
$theme_installer = $this->container->get('theme_installer');
|
||||
$theme_installer->install(['olivero']);
|
||||
$this->drupalGet('condition_test');
|
||||
$this->submitForm(['current_theme[theme]' => 'olivero', 'current_theme[negate]' => TRUE], 'Submit');
|
||||
$this->assertSession()->pageTextContains('The current theme is not olivero');
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue