You are here

function bricks_field_widget_paragraphs_form_alter in Bricks​ 2.x

Same name and namespace in other branches
  1. 8 bricks.module \bricks_field_widget_paragraphs_form_alter()

Implements hook_field_widget_WIDGET_TYPE_form_alter() for `paragraphs`.

File

./bricks.module, line 250

Code

function bricks_field_widget_paragraphs_form_alter(&$element, FormStateInterface $form_state, $context) {
  $field_type = $context['items']
    ->getFieldDefinition()
    ->getType();

  // @TODO: Replace by 'Nested bricks' widget setting.
  if (in_array($field_type, [
    'bricks_revisioned',
  ])) {

    // @TODO: Find a better way to be used in _bricks_preprocess_tabledrag_form().
    $element['#widget'] = 'paragraphs';
    $item = $context['items'][$context['delta']];
    $entity = $item->target_id ? \Drupal::entityTypeManager()
      ->getStorage('paragraph')
      ->load($item->target_id) : Paragraph::create([
      'type' => $element['subform']['#process'][0][0]
        ->getTargetBundle(),
    ]);
    _bricks_form_element_alter($element, $item, $entity);
    hide($element['depth']);
  }
}