diff --git a/config/schema/panels.schema.yml b/config/schema/panels.schema.yml index 4085349..5021232 100644 --- a/config/schema/panels.schema.yml +++ b/config/schema/panels.schema.yml @@ -20,3 +20,14 @@ display_variant.plugin.panels_variant: storage_id: type: string label: Storage Id + css_classes: + type: sequence + label: The list of the display variant CSS classes + sequence: + type: string + html_id: + type: string + label: The HTML Id. of the display variant + css_styles: + type: string + label: The inline CSS styles of the display variant diff --git a/panels.module b/panels.module index fae0eac..c5a3d6c 100644 --- a/panels.module +++ b/panels.module @@ -111,3 +111,26 @@ function panels_form_page_manager_add_variant_form_submit(array &$form, FormStat $plugin->setStorage('page_manager', $page_variant->id()); } } + +/** + * Implements hook_config_schema_info_alter(). + */ +function panels_config_schema_info_alter(&$definitions) { + $definitions['ctools.block_plugin.*']['mapping'] += [ + 'css_classes' => [ + 'type' => 'sequence', + 'label' => 'The list of the display variant CSS classes', + 'sequence' => [ + 'type' => 'string', + ], + ], + 'html_id' => [ + 'type' => 'string', + 'label' => 'The HTML Id. of the display variant', + ], + 'css_styles' => [ + 'type' => 'string', + 'label' => 'The inline CSS styles of the display variant', + ], + ]; +} diff --git a/panels_ipe/src/Form/PanelsIPEBlockPluginForm.php b/panels_ipe/src/Form/PanelsIPEBlockPluginForm.php index a13ba9a..4a2a5e6 100644 --- a/panels_ipe/src/Form/PanelsIPEBlockPluginForm.php +++ b/panels_ipe/src/Form/PanelsIPEBlockPluginForm.php @@ -3,6 +3,7 @@ namespace Drupal\panels_ipe\Form; use Drupal\Component\Plugin\PluginManagerInterface; +use Drupal\Component\Utility\Html; use Drupal\Core\Block\BlockPluginInterface; use Drupal\Core\Form\FormBase; use Drupal\Core\Form\FormState; @@ -11,6 +12,7 @@ use Drupal\Core\Plugin\Context\ContextHandlerInterface; use Drupal\Core\Plugin\ContextAwarePluginAssignmentTrait; use Drupal\Core\Plugin\ContextAwarePluginInterface; use Drupal\Core\Render\RendererInterface; +use Drupal\panels\Form\PanelsStyleTrait; use Drupal\panels\Plugin\DisplayVariant\PanelsDisplayVariant; use Drupal\panels_ipe\PanelsIPEBlockRendererTrait; use Drupal\Core\TempStore\SharedTempStoreFactory; @@ -27,6 +29,7 @@ class PanelsIPEBlockPluginForm extends FormBase { use ContextAwarePluginAssignmentTrait; use PanelsIPEBlockRendererTrait; + use PanelsStyleTrait; /** * @var \Drupal\Component\Plugin\PluginManagerInterface @@ -183,6 +186,7 @@ class PanelsIPEBlockPluginForm extends FormBase { '#required' => TRUE, '#default_value' => $region, ]; + $form['flipper']['front']['settings'] += $this->getCssStyleForm($block_config, TRUE); // Add an add button, which is only used by our App. $form['submit'] = [ @@ -276,6 +280,21 @@ class PanelsIPEBlockPluginForm extends FormBase { // Set the block region appropriately. $block_config = $block_instance->getConfiguration(); $block_config['region'] = $form_state->getValue(['settings', 'region']); + $block_config['css_classes'] = preg_split('/\s+/', trim($form_state->getValue([ + 'settings', + 'style_settings', + 'css_classes', + ]))); + $block_config['html_id'] = $form_state->getValue([ + 'settings', + 'style_settings', + 'html_id', + ]); + $block_config['css_styles'] = $form_state->getValue([ + 'settings', + 'style_settings', + 'css_styles', + ]); // Determine if we need to update or add this block. if ($uuid = $form_state->getValue('uuid')) { @@ -298,6 +317,19 @@ class PanelsIPEBlockPluginForm extends FormBase { // Add our data attribute for the Backbone app. $build['#attributes']['data-block-id'] = $uuid; + // Add CSS classes. + foreach ($block_config['css_classes'] as $class) { + $build['#attributes']['class'][] = Html::cleanCssIdentifier($class); + } + // Add HTML Id. + if (!empty($block_config['html_id'])) { + $build['#attributes']['id'] = Html::getId($block_config['html_id']); + } + // Add CSS styles. + if (!empty($block_config['css_styles'])) { + $build['#attributes']['style'] = $block_config['css_styles']; + } + $plugin_definition = $block_instance->getPluginDefinition(); $block_model = [ @@ -344,6 +376,30 @@ class PanelsIPEBlockPluginForm extends FormBase { // Gather a render array for the block. $build = $this->buildBlockInstance($block_instance, $this->panelsDisplay); + // Add CSS classes. + $css_classes = preg_split('/\s+/', trim($form_state->getValue([ + 'settings', + 'style_settings', + 'css_classes', + ]))); + foreach ($css_classes as $class) { + $build['#attributes']['class'][] = Html::cleanCssIdentifier($class); + } + // Add HTML Id. + $html_id = $form_state->getValue(['settings', 'style_settings', 'html_id']); + if (!empty($html_id)) { + $build['#attributes']['id'] = Html::getId($html_id); + } + // Add CSS styles. + $css_styles = $form_state->getValue([ + 'settings', + 'style_settings', + 'css_styles', + ]); + if (!empty($css_styles)) { + $build['#attributes']['style'] = $css_styles; + } + // Replace any nested form tags from the render array. $build['content']['#post_render'][] = function ($html, array $elements) { $search = ['