You are here

AssetInjectorDisableForm.php in Asset Injector 8.2

Same filename and directory in other branches
  1. 8 src/Form/AssetInjectorDisableForm.php

File

src/Form/AssetInjectorDisableForm.php
View source
<?php

namespace Drupal\asset_injector\Form;

use Drupal;
use Drupal\Core\Entity\EntityConfirmFormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url;

/**
 * Class AssetInjectorDisableForm.
 *
 * @package Drupal\asset_injector\Form
 */
class AssetInjectorDisableForm extends EntityConfirmFormBase {

  /**
   * {@inheritdoc}
   */
  public function getQuestion() {
    return $this
      ->t('Disable @type: %label?', [
      '@type' => $this->entity
        ->getEntityType()
        ->getLabel(),
      '%label' => $this->entity
        ->label(),
    ]);
  }

  /**
   * {@inheritdoc}
   */
  public function getDescription() {
    return $this
      ->t('Disable @type: %label?', [
      '@type' => $this->entity
        ->getEntityType()
        ->getLabel(),
      '%label' => $this->entity
        ->label(),
    ]);
  }

  /**
   * {@inheritdoc}
   */
  public function getCancelUrl() {
    $type = $this->entity
      ->getEntityType()
      ->get('id');
    return new Url("entity.{$type}.collection");
  }

  /**
   * {@inheritdoc}
   */
  public function submitForm(array &$form, FormStateInterface $form_state) {

    /** @var \Drupal\Core\Config\Entity\ConfigEntityInterface $entity */
    $entity = $this->entity;
    $entity
      ->disable()
      ->save();
    Drupal::logger('asset_injector')
      ->notice('%type asset %id disabled', [
      '%type' => $entity
        ->get('entityTypeId'),
      '%id' => $entity->id,
    ]);
    parent::submitForm($form, $form_state);
    $form_state
      ->setRedirectUrl($this
      ->getCancelUrl());
  }

}

Classes

Namesort descending Description
AssetInjectorDisableForm Class AssetInjectorDisableForm.