public function FormAlter::alterEntityViewDisplayFormAllowedBlockCategories in Dashboards with Layout Builder 2.0.x
The actual form elements.
File
- src/
Form/ FormAlter.php, line 86
Class
- FormAlter
- Supplement form UI to add setting for which blocks & layouts are available.
Namespace
Drupal\dashboards\FormCode
public function alterEntityViewDisplayFormAllowedBlockCategories(&$form, FormStateInterface $form_state, $form_id) {
$display = $form_state
->getFormObject()
->getEntity();
$is_enabled = $display
->isLayoutBuilderEnabled();
if ($is_enabled) {
$form['#entity_builders'][] = [
$this,
'entityFormEntityBuild',
];
$allowed_block_categories = $display
->getThirdPartySetting('layout_builder_restrictions', 'allowed_block_categories', []);
$form['layout']['layout_builder_restrictions']['allowed_block_categories'] = [
'#title' => $this
->t('Default restriction for new categories of blocks not listed below.'),
'#description_display' => 'before',
'#type' => 'radios',
'#options' => [
"allowed" => $this
->t('Allow all blocks from newly available categories.'),
"restricted" => $this
->t('Restrict all blocks from newly available categories.'),
],
'#parents' => [
'layout_builder_restrictions',
'allowed_block_categories',
],
'#default_value' => !empty($allowed_block_categories) ? "restricted" : "allowed",
];
}
}