function thunder_paragraphs_field_widget_paragraphs_form_alter in Thunder 8.5
Same name and namespace in other branches
- 8.2 modules/thunder_paragraphs/thunder_paragraphs.module \thunder_paragraphs_field_widget_paragraphs_form_alter()
- 8.3 modules/thunder_paragraphs/thunder_paragraphs.module \thunder_paragraphs_field_widget_paragraphs_form_alter()
- 8.4 modules/thunder_paragraphs/thunder_paragraphs.module \thunder_paragraphs_field_widget_paragraphs_form_alter()
- 6.2.x modules/thunder_paragraphs/thunder_paragraphs.module \thunder_paragraphs_field_widget_paragraphs_form_alter()
- 6.0.x modules/thunder_paragraphs/thunder_paragraphs.module \thunder_paragraphs_field_widget_paragraphs_form_alter()
- 6.1.x modules/thunder_paragraphs/thunder_paragraphs.module \thunder_paragraphs_field_widget_paragraphs_form_alter()
Implements hook_field_widget_WIDGET_TYPE_form_alter().
Used for Experimental Paragraphs widget.
File
- modules/
thunder_paragraphs/ thunder_paragraphs.module, line 64 - Contains paragraphs related hook implementations and functions.
Code
function thunder_paragraphs_field_widget_paragraphs_form_alter(&$element, FormStateInterface $form_state, $context) {
// Based on logic in ParagraphsWidget::formMultipleElements - execution of
// alter hook for existing paragraphs will be executed first and only with
// list of editable paragraphs. Since all editable paragraphs are processed
// before new paragraphs, we can simply disable "Collapse and save" for any
// following paragraph.
$processing_new_paragraphs = FALSE;
/** @var \Drupal\Core\Field\Plugin\Field\FieldType\EntityReferenceItem $item */
foreach ($context['items'] as $item) {
if ($item
->isEmpty()) {
$processing_new_paragraphs = TRUE;
break;
}
}
_thunder_paragraph_attach_ief_submit($element, [
'top',
'actions',
'actions',
'collapse_button',
], !$processing_new_paragraphs);
}