You are here

webform_revisions.install in Config Entity Revisions 8

File

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

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');
  $entity = $cert_storage
    ->load('webform_revisions');
  $cert_storage
    ->delete([
    $entity,
  ]);
}

/**
 * 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().