ercore-8.x-1.20/ercore.install
ercore.install
<?php /** * @file * The ERCore install file. */ use Drupal\node\Entity\Node; /** * ERCore install file sets variables. */ function ercore_install() { \Drupal::service('config.factory')->getEditable('ercore.settings') ->set('ercore_epscor_start', '2018-03-08') ->set('ercore_epscor_end', '2023-03-08') ->set('ercore_reporting_month', '03') ->set('ercore_grant_type', '5') ->set('ercore_grant_extension', '0') ->save(); $features = [ 'ercore_institution', 'ercore_component', 'ercore_program', 'ercore_core', 'ercore_event', 'ercore_collaboration', 'ercore_j_highlight', 'ercore_j_honor', 'ercore_other_product', 'ercore_patent', 'ercore_presentation', 'ercore_proposal', 'ercore_publication', 'ercore_summary_views', ]; foreach ($features as $feature) { \Drupal::service('config_import.features_importer') ->import($feature); } } /** * ERCore uninstall file sets variables and modules. */ function ercore_uninstall() { \Drupal::configFactory()->getEditable('ercore.settings')->delete(); } /** * Updating config to add new tokens (beta23). */ function ercore_update_8001() { if (!\Drupal::moduleHandler()->moduleExists('field_token_value')) { \Drupal::service('module_installer')->install(['field_token_value']); } // Re-import ERCore modules.\ to update config. \Drupal::service('config.installer')->installDefaultConfig('module', 'ercore_institution'); \Drupal::service('config.installer')->installDefaultConfig('module', 'ercore_component'); \Drupal::service('config.installer')->installDefaultConfig('module', 'ercore_program'); \Drupal::service('config.installer')->installDefaultConfig('module', 'ercore_event'); \Drupal::service('config.installer')->installDefaultConfig('module', 'ercore_collaboration'); \Drupal::service('config.installer')->installDefaultConfig('module', 'ercore_j_highlight'); \Drupal::service('config.installer')->installDefaultConfig('module', 'ercore_j_honor'); \Drupal::service('config.installer')->installDefaultConfig('module', 'ercore_other_product'); \Drupal::service('config.installer')->installDefaultConfig('module', 'ercore_patent'); \Drupal::service('config.installer')->installDefaultConfig('module', 'ercore_presentation'); \Drupal::service('config.installer')->installDefaultConfig('module', 'ercore_proposal'); \Drupal::service('config.installer')->installDefaultConfig('module', 'ercore_publication'); \Drupal::service('config.installer')->installDefaultConfig('module', 'ercore_summary_views'); $types = [ 'ercore_collaboration', 'ercore_event', 'ercore_j_highlight', 'ercore_j_honor', 'ercore_other_product', 'ercore_patent', 'ercore_presentation', 'ercore_proposal', 'ercore_publication', ]; foreach ($types as $type) { $nids = \Drupal::entityQuery('node') ->condition('status', 1) ->condition('type', $type) ->execute(); $nodes = Node::loadMultiple($nids); foreach ($nodes as $node) { $value = ercore_token_get_institutions($node->get('field_ercore_organizer') ->getValue()); $node->set('field_ercore_related_institution', $value, FALSE); $node->save(); } } }