PanelsIPEBlockContentForm.php in Panels 8.3
File
panels_ipe/src/Form/PanelsIPEBlockContentForm.php
View source
<?php
namespace Drupal\panels_ipe\Form;
use Drupal\block_content\BlockContentForm;
use Drupal\Core\Form\FormStateInterface;
class PanelsIPEBlockContentForm extends BlockContentForm {
protected function actions(array $form, FormStateInterface $form_state) {
$button_value = $this
->t('Create and Place');
if (!$this->entity
->isNew()) {
$button_value = $this
->t('Update');
}
$actions['submit'] = [
'#type' => 'button',
'#value' => $button_value,
'#name' => 'panels_ipe_submit',
'#ajax' => [
'callback' => '::submitForm',
'wrapper' => 'panels-ipe-block-type-form-wrapper',
'method' => 'replace',
'progress' => [
'type' => 'throbber',
'message' => '',
],
],
];
return $actions;
}
public function form(array $form, FormStateInterface $form_state) {
$form = parent::form($form, $form_state);
$form['is_new'] = [
'#type' => 'value',
'#value' => $this->entity
->isNew(),
];
$form['#prefix'] = '<div id="panels-ipe-block-type-form-wrapper">';
$form['#suffix'] = '</div>';
return $form;
}
public function submitForm(array &$form, FormStateInterface $form_state) {
$triggering_element = $form_state
->getTriggeringElement();
if ($form_state
->hasAnyErrors() || $triggering_element['#name'] !== 'panels_ipe_submit') {
return $form;
}
parent::submitForm($form, $form_state);
parent::save($form, $form_state);
if ($form_state
->getValue('is_new')) {
$form['#attached']['drupalSettings']['panels_ipe']['new_block_content'] = $this->entity
->uuid();
}
else {
$form['#attached']['drupalSettings']['panels_ipe']['edit_block_content'] = $this->entity
->uuid();
}
return $form;
}
}