You are here

uc_catalog.install in Ubercart 8.4

Install, update and uninstall functions for the uc_catalog module.

File

uc_catalog/uc_catalog.install
View source
<?php

/**
 * @file
 * Install, update and uninstall functions for the uc_catalog module.
 */
use Drupal\Core\Url;
use Drupal\image\Entity\ImageStyle;
use Drupal\taxonomy\Entity\Vocabulary;

/**
 * Implements hook_install().
 */
function uc_catalog_install() {
  foreach (uc_product_types() as $type) {
    uc_catalog_add_node_type($type);
  }
  uc_catalog_add_image_field();
}

/**
 * Implements hook_uninstall().
 */
function uc_catalog_uninstall() {
  if ($vid = \Drupal::config('uc_catalog.settings')
    ->get('vocabulary')) {
    $vocab = Vocabulary::load($vid);
    \Drupal::messenger()
      ->addWarning(t('The Ubercart %catalog vocabulary has not been deleted. If you need to delete it, <a href=":url">please do so manually</a>.', [
      '%catalog' => $vocab
        ->label(),
      ':url' => Url::fromRoute('entity.taxonomy_vocabulary.edit_form', [
        'taxonomy_vocabulary' => $vocab
          ->id(),
      ])
        ->toString(),
    ]));
  }
  $styles = ImageStyle::loadMultiple([
    'uc_category',
    'uc_product_list',
  ]);
  if (!empty($styles)) {
    $style_names = [];
    foreach ($styles as $style) {
      $style_names[] = $style
        ->label();
    }
    \Drupal::messenger()
      ->addWarning(\Drupal::translation()
      ->formatPlural(count($style_names), 'The image style %style has not been deleted. If you need to delete it, <a href=":url">please do so manually</a>.', 'The image styles %styles have not been deleted. If you need to delete them, <a href=":url">please do so manually</a>.', [
      '%style' => $style_names[0],
      '%styles' => implode(', ', $style_names),
      ':url' => Url::fromRoute('entity.image_style.collection')
        ->toString(),
    ]));
  }
}

Functions

Namesort descending Description
uc_catalog_install Implements hook_install().
uc_catalog_uninstall Implements hook_uninstall().