Programm fill block_field in paragraph

Created on 23 August 2023, about 1 year ago

Problem/Motivation

Hello everyone, can you help me set default values for block_field?

I have content type with fields:
field_blocks (block_field type)
field_override_blocks (paragraph)
--field_blocks (block_field type in paragraph)

when I add a new paragraph I want to set the same blocks from field_blocks in field_blocks which in paragraph

I tried to use next code

/**
 * Implements hook_field_widget_WIDGET_TYPE_form_alter().
 */
function MODULE_field_widget_paragraphs_form_alter(&$element, &$form_state, $context) {
............
      //Code just for demo.
      $element['subform']['field_blocks']['widget'][0]['plugin_id']['#default_value'] = 'content_hub_main_block';
      $element['subform']['field_blocks']['widget'][1] = $element['subform']['field_blocks']['widget'][0];//strange things for copy structure
      $element['subform']['field_blocks']['widget'][1]['plugin_id']['#default_value'] = 'content_hub_3d_models_category_block';
..........
}

but when I add a new paragraph item my previous items removed all except 0 index.

I reserched thiw two days and can't understand why it doesn't works. For example I used some other contrib fields and it work good.

💬 Support request
Status

Active

Component

Code

Created by

🇧🇾Belarus mozh92

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024