podcast_publisher-1.0.0-alpha3/podcast_publisher.install

podcast_publisher.install
<?php

/**
 * @file
 * Install hooks for module.
 */

use Drupal\Core\Field\BaseFieldDefinition;
use Symfony\Component\Yaml\Yaml;

/**
 * Implements hook_install().
 */
function podcast_publisher_install() {
  // Create itunes category terms.
  $file_path = \Drupal::service('module_handler')->getModule('podcast_publisher')->getPath() . '/itunes-categories.yml';
  $categories = Yaml::parse(file_get_contents($file_path));
  $term_storage = \Drupal::entityTypeManager()->getStorage('taxonomy_term');
  $vid = 'pp_itunes_categories';
  foreach ($categories as $category => $sub_categories) {
    $parent = $term_storage->create([
      'name' => $category,
      'vid' => $vid,
    ]);
    $parent->save();
    foreach ($sub_categories as $sub_category) {
      $term_storage->create([
        'name' => $sub_category,
        'vid' => $vid,
        'parent' => $parent->id(),
      ])->save();
    }
  }
}

/**
 * Implements hook_uninstall().
 */
function podcast_publisher_uninstall($is_syncing) {
  // Remove custom node type.
  $node_type = \Drupal::entityTypeManager()
    ->getStorage('node_type')
    ->load('podcast_episode_page');

  if ($node_type) {
    $node_type->delete();
  }

  // Remove custom image style.
  $image_style = \Drupal::entityTypeManager()
    ->getStorage('image_style')
    ->load('podcast_3000x3000');

  if ($image_style) {
    $image_style->delete();
  }

  // Remove custom taxonomy.
  $vocabulary = \Drupal::entityTypeManager()
    ->getStorage('taxonomy_vocabulary')
    ->load('pp_itunes_categories');

  if ($vocabulary) {
    $vocabulary->delete();
  }
}

/**
 * Implements hook_update_N().
 *
 * Create new episode type field.
 */
function podcast_publisher_update_9001(&$sandbox) {
  $field_storage_definition = BaseFieldDefinition::create('list_string')
    ->setLabel(t('Type'))
    ->setDescription(t('Type of Episode.'))
    ->setCardinality(1)
    ->setRequired(TRUE)
    ->setDefaultValue('full')
    ->setSetting('allowed_values', [
      'full' => 'Full',
      'trailer' => 'Trailer',
      'bonus' => 'Bonus',
    ])
    ->setDisplayOptions('form', [
      'weight' => 5,
    ])
    ->setDisplayConfigurable('form', TRUE)
    ->setDisplayConfigurable('view', TRUE);

  \Drupal::entityDefinitionUpdateManager()
    ->installFieldStorageDefinition('type', 'podcast_episode', 'podcast_publisher', $field_storage_definition);
}

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

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