You are here

thunder_taxonomy.install in Thunder 8.2

Contains Thunder taxonomy install / uninstall hooks.

File

modules/thunder_taxonomy/thunder_taxonomy.install
View source
<?php

/**
 * @file
 * Contains Thunder taxonomy install / uninstall hooks.
 */
use Drupal\user\Entity\Role;
use Drupal\taxonomy\Entity\Vocabulary;

/**
 * Update hook dependencies.
 *
 * @return mixed
 *   Returns list of update hook dependencies.
 */
function thunder_taxonomy_update_dependencies() {
  $dependencies['thunder_taxonomy'] = [
    // Dependency on pinterest media type.
    8002 => [
      'thunder' => '8114',
    ],
  ];
  return $dependencies;
}

/**
 * Grant term access permissions.
 */
function thunder_taxonomy_update_8001() {

  /** @var \Drupal\user\Entity\Role[] $roles */
  $roles = Role::loadMultiple();

  /** @var \Drupal\taxonomy\Entity\Vocabulary[] $vocabularies */
  $vocabularies = Vocabulary::loadMultiple();
  foreach ($roles as $role) {
    foreach ($vocabularies as $vocabulary) {
      if ($role
        ->hasPermission('access content')) {
        $role
          ->grantPermission('view published terms in ' . $vocabulary
          ->id());
      }
      if ($role
        ->hasPermission('view own unpublished content')) {
        $role
          ->grantPermission('view unpublished terms in ' . $vocabulary
          ->id());
      }
      $role
        ->save();
    }
  }
}

/**
 * Enable pinterest paragraph type on taxonomy terms.
 */
function thunder_taxonomy_update_8002() {

  /** @var \Drupal\update_helper\Updater $updater */
  $updater = \Drupal::service('update_helper.updater');
  $updater
    ->executeUpdate('thunder', 'thunder_taxonomy_update_8002');

  // Output logged messages to related channel of update execution.
  return $updater
    ->logger()
    ->output();
}

/**
 * Use core's term status field definition.
 */
function thunder_taxonomy_update_8003() {

  /** @var \Drupal\update_helper\Updater $updater */
  $updater = \Drupal::service('update_helper.updater');
  $definition_update_manager = \Drupal::entityDefinitionUpdateManager();
  $entity_type = $definition_update_manager
    ->getEntityType('taxonomy_term');
  $entity_keys = $entity_type
    ->getKeys();
  $entity_keys['published'] = 'status';
  $entity_type
    ->set('entity_keys', $entity_keys);
  $definition_update_manager
    ->updateEntityType($entity_type);

  /** @var \Drupal\Core\Entity\EntityFieldManagerInterface $field_manager */
  $field_manager = \Drupal::service('entity_field.manager');
  $status = $field_manager
    ->getBaseFieldDefinitions('taxonomy_term')['status'];
  $definition_update_manager
    ->updateFieldStorageDefinition($status
    ->getFieldStorageDefinition());

  // Copied this part from https://www.drupal.org/node/2985366. It's only for
  // safties sake, because Thunder user should never had the
  // content_translation_status field.
  $has_content_translation_status_field = $definition_update_manager
    ->getFieldStorageDefinition('content_translation_status', 'taxonomy_term');

  // Uninstall the 'content_translation_status' field if needed.
  if ($has_content_translation_status_field) {
    $content_translation_status = $definition_update_manager
      ->getFieldStorageDefinition('content_translation_status', 'taxonomy_term');
    $definition_update_manager
      ->uninstallFieldStorageDefinition($content_translation_status);
  }

  // Output logged messages to related channel of update execution.
  return $updater
    ->logger()
    ->output();
}

Functions

Namesort descending Description
thunder_taxonomy_update_8001 Grant term access permissions.
thunder_taxonomy_update_8002 Enable pinterest paragraph type on taxonomy terms.
thunder_taxonomy_update_8003 Use core's term status field definition.
thunder_taxonomy_update_dependencies Update hook dependencies.