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 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' => '',
];
public function contentEntityCount($rid) {
return \Drupal::database()
->query("SELECT COUNT(sid) FROM {webform_submission} WHERE webform_revision = :rid", [
':rid' => $rid,
])
->fetchField();
}
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);
}
public function deleteElement($key) {
$elements = $this
->getElementsDecoded();
$sub_element_keys = $this
->deleteElementRecursive($elements, $key);
$this
->setElements($elements);
}
}