DashboardConfigureBlockForm.php in Draggable dashboard 8.2
File
src/Form/DashboardConfigureBlockForm.php
View source
<?php
namespace Drupal\draggable_dashboard\Form;
use Drupal\Core\Form\FormStateInterface;
use Drupal\draggable_dashboard\Entity\DashboardEntityInterface;
class DashboardConfigureBlockForm extends DashboardBlockFormBase {
protected $block_id;
public function getFormId() {
return 'draggable_dashboard_configure_block';
}
protected function init(FormStateInterface $form_state, DashboardEntityInterface $dashboard_entity, $block_id = '') {
parent::init($form_state, $dashboard_entity);
$blocks = $dashboard_entity
->get('blocks');
if (!empty($blocks[$block_id])) {
$this->block = $blocks[$block_id];
}
else {
$this->block = [
'settings' => [
'id' => 'broken',
],
];
}
$this->block_id = $block_id;
}
public function buildForm(array $form, FormStateInterface $form_state, DashboardEntityInterface $dashboard_entity = NULL, $block_id = '') {
if (!$form_state
->has('form_initialized')) {
$this
->init($form_state, $dashboard_entity, $block_id);
}
return parent::buildForm($form, $form_state);
}
public function submitForm(array &$form, FormStateInterface $form_state) {
parent::submitForm($form, $form_state);
$blocks = $this->dashboard
->get('blocks') ? $this->dashboard
->get('blocks') : [];
$blocks[$this->block_id]['settings'] = $form_state
->getValue('settings');
$this->dashboard
->set('blocks', $blocks)
->save();
$form_state
->setRedirect('entity.dashboard_entity.edit_form', [
'dashboard_entity' => $this->dashboard
->id(),
]);
}
}