function paragraphs_library_make_library_item_submit in Paragraphs 8
Make library item submit callback.
Parameters
array $form: The element form array.
\Drupal\Core\Form\FormStateInterface $form_state: The form state object.
1 string reference to 'paragraphs_library_make_library_item_submit'
- paragraphs_library_paragraphs_widget_actions_alter in modules/
paragraphs_library/ paragraphs_library.module - Implements hook_paragraphs_widget_actions_alter().
File
- modules/
paragraphs_library/ paragraphs_library.module, line 110 - Main module file for the Paragraphs Library module.
Code
function paragraphs_library_make_library_item_submit(array $form, FormStateInterface $form_state) {
$submit = ParagraphsWidget::getSubmitElementInfo($form, $form_state, ParagraphsWidget::ACTION_POSITION_ACTIONS);
// Replacing element in the array.
$library_item = LibraryItem::createFromParagraph($submit['widget_state']['paragraphs'][$submit['delta']]['entity']);
// If the item has a moderation field, set it to published.
if ($library_item
->hasField('moderation_state')) {
$library_item
->set('moderation_state', 'published');
}
$library_item
->save();
// Replace this paragraph with a library reference one.
$paragraph_item = [
'entity' => Paragraph::create([
'type' => 'from_library',
'field_reusable_paragraph' => $library_item,
]),
'display' => $submit['widget_state']['paragraphs'][$submit['delta']]['display'],
'mode' => 'edit',
];
$submit['widget_state']['paragraphs'][$submit['delta']] = $paragraph_item;
WidgetBase::setWidgetState($submit['parents'], $submit['field_name'], $form_state, $submit['widget_state']);
$form_state
->setRebuild();
}