You are here

MollieProfileDeleteForm.php in Mollie Payment 8.2

File

src/Entity/MollieProfile/MollieProfileDeleteForm.php
View source
<?php

namespace Drupal\mollie_payment\Entity\MollieProfile;

use Drupal\Core\Entity\EntityConfirmFormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\StringTranslation\TranslationInterface;
use Psr\Log\LoggerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
 * Provides the Mollie profile deletion form.
 */
class MollieProfileDeleteForm extends EntityConfirmFormBase {

  /**
   * The logger.
   *
   * @var \Psr\Log\LoggerInterface
   */
  protected $logger;

  /**
   * Constructs a new instance.
   *
   * @param \Drupal\Core\StringTranslation\TranslationInterface $string_translation
   *   The string translator.
   * @param \Psr\Log\LoggerInterface $logger
   */
  public function __construct(TranslationInterface $string_translation, LoggerInterface $logger) {
    $this->logger = $logger;
    $this->stringTranslation = $string_translation;
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container) {
    return new static($container
      ->get('string_translation'), $container
      ->get('mollie_payment.logger'));
  }

  /**
   * {@inheritdoc}
   */
  public function getQuestion() {
    return $this
      ->t('Do you really want to delete %label?', [
      '%label' => $this
        ->getEntity()
        ->label(),
    ]);
  }

  /**
   * {@inheritdoc}
   */
  public function getCancelUrl() {
    return $this
      ->getEntity()
      ->toUrl('collection');
  }

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

  /**
   * {@inheritdoc}
   */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    $this
      ->getEntity()
      ->delete();
    $this->logger
      ->info('Mollie profile %label (@id) has been deleted.', [
      '@id' => $this
        ->getEntity()
        ->id(),
      '%label' => $this
        ->getEntity()
        ->label(),
    ]);
    drupal_set_message($this
      ->t('%label has been deleted.', [
      '%label' => $this
        ->getEntity()
        ->label(),
    ]));
    $form_state
      ->setRedirectUrl($this
      ->getEntity()
      ->toUrl('collection'));
  }

}

Classes

Namesort descending Description
MollieProfileDeleteForm Provides the Mollie profile deletion form.