Running Drupal 9 with paragraphs module, paragraphs collapsible and paragraphs jquery ui accordion installed. I wish to modify paragraphs' form, specifically where it displays private files by adding a 'Switch to Public' checkbox under each file description (see attached image).
I am using hook_field_widget_WIDGET_TYPE_form_alter(). Here is example code:
**
* Implements hook_field_widget_WIDGET_TYPE_form_alter().
*/
function sbn_field_widget_paragraphs_form_alter(&$element, &$form_state, $context) {
if (!empty($element['subform']['field_private_files'])) {
# $element['subform']['field_private_files']['widget'][0]['#default_value']['switch'] = [
# '#type' => 'checkbox',
# '#title' => t('Switch to Public'),
# '#required' => FALSE,
# '#default_value' => FALSE,
# ];
$element['subform']['field_private_files']['widget'][0]['#default_value']['switch'] = array(
'#type' => 'checkbox',
'#title' => t('Switch to public'),
'#size' => 10,
'#maxlength' => 255,
'#default_value' => 1,
'#required' => FALSE,
'#description' => '<p>' . t('Switch from private to public.') . '</p>',
);
// dsm($element);
}
}
I know the array elements are there because I used dsm to print out the entire form if ['subform']['field_private_files'] exists:
[field_private_files] => Array
(
[#type] => container
[#parents] => Array
(
[0] => field_body1
[1] => 7
[2] => subform
[3] => field_body2
[4] => 0
[5] => subform
[6] => field_private_files_wrapper
)
[#attributes] => Array
(
[class] => Array
(
[0] => field--type-file
[1] => field--name-field-private-files
[2] => field--widget-file-generic
[3] => paragraphs-content
)
)
[widget] => Array
(
[0] => Array
(
[#title] => Private Files
[#description] =>
[#field_parents] => Array
(
[0] => field_body1
[1] => 7
[2] => subform
[3] => field_body2
[4] => 0
[5] => subform
)
[#required] =>
[#delta] => 0
[#weight] => 0
[#type] => managed_file
[#upload_location] => private://
[#upload_validators] => Array
(
[file_validate_size] => Array(1)
[file_validate_extensions] => Array(1)
)
[#value_callback] => Array
(
[0] => Drupal\file\Plugin\Field\FieldWidget\FileWidget
[1] => value
)
[#process] => Array
(
[0] => Array(2)
[1] => Array(2)
)
[#progress_indicator] => throbber
[#extended] => 1
[#field_name] => field_private_files
[#entity_type] => paragraph
[#display_field] => 1
[#display_default] => 1
[#description_field] => 1
[#cardinality] => -1
[#default_value] => Array
(
[target_id] => 436
[display] => 1
[description] => Executive Session Minutes 11-15-21
[fids] => Array(1)
)
Any suggestions on how to code this so a checkbox would be printed under the 'description' of each Private Files section of each paragraph (there could be multiple paragraphs attached to each node). Thanks!