diff -u b/config/schema/paragraphs_collection.schema.yml b/config/schema/paragraphs_collection.schema.yml --- b/config/schema/paragraphs_collection.schema.yml +++ b/config/schema/paragraphs_collection.schema.yml @@ -2,17 +2,24 @@ type: paragraphs.behavior.settings_base mapping: group: - type: sequence + type: string label: Style group + groups: + type: sequence + label: 'Messages' sequence: type: string + label: 'Message' default: type: string label: Default style - deafults: + defaults: type: sequence + label: 'Test' sequence: type: string + label: 'Test' + paragraphs.behavior.settings.grid_layout: type: paragraphs.behavior.settings_base mapping: diff -u b/src/Plugin/paragraphs/Behavior/ParagraphsStylePlugin.php b/src/Plugin/paragraphs/Behavior/ParagraphsStylePlugin.php --- b/src/Plugin/paragraphs/Behavior/ParagraphsStylePlugin.php +++ b/src/Plugin/paragraphs/Behavior/ParagraphsStylePlugin.php @@ -80,13 +80,27 @@ 'id' => $wrapper_id, ], ]; - $form['style_wrapper']['style'] = [ - '#type' => 'select', - '#options' => $this->getStyleOptions($this->configuration['group'], $this->configuration['default']), - '#default_value' => $paragraph->getBehaviorSetting($this->getPluginId(), 'style', $this->configuration['default']), - '#title' => !empty($this->configuration['group']) ? t('%group Style', ['%group' => $this->configuration['group']]) : t('Style'), - '#attributes' => ['class' => ['paragraphs-style']], - ]; + if (count($this->configuration['groups']) > 1) { + foreach ($this->configuration['groups'] as $group) { + $group_id = strtolower(str_replace(' ', '_', $group)); + $form['style_wrapper']['style'][$group_id] = [ + '#type' => 'select', + '#options' => $this->getStyleOptions($group, $this->configuration['defaults'][$group_id]), + '#default_value' => $paragraph->getBehaviorSetting($this->getPluginId(), 'style', $this->configuration['default']), + '#title' => !empty($this->configuration['group']) ? t('%group Style', ['%group' => $this->configuration['group']]) : t('Style'), + '#attributes' => ['class' => ['paragraphs-style']], + ]; + } + } + else { + $form['style_wrapper']['style'] = [ + '#type' => 'select', + '#options' => $this->getStyleOptions($this->configuration['group'], $this->configuration['default']), + '#default_value' => $paragraph->getBehaviorSetting($this->getPluginId(), 'style', $this->configuration['default']), + '#title' => !empty($this->configuration['group']) ? t('%group Style', ['%group' => $this->configuration['group']]) : t('Style'), + '#attributes' => ['class' => ['paragraphs-style']], + ]; + } // Allow empty option in case there is no default style configured. if (!$this->configuration['default']) { $form['style_wrapper']['style']['#empty_option'] = $this->t('- Default -'); @@ -128,22 +142,22 @@ * {@inheritdoc} */ public function buildConfigurationForm(array $form, FormStateInterface $form_state) { - $form['group'] = [ + $form['groups'] = [ '#type' => 'select', '#multiple' => TRUE, '#empty_option' => $this->t('- None -'), '#options' => $this->yamlStyleDiscovery->getStyleGroups(), - '#title' => $this->t('Style group'), + '#title' => $this->t('Style groups'), '#description' => $this->t('Restrict available styles to a certain style group. Select "- None -" to allow all styles.'), - '#default_value' => $this->configuration['group'], + '#default_value' => $this->configuration['groups'], '#ajax' => [ 'callback' => [$this, 'updateDefaultStyle'], 'wrapper' => 'style-wrapper', ], ]; // @todo: Remove getCompleteFormState() after https://www.drupal.org/project/drupal/issues/2798261. - $group_key = ['behavior_plugins', $this->getPluginId(), 'settings', 'group']; - $groups = $form_state->getCompleteFormState()->getValue($group_key, $this->configuration['group']); + $group_key = ['behavior_plugins', $this->getPluginId(), 'settings', 'groups']; + $groups = $form_state->getCompleteFormState()->getValue($group_key, $this->configuration['groups']); if (count($groups) > 1) { $form['defaults'] = [ '#type' => 'container', @@ -153,11 +167,11 @@ foreach($groups as $group) { $form['defaults'][strtolower(str_replace(' ', '_', $group))] = [ '#type' => 'select', + '#title' => $this->t($group . ' default style'), '#empty_option' => $this->t('- None -'), '#options' => $this->yamlStyleDiscovery->getStyleOptions($group), - '#title' => $this->t('Default style'), '#description' => $this->t('This style will be default option on a behavior form.'), - '#default_value' => $this->configuration['default'], + '#default_value' => $this->configuration['defaults'][strtolower(str_replace(' ', '_', $group))], ]; } } @@ -207,8 +221,9 @@ * {@inheritdoc} */ public function submitConfigurationForm(array &$form, FormStateInterface $form_state) { - $this->configuration['group'] = $form_state->getValue('group'); + $this->configuration['groups'] = $form_state->getValue('groups'); $this->configuration['default'] = $form_state->getValue('default'); + $this->configuration['defaults'] = $form_state->getValue('defaults'); } /** @@ -216,8 +231,9 @@ */ public function defaultConfiguration() { return [ - 'group' => '', + 'groups' => [], 'default' => '', + 'defaults' => [], ]; } only in patch2: unchanged: --- a/src/Tests/ParagraphsStylePluginTest.php +++ b/src/Tests/ParagraphsStylePluginTest.php @@ -48,11 +48,11 @@ class ParagraphsStylePluginTest extends ParagraphsExperimentalTestBase { // Add a text field. $this->fieldUIAddExistingField('admin/structure/paragraphs_type/' . $paragraph_type, 'paragraphs_text', $paragraph_type); $this->drupalGet('admin/structure/paragraphs_type/' . $paragraph_type); - $this->assertFieldByName('behavior_plugins[style][settings][group]', ''); + $this->assertFieldByName('behavior_plugins[style][settings][groups]', ''); $this->assertFieldByName('behavior_plugins[style][settings][default]', ''); $edit = [ 'behavior_plugins[style][enabled]' => TRUE, - 'behavior_plugins[style][settings][group]' => '', + 'behavior_plugins[style][settings][groups]' => '', 'behavior_plugins[style][settings][default]' => '', ]; $this->drupalPostForm(NULL, $edit, t('Save')); @@ -83,10 +83,10 @@ class ParagraphsStylePluginTest extends ParagraphsExperimentalTestBase { // Restrict the paragraphs type to the "Italic Test Group" style group. $this->drupalGet('admin/structure/paragraphs_type/' . $paragraph_type); - $this->assertFieldByName('behavior_plugins[style][settings][group]', ''); + $this->assertFieldByName('behavior_plugins[style][settings][groups]', ''); $edit = [ 'behavior_plugins[style][enabled]' => TRUE, - 'behavior_plugins[style][settings][group]' => 'Italic Test Group', + 'behavior_plugins[style][settings][groups]' => 'Italic Test Group', ]; $this->drupalPostForm(NULL, $edit, t('Save')); @@ -112,7 +112,7 @@ class ParagraphsStylePluginTest extends ParagraphsExperimentalTestBase { $this->drupalGet('admin/structure/paragraphs_type/' . $paragraph_type); $this->assertFieldByName('behavior_plugins[style][settings][default]', ''); $edit = [ - 'behavior_plugins[style][settings][group]' => 'Regular Test Group', + 'behavior_plugins[style][settings][groups]' => 'Regular Test Group', ]; $this->drupalPostAjaxForm(NULL, $edit, 'behavior_plugins[style][settings][group]'); $edit = [