sgd_dashboard-1.0.0-beta1/sgd_dashboard.install

sgd_dashboard.install
<?php

/**
 * @file
 * Install, update, and uninstall functions for the sgd_dashboard module.
 */

use Drupal\field\Entity\FieldStorageConfig;
use Drupal\taxonomy\Entity\Term;

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

  // Term names to be added.
  $items = [
    'Production',
    'Preprod',
    'Staging',
    'Testing',
    'Development',
    'Local',
    'Other',
  ];

  foreach ($items as $item) {
    Term::create([
      'parent' => [],
      'name' => $item,
      'vid' => 'environment_type',
    ])->save();
  }
}

/**
 * Implements hook_uninstall().
 */
function sgd_dashboard_uninstall() {

  // Need to delete the views on uninstall as get errors from viewsdata if we
  // don't.
  \Drupal::service('config.factory')->getEditable('views.view.websites')->delete();
  \Drupal::service('config.factory')->getEditable('views.view.website_projects')->delete();

  // Delete all the storage for the website fields. They wont uninstall
  // otherwise which stops you installing the module again.
  $fields = [
    'field_client',
    'field_contrib_security',
    'field_core_security',
    'field_environment_type',
    'field_http_auth_password',
    'field_http_auth_user',
    'field_report_recipients',
    'field_site_guardian_key',
    'field_site_last_checked',
    'field_title_suffix',
    'field_url',
  ];

  // Following code adapted from the forum modules uninstall.
  foreach ($fields as $field) {
    if ($field_storage = FieldStorageConfig::loadByName('node', $field)) {
      $field_storage->delete();
    }
  }

  field_purge_batch(10);
}

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc