function bricks_field_widget_paragraphs_form_alter in Bricks 8
Same name and namespace in other branches
- 2.x bricks.module \bricks_field_widget_paragraphs_form_alter()
Implements hook_field_widget_WIDGET_TYPE_form_alter() for `paragraphs`.
File
- ./
bricks.module, line 154
Code
function bricks_field_widget_paragraphs_form_alter(&$element, \Drupal\Core\Form\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 ? entity_load('paragraph', $item->target_id) : entity_create('paragraph', array(
'type' => $element['subform']['#process'][0][0]
->getTargetBundle(),
));
_bricks_form_element_alter($element, $item, $entity);
hide($element['depth']);
}
}