You are here

thunder_riddle.install in Thunder 8.2

Thunder Riddle integration install hooks.

File

modules/thunder_article/modules/thunder_riddle/thunder_riddle.install
View source
<?php

/**
 * @file
 * Thunder Riddle integration install hooks.
 */
use Drupal\user\Entity\Role;

/**
 * Implements hook_install().
 *
 * Granting permissions for "editor" and "seo" user roles for proper functioning
 * of Riddle entity browser.
 */
function thunder_riddle_install() {
  $logger = \Drupal::logger('thunder_riddle');

  /** @var \Drupal\user\RoleInterface[] $roles */
  $roles = Role::loadMultiple([
    'editor',
    'seo',
  ]);
  foreach ($roles as $role) {
    $role
      ->grantPermission('access riddle_browser entity browser pages');
    if ($role
      ->save()) {
      $logger
        ->info(t('Permissions to access riddle entity browser granted for "@user_role" user role.', [
        '@user_role' => $role
          ->id(),
      ]));
    }
    else {
      $logger
        ->warning(t('Unable to grant access for riddle entity browser for "@user_role" user role.', [
        '@user_role' => $role
          ->id(),
      ]));
    }
  }
}

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

  /** @var \Drupal\Core\Config\ConfigFactoryInterface $configFactory */
  $configFactory = \Drupal::configFactory();
  $logger = \Drupal::logger('thunder_riddle');
  $config = [
    'core.entity_form_display.media.riddle.default',
    'core.entity_form_display.paragraph.riddle.default',
    'core.entity_view_display.media.riddle.default',
    'core.entity_view_display.media.riddle.thumbnail',
    'core.entity_view_display.paragraph.riddle.default',
    'core.entity_view_display.paragraph.riddle.preview',
    'entity_browser.browser.riddle_browser',
    'field.field.media.riddle.field_riddle_id',
    'field.field.paragraph.riddle.field_riddle',
    'field.storage.media.field_riddle_id',
    'field.storage.paragraph.field_riddle',
    'media_entity.bundle.riddle',
    'paragraphs.paragraphs_type.riddle',
    'views.view.riddle_browser',
  ];
  foreach ($config as $tour) {
    try {
      $configFactory
        ->getEditable($tour)
        ->delete();
    } catch (\Exception $e) {
      $logger
        ->warning(sprintf('Unable to uninstall config: %s.', $tour));
    }
  }
}

Functions