event_platform-1.0.x-dev/event_platform_sponsors/event_platform_sponsors.install

event_platform_sponsors/event_platform_sponsors.install
<?php

/**
 * @file
 * Install, update and uninstall functions for Event Platform Sponsors.
 */

use Drupal\taxonomy\Entity\Term;
use Drupal\user\Entity\Role;

/**
 * Implements hook_install().
 */
function event_platform_sponsors_install() {
  $terms['sponsor_level'] = [
    'In Kind Sponsors',
    'Bronze Sponsors',
    'Silver Sponsors',
    'Gold Sponsors',
    'Platinum Sponsors',
  ];

  foreach ($terms as $vocab => $vocab_terms) {
    $index = 0;
    foreach ($vocab_terms as $label) {
      // Create the taxonomy term.
      $new_term = Term::create([
        'name' => $label,
        'vid' => $vocab,
      ]);
      $new_term->setWeight($index);

      // Save the taxonomy term.
      $new_term->save();
      $index++;
    }
  }

  // Add permission to view field_r and field_time_slot.
  foreach (['anonymous', 'authenticated'] as $role) {
    $role_object = Role::load($role);
    if (!$role_object) {
      continue;
    }
    $role_object->grantPermission(
      'view published sponsorship storage entities',
    );
    $role_object->save();
  }
}

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

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