You are here

answers.install in Answers 8

Install, update, and uninstall functions for the Answers module.

File

answers.install
View source
<?php

/**
 * @file
 * Install, update, and uninstall functions for the Answers module.
 */
use Drupal\field\Entity\FieldStorageConfig;

/**
 * Implements hook_install().
 */
function answers_install() {

  // Do not allow the locked content type to be deleted.
  $locked = Drupal::state()
    ->get('node.type.locked');
  $locked['answers_question'] = 'answers_question';
  $locked['answers_answer'] = 'answers_answer';
  Drupal::state()
    ->set('node.type.locked', $locked);

  // \Drupal::entityTypeManager()
  // ->getStorage('answers_related_question')
  // ->load('node.answers_related_question')
  // ->setLocked(FALSE)
  // ->save();
}

/**
 * Implements hook_uninstall().
 */
function answers_uninstall() {
  if ($field_storage = FieldStorageConfig::loadByName('node', 'answers_related_question')) {
    $field_storage
      ->delete();
  }

  // Purge field data now to allow taxonomy and options module to be uninstalled
  // if this is the only field remaining.
  field_purge_batch(10);

  // Allow locked_content_type to be deleted.
  $locked = Drupal::state()
    ->get('node.type.locked');
  unset($locked['answers_question']);
  unset($locked['answers_answer']);
  Drupal::state()
    ->set('node.type.locked', $locked);
}

Functions

Namesort descending Description
answers_install Implements hook_install().
answers_uninstall Implements hook_uninstall().