You are here

function views_rss_itunes_install in Views RSS: iTunes Elements 8

Same name and namespace in other branches
  1. 6 views_rss_itunes.install \views_rss_itunes_install()
  2. 7 views_rss_itunes.install \views_rss_itunes_install()

Implements hook_install().

File

./views_rss_itunes.install, line 16
(Un)installation functions for Views RSS: iTunes Elements module.

Code

function views_rss_itunes_install() {

  // Make sure that "iTunes Category" vocabulary does not exist
  // (it could still be there from previous module installations).
  if (!Vocabulary::load('views_rss_itunes_category')) {

    // Create "iTunes Category" vocabulary.
    $vocabulary = entity_create('taxonomy_vocabulary', array(
      'name' => 'iTunes Category',
      'vid' => 'views_rss_itunes_category',
    ));
    $vocabulary
      ->save();

    // Create main iTunes categories as first-level terms.
    $first_level_terms = array(
      'arts' => array(
        'name' => 'Arts',
      ),
      'business' => array(
        'name' => 'Business',
      ),
      'comedy' => array(
        'name' => 'Comedy',
      ),
      'education' => array(
        'name' => 'Education',
      ),
      'games_and_hobbies' => array(
        'name' => 'Games & Hobbies',
      ),
      'government_and_organizations' => array(
        'name' => 'Government & Organizations',
      ),
      'health' => array(
        'name' => 'Health',
      ),
      'kids_and_family' => array(
        'name' => 'Kids & Family',
      ),
      'music' => array(
        'name' => 'Music',
      ),
      'news_and_politics' => array(
        'name' => 'News & Politics',
      ),
      'religion_and_spirituality' => array(
        'name' => 'Religion & Spirituality',
      ),
      'science_and_medicine' => array(
        'name' => 'Science & Medicine',
      ),
      'society_and_culture' => array(
        'name' => 'Society & Culture',
      ),
      'sports_and_recreation' => array(
        'name' => 'Sports & Recreation',
      ),
      'technology' => array(
        'name' => 'Technology',
      ),
      'tv_and_film' => array(
        'name' => 'TV & Film',
      ),
    );
    foreach ($first_level_terms as $key => $term_data) {
      $term_data['vid'] = $vocabulary
        ->id();
      $term = entity_create('taxonomy_term', $term_data);
      $term
        ->save();
      $first_level_terms[$key] = $term;
    }

    // Create iTunes subcategories as second-level terms.
    $second_level_terms = array(
      'arts' => array(
        array(
          'name' => 'Design',
        ),
        array(
          'name' => 'Fashion & Beauty',
        ),
        array(
          'name' => 'Food',
        ),
        array(
          'name' => 'Literature',
        ),
        array(
          'name' => 'Performing Arts',
        ),
        array(
          'name' => 'Visual Arts',
        ),
      ),
      'business' => array(
        array(
          'name' => 'Business News',
        ),
        array(
          'name' => 'Careers',
        ),
        array(
          'name' => 'Investing',
        ),
        array(
          'name' => 'Management & Marketing',
        ),
        array(
          'name' => 'Shopping',
        ),
      ),
      'education' => array(
        array(
          'name' => 'Education',
        ),
        array(
          'name' => 'Education Technology',
        ),
        array(
          'name' => 'Higher Education',
        ),
        array(
          'name' => 'K-12',
        ),
        array(
          'name' => 'Language Courses',
        ),
        array(
          'name' => 'Training',
        ),
      ),
      'games_and_hobbies' => array(
        array(
          'name' => 'Automotive',
        ),
        array(
          'name' => 'Aviation',
        ),
        array(
          'name' => 'Hobbies',
        ),
        array(
          'name' => 'Other Games',
        ),
        array(
          'name' => 'Video Games',
        ),
      ),
      'government_and_organizations' => array(
        array(
          'name' => 'Local',
        ),
        array(
          'name' => 'National',
        ),
        array(
          'name' => 'Non-Profit',
        ),
        array(
          'name' => 'Regional',
        ),
      ),
      'health' => array(
        array(
          'name' => 'Alternative Health',
        ),
        array(
          'name' => 'Fitness & Nutrition',
        ),
        array(
          'name' => 'Self-Help',
        ),
        array(
          'name' => 'Sexuality',
        ),
      ),
      'religion_and_spirituality' => array(
        array(
          'name' => 'Buddhism',
        ),
        array(
          'name' => 'Christianity',
        ),
        array(
          'name' => 'Hinduism',
        ),
        array(
          'name' => 'Islam',
        ),
        array(
          'name' => 'Judaism',
        ),
        array(
          'name' => 'Other',
        ),
        array(
          'name' => 'Spirituality',
        ),
      ),
      'science_and_medicine' => array(
        array(
          'name' => 'Medicine',
        ),
        array(
          'name' => 'Natural Sciences',
        ),
        array(
          'name' => 'Social Sciences',
        ),
      ),
      'society_and_culture' => array(
        array(
          'name' => 'History',
        ),
        array(
          'name' => 'Personal Journals',
        ),
        array(
          'name' => 'Philosophy',
        ),
        array(
          'name' => 'Places & Travel',
        ),
      ),
      'sports_and_recreation' => array(
        array(
          'name' => 'Amateur',
        ),
        array(
          'name' => 'College & High School',
        ),
        array(
          'name' => 'Outdoor',
        ),
        array(
          'name' => 'Professional',
        ),
      ),
      'technology' => array(
        array(
          'name' => 'Gadgets',
        ),
        array(
          'name' => 'Tech News',
        ),
        array(
          'name' => 'Podcasting',
        ),
        array(
          'name' => 'Software How-To',
        ),
      ),
    );
    foreach ($second_level_terms as $key1 => $terms) {
      foreach ($terms as $key2 => $term_data) {
        $term_data['vid'] = $vocabulary
          ->id();
        $term_data['parent'] = $first_level_terms[$key1]
          ->id();
        $term = entity_create('taxonomy_term', $term_data);
        $term
          ->save();
        $second_level_terms[$key1][$key2] = $term;
      }
    }
  }

  // Clear Views cache to force-rebuild namespaces and feed elements.
  Cache::invalidateTags(array(
    'views_rss',
  ));
}