Thanks for all of the hard work porting Block Class to D8!

It works great for the core block.module but it would be great if it supported block display variants added to pages via the Page Manager module.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Devin Carlson’s picture

Status: Active » Needs review
FileSize
3.23 KB

A starting patch. There's probably a cleaner way to do this.

samuel.mortenson’s picture

FileSize
3.23 KB

Looks like the index for $page has changed, re-rolling.

Berdir’s picture

  1. +++ b/block_class.module
    @@ -29,6 +30,52 @@ function block_class_form_block_form_alter(&$form, \Drupal\Core\Form\FormStateIn
    +  switch ($form_id) {
    +    case 'page_manager_display_variant_add_block_form':
    +    case 'page_manager_display_variant_edit_block_form':
    +      if (\Drupal::currentUser()->hasPermission('administer block classes')) {
    +        $display_variant_id = $form_state->get('display_variant_id');
    

    What about opening an issue in page_manager to add a common base form id for those two forms so that form altering is easier?

  2. +++ b/block_class.module
    @@ -29,6 +30,52 @@ function block_class_form_block_form_alter(&$form, \Drupal\Core\Form\FormStateIn
    +        $page = $form_state->getBuildInfo()['args'][1];
    +        $display_variant = $page->getVariant($display_variant_id);
    +        $block = $display_variant->getBlock($block_id);
    

    Same here, would be nice if those forms would explicitly add the page/display to $form_state so that use cases like this don't need to mess with build info arguments.

  3. +++ b/block_class.module
    @@ -29,6 +30,52 @@ function block_class_form_block_form_alter(&$form, \Drupal\Core\Form\FormStateIn
    +        $configuration = $block->getConfiguration();
    +
    +        $form['settings']['classes'] = [
    +          '#type' => 'textfield',
    +          '#title' => t('CSS class(es)'),
    +          '#description' => t('Customize the styling of this block by adding CSS classes. Separate multiple classes by spaces.'),
    +          '#default_value' => isset($configuration['classes']) ? $configuration['classes'] : NULL,
    +        ];
    +
    +        $form['#submit'][] = 'block_class_page_manager_display_variant_block_form_submit';
    
    +++ b/config/schema/block_class.schema.yml
    @@ -5,3 +5,11 @@ block.block.*.third_party.block_class:
    +page_manager.block_plugin.*.block_class:
    +  type: mapping
    

    Does this really work? I doubt it...

    We possibly need to store this using the third party settings API directly on the page, keyed by display.block UUID or so. But that's tricky too, how will we access it then..

    Possibly page_manager, (which needs config schema fixes anyway since what it does now doesn't fly) should provide a third-party-settings like place to store things per-block

s_leu’s picture

Adding a patch that covers suggestions in #3

Does this really work? I doubt it...

This does in fact work. Also i don't see the need for this third party schema key as classes is actually pretty self explaining and in the right place as well. So i didn't change anything there.

Rajab Natshah’s picture

Testing this patch.

Berdir’s picture

Status: Needs review » Needs work

I can't imagine that this still works, will definitely need a reroll.

Rajab Natshah’s picture

Still we can not see the CSS class(es) .. I used patch #4
I will try to use m patch #2

Rajab Natshah’s picture

Patch #2 is not working too!!!

I will be working to have a working patch.

Yaron Tal’s picture

Project: Block Class D8 » Block Class
Version: » 8.x-1.x-dev
mpp’s picture

It's not clear how this could work but I guess the problem here is that page_manager is not adding the block ID. Not that we can't hack into page_manager to add another configuration.

Take this use case for example: a user creates a custom block and decides to give it a class using block_class. The user then adds this block to a page using page_manager.
It wouldn't make sense to create another setting for this block.

dobrzyns’s picture

@mpp. I actually can see it making sense to have class settings for both the instance (when added using page_manager) and at the custom block level, where the two settings could be different. However, I'm not sure if the former should be implemented (at least to start).

The patch in #4 does not work for me either.

@berdir Makes excellent points in #3.

dobrzyns’s picture

Looks like this duplicates https://www.drupal.org/node/2710169

samuel.mortenson’s picture

At this point I think that it's a Core issue that Block Plugins can't generically be altered to allow for custom form elements and configuration. It should only take one alter hook and one submit handler to add Block Class support for all Block Plugin use cases (Page Manager, Panelizer, Panels IPE, Core Block Entities, etc.).

andypost’s picture

berenddeboer’s picture

Status: Needs work » Closed (outdated)