You are here

AssetInjectorEnableForm.php in Asset Injector 8

Same filename and directory in other branches
  1. 8.2 src/Form/AssetInjectorEnableForm.php

File

src/Form/AssetInjectorEnableForm.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 AssetInjectorEnableForm.
 *
 * @package Drupal\asset_injector\Form
 */
class AssetInjectorEnableForm extends EntityConfirmFormBase {

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

  /**
   * {@inheritdoc}
   */
  public function getDescription() {
    return $this
      ->t('Enable @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
      ->enable()
      ->save();
    Drupal::logger('asset_injector')
      ->notice('%type asset %id enabled', [
      '%type' => $entity
        ->get('entityTypeId'),
      '%id' => $entity
        ->id(),
    ]);
    parent::submitForm($form, $form_state);
    $form_state
      ->setRedirectUrl($this
      ->getCancelUrl());
  }

}

Classes

Namesort descending Description
AssetInjectorEnableForm Class AssetInjectorEnableForm.