function paragraphs_inline_entity_form_form_alter in Paragraphs Inline Entity Form 2.x
Same name and namespace in other branches
- 8 paragraphs_inline_entity_form.module \paragraphs_inline_entity_form_form_alter()
- 2.0.x paragraphs_inline_entity_form.module \paragraphs_inline_entity_form_form_alter()
Implements hook_form_alter().
File
- ./
paragraphs_inline_entity_form.module, line 14 - Module.
Code
function paragraphs_inline_entity_form_form_alter(&$form, FormStateInterface $form_state, $form_id) {
/* @var Drupal\Core\Entity\FieldableEntityInterface $entity */
$formObject = $form_state
->getFormObject();
if ($formObject instanceof EntityFormInterface) {
$form['#attached']['library'][] = 'paragraphs_inline_entity_form/dialog';
}
if ($formObject instanceof EntityEmbedDialog) {
if (paragraphs_inline_entity_form_entity_browser_is_paragraph_item($form)) {
$form['#attached']['library'][] = 'paragraphs_inline_entity_form/dialog';
switch ($form_state
->get('step')) {
case 'select':
break;
case 'embed':
// Change the back button to link to the paragraph edit form.
$entity_uuid = $form['attributes']['data-entity-uuid']['#value'];
$entity_type_manager = \Drupal::service('entity_type.manager');
$entity = $entity_type_manager
->getStorage('paragraph')
->loadByProperties([
'uuid' => $entity_uuid,
]);
$paragraph = current($entity);
$form['actions']['back'] = [
'#type' => 'submit',
'#value' => t('Back'),
'#submit' => [],
'#ajax' => [
'url' => Url::fromRoute('entity_browser.edit_form', [
'entity_type' => 'paragraph',
'entity' => $paragraph
->id(),
]),
'event' => 'click',
],
];
//@todo update widget
// $details_id = $request->query->get('details_id');
// if (!empty($details_id)) {
// $response->addCommand(new ValueUpdatedCommand($details_id));
// }
// return $response;
break;
}
}
}
}