MapControlDeleteForm.php in Openlayers 8.4
File
src/Form/MapControlDeleteForm.php
View source
<?php
namespace Drupal\openlayers\Form;
use Drupal\Core\Form\ConfirmFormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\openlayers\OpenlayersMapInterface;
use Drupal\openlayers\MapControl;
class MapControlDeleteForm extends ConfirmFormBase {
protected $olMap;
protected $mapControl;
public function getQuestion() {
return $this
->t('Are you sure you want to delete the %control control from the %map map?', [
'%map' => $this->olMap
->label(),
'%control' => $this->mapControl
->label(),
]);
}
public function getConfirmText() {
return $this
->t('Delete');
}
public function getCancelUrl() {
return $this->olMap
->toUrl('edit-form');
}
public function getFormId() {
return 'ol_control_delete_form';
}
public function buildForm(array $form, FormStateInterface $form_state, OpenlayersMapInterface $map = NULL, $control = NULL) {
$this->olMap = $map;
$this->mapControl = new MapControl($this->olMap->controls[$control], 'delete');
return parent::buildForm($form, $form_state);
}
public function submitForm(array &$form, FormStateInterface $form_state) {
$this->olMap
->deleteMapControl($this->mapControl);
$this->olMap
->save();
$this
->messenger()
->addStatus($this
->t('The control %name has been deleted from the map.', [
'%name' => $this->mapControl
->label(),
]));
$form_state
->setRedirectUrl($this->olMap
->toUrl('edit-form'));
}
}