You are here

ConfigEntityRevisionsEditFormTrait.php in Config Entity Revisions 8.2

File

src/ConfigEntityRevisionsEditFormTrait.php
View source
<?php

namespace Drupal\config_entity_revisions;

use Drupal\Core\Form\FormStateInterface;

/**
 * Trait ConfigEntityRevisionsEditFormTrait.
 *
 * @package Drupal\config_entity_revisions
 */
trait ConfigEntityRevisionsEditFormTrait {

  /**
   * {@inheritdoc}
   */
  public function save(array $form, FormStateInterface $form_state) {
    parent::save($form, $form_state);
    $entity = $this
      ->getEntity();
    if ($entity instanceof ConfigEntityRevisionsConfigEntityContainerInterface) {
      $revId = $entity
        ->revisionedEntity()
        ->get('loadedRevisionId');
      $cacheId = $revId ? $entity
        ->id() . '-' . $revId : $entity
        ->id();
      $this->tempStore
        ->delete($cacheId);
    }
  }

  /**
   * Form submission handler for the 'cancel' action.
   *
   * @param array $form
   *   An associative array containing the structure of the form.
   * @param \Drupal\Core\Form\FormStateInterface $form_state
   *   The current state of the form.
   */
  public function cancel(array $form, FormStateInterface $form_state) {

    // Remove this view from cache so edits will be lost.
    parent::cancel($form, $form_state);
    $entity = $this
      ->getEntity();
    if ($entity instanceof ConfigEntityRevisionsConfigEntityContainerInterface) {
      $revId = $entity
        ->revisionedEntity()
        ->get('loadedRevisionId');
      $cacheId = $revId ? $entity
        ->id() . '-' . $revId : $entity
        ->id();
      $this->tempStore
        ->delete($cacheId);
    }
  }

}

Traits

Namesort descending Description
ConfigEntityRevisionsEditFormTrait Trait ConfigEntityRevisionsEditFormTrait.