You are here

function thunder_riddle_install in Thunder 8.4

Same name and namespace in other branches
  1. 8.5 modules/thunder_riddle/thunder_riddle.install \thunder_riddle_install()
  2. 8.2 modules/thunder_article/modules/thunder_riddle/thunder_riddle.install \thunder_riddle_install()
  3. 8.3 modules/thunder_article/modules/thunder_riddle/thunder_riddle.install \thunder_riddle_install()

Implements hook_install().

Granting permissions for "editor" and "seo" user roles for proper functioning of Riddle entity browser.

File

modules/thunder_article/modules/thunder_riddle/thunder_riddle.install, line 16
Thunder Riddle integration install hooks.

Code

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(),
      ]));
    }
  }

  /** @var \Drupal\field\Entity\FieldConfig $field */
  $field = \Drupal::entityTypeManager()
    ->getStorage('field_config')
    ->load('node.article.field_paragraphs');
  if ($field) {
    $settings = $field
      ->getSetting('handler_settings');
    if (!isset($settings['negate']) || !$settings['negate']) {
      $settings['target_bundles']['riddle'] = 'riddle';
      $settings['target_bundles_drag_drop']['riddle'] = [
        'enabled' => TRUE,
        'weight' => 10,
      ];
      $field
        ->setSetting('handler_settings', $settings);
      $field
        ->save();
    }
  }
}