function paragraphs_preprocess_field_multiple_value_form in Paragraphs 8
Implements hook_preprocess_HOOK() for field_multiple_value_form().
File
- ./
paragraphs.module, line 353 - Contains paragraphs.module
Code
function paragraphs_preprocess_field_multiple_value_form(&$variables) {
if (!empty($variables['table']['#header']) && isset($variables['table']['#rows'])) {
// Find paragraph_actions and move to header.
// @see template_preprocess_field_multiple_value_form()
if (!empty($variables['table']['#rows'][0]['data'][1]['data']['#paragraphs_header'])) {
$variables['table']['#header'][0]['data'] = [
'title' => $variables['table']['#header'][0]['data'],
'button' => $variables['table']['#rows'][0]['data'][1]['data'],
];
unset($variables['table']['#rows'][0]);
}
// Add the paragraph type as a class to every row.
if (isset($variables['element']['#paragraphs_widget'])) {
foreach ($variables['table']['#rows'] as $key => $row) {
if (isset($row['data'][1]['data']['#paragraph_type'])) {
$variables['table']['#rows'][$key]['class'][] = 'paragraph-type--' . str_replace('_', '-', $row['data'][1]['data']['#paragraph_type']);
}
}
}
}
// Remove the drag handler if we are translating, if the field's cardinality
// is 1 or if there are no paragraphs added. Passing through this will not
// only remove the drag handler but also the order column that is empty when
// no paragraphs are added and when the field is single value.
if (isset($variables['element']['#allow_reference_changes']) && !$variables['element']['#allow_reference_changes'] || isset($variables['element']['#cardinality']) && $variables['element']['#cardinality'] == 1 || isset($variables['table']['#rows']) && count($variables['table']['#rows']) == 0) {
if (isset($variables['table']['#tabledrag'])) {
// Remove the tabledrag.
unset($variables['table']['#tabledrag']);
unset($variables['table']['#header'][1]);
foreach ($variables['table']['#rows'] as $key => $value) {
$variables['table']['#rows'][$key]['data'][0]['class'][] = 'paragraph-bullet';
// Restore the removed weight and give access FALSE.
$variables['table']['#rows'][$key]['data'][1]['data']['_weight'] = $value['data'][2]['data'];
unset($variables['table']['#rows'][$key]['data'][2]);
$variables['table']['#rows'][$key]['data'][1]['data']['_weight']['#access'] = FALSE;
}
}
}
}