function paragraphs_sets_field_widget_settings_summary_alter in Paragraphs Sets 8.2
Implements hook_field_widget_settings_summary_alter().
File
- ./
paragraphs_sets.module, line 45 - Main functions of paragraphs_sets.module.
Code
function paragraphs_sets_field_widget_settings_summary_alter(&$summary, $context) {
if ($context['widget'] instanceof ParagraphsWidget) {
$settings = $context['widget']
->getThirdPartySettings('paragraphs_sets');
if (isset($settings['paragraphs_sets']['use_paragraphs_sets']) && $settings['paragraphs_sets']['use_paragraphs_sets']) {
$summary[] = t('Show Paragraphs Sets');
}
// Get the list of Paragraphs Sets machine names and display names.
$field_definition = $context['field_definition'];
$field_allowed_paragraphs_types = $context['widget']
->getAllowedTypes($field_definition);
$cardinality = $field_definition
->getFieldStorageDefinition()
->getCardinality();
$sets_options = ParagraphsSets::getSetsOptions(array_keys($field_allowed_paragraphs_types), $cardinality);
// Show "Allowed Paragraphs Sets" in the field widget settings summary.
if ($settings['paragraphs_sets']['use_paragraphs_sets'] ?? FALSE) {
$sets_allowed = array_filter($settings['paragraphs_sets']['sets_allowed'] ?? []);
if ($sets_allowed) {
$sets_allowed_summary = implode(', ', array_intersect_key($sets_options, $sets_allowed));
$summary[] = t('Limit sets to: @sets', [
'@sets' => $sets_allowed_summary,
]);
}
}
// Show "Default Paragraphs Set" in the field widget settings summary.
$default_set = $settings['paragraphs_sets']['default_set'] ?? PARAGRAPHS_SETS_DEFAULT_EMPTY_VALUE;
if ($default_set !== PARAGRAPHS_SETS_DEFAULT_EMPTY_VALUE && isset($sets_options[$default_set])) {
$summary[] = t('Default set: @set', [
'@set' => $sets_options[$default_set],
]);
}
}
}