0

I'm using Panels in page manager to create unique pages with different blocks and panes. I'd like to be able to add settings to each individual pane such as adding a class or style. For example when I edit a block or pane, I receive this window enter image description here

I'd like to be able to add settings here but I'm not sure where to start. In Drupal 7 adding styles to individual panes was clear and I'm not sure it even has that functionality in 8 yet.

1 Answer 1

0

I managed to create what I was after by using the Plugin Api I created module with the file structure

mymodule
   -src
      -Plugin
          -Block
           Block.php

In block PHP I used the following

<?php

/**
 * @file
 * Contains \Drupal\mymodule\Plugin\Block\Basic.
 */

namespace Drupal\mymodule\Plugin\Block;

use Drupal\Core\Block\BlockBase;
use Drupal\Core\Form\FormStateInterface;

/**
 *
 * @Block(
 *   id = "basic_text",
 *   admin_label = @Translation("Basic MyModule Block (basic_text)")
 * )
 */

class Basic extends BlockBase {

    /**
     * {@inheritdoc}
     */
    public function defaultConfiguration() {
        return array(
            'mymodule_string' => $this->t('Enter text here'),
            );
    }

    /**
     * {@inheritdoc}
     */
    public function blockForm($form, FormStateInterface $form_state){
        $form['mymodule_string_text'] = array(
          '#type' => 'textarea',
          '#title' => $this->t('Block contents'),
          '#description' => $this->t('This text will appear in the block.'),
          '#default_value' => $this->configuration['mymodule_string'],
        );
        $form['mymodule_style_selected'] = array(
            '#type' => 'select',
            '#title' => t('Style'),
            '#options' => array(
                0 => t('default'),
                1 => t('black'),
                2 => t('white'),
            ),
            '#default_value' => $this->configuration['mymodule_style'],
        );
        return $form;
    }
    /**
     * {@inheritdoc}
     */
    public function blockSubmit($form, FormStateInterface $form_state) {
        $this->configuration['mymodule_string'] 
         = $form_state->getValue('mymodule_string_text');
    }
    /**
     * {@inheritdoc}
     */
    public function build(){
        return array(
            '#type' => 'markup',
            '#markup' => $this->configuration['mymodule_string'],
        );
    }
}

I haven't implemented the logic handling the style options but I can now place a pane using the IPE and configure the style pane by pane.

1
  • Hi, have tried creating the plugin same as above but not able to see the options from the pane settings.
    – claire
    Commented Apr 18, 2017 at 7:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.