You are here

webform_revisions.install in Config Entity Revisions 8.2

Install and update hooks for webform_revisions.

File

modules/webform_revisions/webform_revisions.install
View source
<?php

/**
 * @file
 * Install and update hooks for webform_revisions.
 */
use Drupal\Core\Field\BaseFieldDefinition;

/**
 * Implements hook_install().
 */
function webform_revisions_install() {
  $entityTypeManager = \Drupal::entityTypeManager();
  $cert_storage = $entityTypeManager
    ->getStorage('config_entity_revisions_type');
  $entity = $cert_storage
    ->create([
    'id' => 'webform_revisions',
    'label' => 'Webform Revisions',
  ]);
  $entity
    ->save();
}

/**
 * Implements hook_uninstall().
 */
function webform_revisions_uninstall() {
  $entityTypeManager = \Drupal::entityTypeManager();
  $cert_storage = $entityTypeManager
    ->getStorage('config_entity_revisions_type');
  $entities = $cert_storage
    ->loadByProperties([
    'type' => 'webform_revisions',
  ]);
  if ($entities) {
    $cert_storage
      ->delete([
      $entities,
    ]);
  }
  Drupal::configFactory()
    ->getEditable('config_entity_revisions.config_entity_revisions_type.webform_revisions')
    ->delete();
}

/**
 * Implements hook_update().
 */
function webform_revisions_8000(&$sandbox) {

  // Add a reference from a webform submission to the matching config entity
  // revision.
  $storage_definition = BaseFieldDefinition::create('entity_reference')
    ->setLabel(t('Webform revision'))
    ->setTargetEntityTypeId('config_entity_revisions')
    ->setTargetBundle(NULL);
  \Drupal::entityDefinitionUpdateManager()
    ->uninstallFieldStorageDefinition('webform_revision', 'webform_submission', 'webform_revisions', $storage_definition);
  $entityTypeManager = \Drupal::entityTypeManager();
  $cert_storage = $entityTypeManager
    ->getStorage('config_entity_revisions_type');
  $entity = $cert_storage
    ->create([
    'id' => 'webform_revisions',
  ]);
  $entity
    ->save();
}

Functions

Namesort descending Description
webform_revisions_8000 Implements hook_update().
webform_revisions_install Implements hook_install().
webform_revisions_uninstall Implements hook_uninstall().