0

I manage to build/define some custom blocks with my own parameters/form elements when placing them, so I'm looking to do the same with sections. I've seen that the core code does that, but ideally I would like to add more form elements to that interface and allow the editors to customise a bit more the abilities of each section. I found the core file that contains the functions but doesn't feel right to me to just copy the whole file and modify it for my purpose.

I also found this module that seems that does what I'm after but has some issues I think.

I made a layout module in order to define some basic layouts (4 of them) and now I'm trying to do the above. The code is as follow:

hs_layout.module file

/**
 * Implements hook_form_alter().
 */
function hs_layout_form_layout_builder_add_block_alter(array &$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id) {
  $form['settings']['admin_label'] = [];
  $form['settings']['label'] = [];
  $form['settings']['label_display'] = [];
}

/**
 * Implements hook_form_alter().
 */
function hs_layout_form_layout_builder_update_block_alter(array &$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id) {
  $form['settings']['admin_label'] = [];
  $form['settings']['label'] = [];
  $form['settings']['label_display'] = [];
}

HsOneColumnLayout.php file

namespace Drupal\hs_layout\Plugin;

use Drupal\Core\Layout\LayoutDefault;
use Drupal\Core\Plugin\PluginFormInterface;

/**
 * Class HsOneColumnLayout.
 *
 * @package Drupal\hs_layout\Plugin
 */
class HsOneColumnLayout extends LayoutDefault implements PluginFormInterface {
}
4
  • 1
    This question doesn't really fit DA's narrow question & answer format. Please take a look at the docs first and create a new, more specific question if any problems arise.
    – Hudri
    May 10 at 9:48
  • It is specific, because I need a way to add options to my custom layout sections. How much more specific than that?
    – Alimba
    May 10 at 10:30
  • So can you show us your code, what have you tried and which problem couldn't be solved? Asking for any documentation and a methodology is not specific at all.
    – Hudri
    May 10 at 10:40
  • I edited the question with some of the code I use to define the layouts.
    – Alimba
    May 10 at 10:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.