class LibraryItemRevisionDeleteForm

Hierarchy

Expanded class hierarchy of LibraryItemRevisionDeleteForm

1 string reference to 'LibraryItemRevisionDeleteForm'
paragraphs_library.routing.yml in paragraphs/modules/paragraphs_library/paragraphs_library.routing.yml
paragraphs/modules/paragraphs_library/paragraphs_library.routing.yml

File

paragraphs/modules/paragraphs_library/src/Form/LibraryItemRevisionDeleteForm.php, line 13

Namespace

Drupal\paragraphs_library\Form
View source
class LibraryItemRevisionDeleteForm extends ConfirmFormBase {

  /**
   * The library_item revision.
   *
   * @var \Drupal\paragraphs_library\LibraryItemInterface
   */
  protected $revision;

  /**
   * The entity type manager.
   *
   * @var \Drupal\Core\Entity\EntityTypeManagerInterface
   */
  protected $entityTypeManager;

  /**
   * The date formatter service.
   *
   * @var \Drupal\Core\Datetime\DateFormatterInterface
   */
  protected $dateFormatter;

  /**
   * Provides messenger service.
   *
   * @var \Drupal\Core\Messenger\Messenger
   */
  protected $messenger;

  /**
   * LibraryItemRevisionDeleteForm constructor.
   *
   * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
   *   The entity type manager service.
   * @param \Drupal\Core\Datetime\DateFormatterInterface $date_formatter
   *   The date formatter service.
   * @param \Drupal\Core\Messenger\MessengerInterface $messenger
   *   The messenger service.
   */
  public function __construct(EntityTypeManagerInterface $entity_type_manager, DateFormatterInterface $date_formatter, MessengerInterface $messenger) {
    $this->entityTypeManager = $entity_type_manager;
    $this->dateFormatter = $date_formatter;
    $this->messenger = $messenger;
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container) {
    return new static($container
      ->get('entity_type.manager'), $container
      ->get('date.formatter'), $container
      ->get('messenger'));
  }

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

  /**
   * {@inheritdoc}
   */
  public function buildForm(array $form, FormStateInterface $form_state, $paragraphs_library_item_revision = NULL) {
    $this->revision = $this->entityTypeManager
      ->getStorage('paragraphs_library_item')
      ->loadRevision($paragraphs_library_item_revision);
    return parent::buildForm($form, $form_state);
  }

  /**
   * {@inheritdoc}
   */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    $this->entityTypeManager
      ->getStorage('paragraphs_library_item')
      ->deleteRevision($this->revision
      ->getRevisionId());
    $this->messenger
      ->addMessage($this
      ->t('Revision from %revision-date has been deleted.', [
      '%revision-date' => $this->dateFormatter
        ->format($this->revision
        ->getChangedTime()),
    ]));
    $form_state
      ->setRedirect('entity.paragraphs_library_item.version_history', [
      'paragraphs_library_item' => $this->revision
        ->id(),
    ]);
  }

  /**
   * {@inheritdoc}
   */
  public function getCancelUrl() {
    return new Url('entity.paragraphs_library_item.version_history', [
      'paragraphs_library_item' => $this->revision
        ->id(),
    ]);
  }

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

  /**
   * {@inheritdoc}
   */
  public function getQuestion() {
    return $this
      ->t('Are you sure you want to delete revision from %revision-date?', [
      '%revision-date' => $this->dateFormatter
        ->format($this->revision
        ->getChangedTime()),
    ]);
  }

}

Members

Name Modifierssort descending Type Description Overrides
LibraryItemRevisionDeleteForm::$revision protected property The library_item revision.
LibraryItemRevisionDeleteForm::$entityTypeManager protected property The entity type manager.
LibraryItemRevisionDeleteForm::$dateFormatter protected property The date formatter service.
LibraryItemRevisionDeleteForm::$messenger protected property Provides messenger service.
LibraryItemRevisionDeleteForm::__construct public function LibraryItemRevisionDeleteForm constructor.
LibraryItemRevisionDeleteForm::getFormId public function
LibraryItemRevisionDeleteForm::buildForm public function
LibraryItemRevisionDeleteForm::submitForm public function
LibraryItemRevisionDeleteForm::getCancelUrl public function
LibraryItemRevisionDeleteForm::getConfirmText public function
LibraryItemRevisionDeleteForm::getQuestion public function
LibraryItemRevisionDeleteForm::create public static function