You are here

WebformRevision.php in Config Entity Revisions 8.2

File

modules/webform_revisions/src/Entity/WebformRevision.php
View source
<?php

namespace Drupal\webform_revisions\Entity;

use Drupal\config_entity_revisions\ConfigEntityRevisionsConfigEntityInterface;
use Drupal\config_entity_revisions\ConfigEntityRevisionsConfigEntityTrait;
use Drupal\Core\Entity\EntityPublishedInterface;
use Drupal\Core\Entity\EntityPublishedTrait;
use Drupal\webform\Entity\Webform;

/**
 * Class WebformRevision.
 *
 * @package Drupal\webform_revisions\Entity
 */
class WebformRevision extends Webform implements ConfigEntityRevisionsConfigEntityInterface, EntityPublishedInterface {
  use ConfigEntityRevisionsConfigEntityTrait;
  use EntityPublishedTrait;
  private $constants = [
    'module_name' => 'webform_revisions',
    'config_entity_name' => 'webform',
    'revisions_entity_name' => 'WebformRevision',
    'bundle_name' => 'webform_revisions',
    'setting_name' => 'webform_revisions_id',
    'title' => 'Webform',
    'has_own_content' => TRUE,
    'content_entity_type' => 'webform_submissions',
    'content_entity_table' => 'webform_submissions',
    'content_parameter_name' => 'webform_submission',
    'content_parent_reference_field' => 'webform',
    'admin_permission' => 'administer webforms',
    'has_canonical_url' => TRUE,
    'preview_form_id' => '',
  ];

  /**
   * Get the number of submissions related to a revision.
   *
   * @return int
   *   The number of content entities using a particular revision.
   */
  public function contentEntityCount($rid) {
    return \Drupal::database()
      ->query("SELECT COUNT(sid) FROM {webform_submission} WHERE webform_revision = :rid", [
      ':rid' => $rid,
    ])
      ->fetchField();
  }

  /**
   * Delete submissions related to a revision.
   */
  public function deleteRelatedContentEntities($rid) {
    $sids = \Drupal::database()
      ->query("SELECT sid FROM {webform_submission} WHERE webform_revision = :rid", [
      ':rid' => $rid,
    ])
      ->fetchCol();
    $storage = \Drupal::entityTypeManager()
      ->getStorage('webform_submission');
    $submissions = $storage
      ->loadMultiple($sids);
    $storage
      ->delete($submissions);
  }

  /**
   * {@inheritdoc}
   */
  public function deleteElement($key) {

    // Delete element from the elements render array.
    $elements = $this
      ->getElementsDecoded();
    $sub_element_keys = $this
      ->deleteElementRecursive($elements, $key);
    $this
      ->setElements($elements);

    // Don't delete submission data so that it can still be viewed for previous
    // revisions.
  }

}

Classes

Namesort descending Description
WebformRevision Class WebformRevision.