diff --git a/docroot/modules/custom/yukon_base/yukon_base.module b/docroot/modules/custom/yukon_base/yukon_base.module index 5a381657a..002e58628 100644 --- a/docroot/modules/custom/yukon_base/yukon_base.module +++ b/docroot/modules/custom/yukon_base/yukon_base.module @@ -5,6 +5,32 @@ * Main module file. */ +/** + * Implements hook_form_alter(). + */ +function yukon_base_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id) { + if (!in_array($form_id, ['node_multi_step_page_form', 'node_multi_step_page_edit_form'])) { + return; + } + + if (!isset($form['field_paragraphs']['widget'])) { + return; + } + + $max_steps = 6; + + $item_count = count(array_filter( + array_keys($form['field_paragraphs']['widget']), + fn($key) => is_int($key) + )); + + $form['field_paragraphs']['widget']['#cardinality'] = max($item_count, $max_steps); + + if ($item_count >= $max_steps && isset($form['field_paragraphs']['widget']['add_more'])) { + $form['field_paragraphs']['widget']['add_more']['#access'] = FALSE; + } +} + /** * Implements hook_views_data_alter(). */