openlayers-8.x-4.x-dev/src/Form/MapComponentDeleteForm.php

src/Form/MapComponentDeleteForm.php
<?php

namespace Drupal\openlayers\Form;

use Drupal\Core\Form\ConfirmFormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\openlayers\OpenlayersMapInterface;
use Drupal\openlayers\MapComponent;

/**
 * Form for deleting a map control.
 *
 * @internal
 */
class MapComponentDeleteForm extends ConfirmFormBase {

  /**
   * The map containing the control to be deleted.
   *
   * @var \Drupal\image\ImageControlInterface
   */
  protected $olMap;

  /**
   * The control to be deleted.
   */
  protected $mapComponent;

  /**
   * {@inheritdoc}
   */
  public function getQuestion() {
    return $this->t('Are you sure you want to delete the %component component from the %map map?',
      ['%map' => $this->olMap->label(), '%component' => $this->mapComponent->label()]);
  }

  /**
   * {@inheritdoc}
   */
  public function getConfirmText() {
    return $this->t('Delete');
  }

  /**
   * {@inheritdoc}
   */
  public function getCancelUrl() {
    return $this->olMap->toUrl('edit-form');
  }

  /**
   * {@inheritdoc}
   */
  public function getFormId() {
    return 'ol_control_delete_form';
  }

  /**
   * {@inheritdoc}
   */
  public function buildForm(array $form, FormStateInterface $form_state, OpenlayersMapInterface $map = NULL, $component = NULL) {
    $this->olMap = $map;
    $this->mapComponent = new MapComponent($this->olMap->components[$component], 'delete');

    return parent::buildForm($form, $form_state);
  }

  /**
   * {@inheritdoc}
   */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    $this->olMap->deleteMapComponent($this->mapComponent);
    $this->olMap->save();
    $this->messenger()->addStatus($this->t('The component %name has been deleted from the map.', ['%name' => $this->mapComponent->label()]));
    $form_state->setRedirectUrl($this->olMap->toUrl('edit-form'));
  }

}

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc