Skip to content

Commit

Permalink
Closes #2547 Add ability to customize publication types. (#2574)
Browse files Browse the repository at this point in the history
Co-authored-by: tadean <[email protected]>
Co-authored-by: Joe Parsons <[email protected]>
Co-authored-by: Brian Berndt <[email protected]>
  • Loading branch information
4 people committed Nov 20, 2024
1 parent 6eaeb04 commit ea3b7ab
Show file tree
Hide file tree
Showing 77 changed files with 1,739 additions and 158 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,8 @@
"filter_autop returns self closing br element with slash, lets alter to br (2350049)": "https://www.drupal.org/files/issues/2024-08-15/2350049-48-reroll-against-11.x.patch",
"[10.2 regression] CKEditor 5 breaks when 'Source'/Source editing button is added and 'Manually editable HTML tags' are specified (3410100)": "https://www.drupal.org/files/issues/2024-01-23/drupal-revert-source-editing-validation-tightening-3410100-38.patch",
"[Apache only] Wrong file header returned, when converting an image for example to webp (3310963)": "https://www.drupal.org/files/issues/2024-05-15/3310963-32.patch",
"Hardcode a higher WebP conversion quality setting (3320689)": "https://gist.githubusercontent.com/joeparsons/d99b6c6eef240e8eaf768ba79e1c9f1b/raw/9b99325bd20907db0506969fc4f5823b46065c6b/3320689-10-3-x-hardcoded.patch"
"Hardcode a higher WebP conversion quality setting (3320689)": "https://gist.githubusercontent.com/joeparsons/d99b6c6eef240e8eaf768ba79e1c9f1b/raw/9b99325bd20907db0506969fc4f5823b46065c6b/3320689-10-3-x-hardcoded.patch",
"Add Views EntityReference filter to support better UX for exposed filters (3347343)": "https://gist.githubusercontent.com/trackleft/812286289ec98b72897ba9f59962d62a/raw/185b3481844d28c2d64a5f344e865da9382d0a08/add-Views-EntityReference-filter.patch"
},
"drupal/draggableviews": {
"Row weights not displaying on sort view (3252365)": "https://www.drupal.org/files/issues/2023-08-25/3252365-check-remove-select-all-class.patch",
Expand Down
10 changes: 10 additions & 0 deletions config/install/user.role.az_content_admin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ permissions:
- 'access site reports'
- 'access taxonomy overview'
- 'access tokens overview'
- 'add publication type entities'
- 'administer author entities'
- 'administer block classes'
- 'administer block content'
Expand All @@ -22,6 +23,7 @@ permissions:
- 'administer languages'
- 'administer menu'
- 'administer meta tags'
- 'administer publication type entities'
- 'administer quickstart configuration'
- 'administer redirects'
- 'administer shortcuts'
Expand Down Expand Up @@ -63,6 +65,7 @@ permissions:
- 'delete any webform content'
- 'delete any webform submission'
- 'delete author entities'
- 'delete publication type entities'
- 'delete content translations'
- 'delete own az_carousel_item content'
- 'delete terms in az_academic_programs'
Expand All @@ -79,8 +82,10 @@ permissions:
- 'delete token'
- 'delete webform submissions any node'
- 'delete webform submissions own node'
- 'disable publication type entities'
- 'edit any webform'
- 'edit any webform submission'
- 'edit publication type entities'
- 'edit terms in az_event_categories'
- 'edit terms in az_news_tags'
- 'edit terms in az_page_categories'
Expand All @@ -91,9 +96,14 @@ permissions:
- 'edit webform assets'
- 'edit webform submissions any node'
- 'edit webform submissions own node'
- 'enable publication type entities'
- 'renew token'
- 'revert all publication type revisions'
- 'update any media'
- 'update content translations'
- 'use advanced search'
- 'use marketing campaign page styles'
- 'view all publication type revisions'
- 'view disabled publication type entities'
- 'view enabled publication type entities'
- 'view post access counter'
20 changes: 10 additions & 10 deletions modules/custom/az_demo/data/az_demo_node_publication.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"pmcid": "",
"pmid": "",
"publisher": "Historical Books Publishing",
"type": "book",
"type": "az_book",
"version": "1st Edition",
"volume": ""
},
Expand Down Expand Up @@ -52,7 +52,7 @@
"pmcid": "",
"pmid": "",
"publisher": "Mathematical Works Publishing",
"type": "article",
"type": "az_article",
"version": "2nd Edition",
"volume": ""
},
Expand Down Expand Up @@ -80,7 +80,7 @@
"pmcid": "PMC1234567",
"pmid": "987654321",
"publisher": "Science Journal Publishing",
"type": "article-journal",
"type": "az_article_journal",
"version": "Final",
"volume": "12"
},
Expand Down Expand Up @@ -108,7 +108,7 @@
"pmcid": "",
"pmid": "",
"publisher": "Tech books Publishing",
"type": "book",
"type": "az_book",
"version": "3rd Edition",
"volume": ""
},
Expand Down Expand Up @@ -136,7 +136,7 @@
"pmcid": "",
"pmid": "",
"publisher": "AI Conference Publishing",
"type": "Conference Paper",
"type": "az_paper_conference",
"version": "1st Edition",
"volume": ""
},
Expand Down Expand Up @@ -164,7 +164,7 @@
"pmcid": "",
"pmid": "",
"publisher": "Tech books Publishing",
"type": "book",
"type": "az_book",
"version": "4th Edition",
"volume": ""
},
Expand Down Expand Up @@ -192,7 +192,7 @@
"pmcid": "",
"pmid": "",
"publisher": "AI Books Publishing",
"type": "book",
"type": "az_book",
"version": "1st Edition",
"volume": ""
},
Expand Down Expand Up @@ -220,7 +220,7 @@
"pmcid": "PMC7654321",
"pmid": "123456789",
"publisher": "Statistical Journal Publishing",
"type": "article-journal",
"type": "az_article_journal",
"version": "Final",
"volume": "15"
},
Expand Down Expand Up @@ -248,7 +248,7 @@
"pmcid": "",
"pmid": "",
"publisher": "Ethics Books Publishing",
"type": "book",
"type": "az_book",
"version": "2nd Edition",
"volume": ""
},
Expand Down Expand Up @@ -276,7 +276,7 @@
"pmcid": "PMC2345678",
"pmid": "234567890",
"publisher": "Environmental Journal Publishing",
"type": "article-journal",
"type": "az_article_journal",
"version": "Final",
"volume": "20"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ process:
field_az_publication_pmcid: pmcid
field_az_publication_pmid: pmid
field_az_publication_publisher: publisher
field_az_publication_type: type
field_az_publication_mapped_type/0/target_id: type
field_az_publication_version: version
field_az_publication_volume: volume
destination:
Expand Down
171 changes: 171 additions & 0 deletions modules/custom/az_publication/az_publication.install
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
* Install, update and uninstall functions for az_publication module.
*/

use Drupal\Core\Config\FileStorage;
use Drupal\Core\Database\Database;
use Drupal\Core\Utility\UpdateException;
use Drupal\node\Entity\Node;

/**
* Install the new az_curated_views module (now required by az_publication).
Expand Down Expand Up @@ -83,3 +85,172 @@ function az_publication_update_1020702() {
}

}

/**
* Adds field_az_publication_mapped_type field.
*/
function az_publication_update_1021001() {
$module_dir = \Drupal::service('extension.list.module')->getPath('az_publication');
$module_path = $module_dir . '/config/install';
// Create a new FileStorage object.
$source_storage = new FileStorage($module_path);
$config_factory = \Drupal::service('config.factory');
// Install the az_publication_type entity type.
$entity_type_manager = \Drupal::service('entity_type.manager');
$entity_type_definition = $entity_type_manager->getDefinition('az_publication_type');
\Drupal::entityDefinitionUpdateManager()->installEntityType($entity_type_definition);
$entity_type_manager->clearCachedDefinitions();
// If the field storage and field config are new, import them.
if ($config_factory->get('field.storage.node.field_az_publication_mapped_type')->isNew()) {
$field_storage_config = $source_storage->read('field.storage.node.field_az_publication_mapped_type');
\Drupal::entityTypeManager()->getStorage('field_storage_config')->create($field_storage_config)->save();
}
if ($config_factory->get('field.field.node.az_publication.field_az_publication_mapped_type')->isNew()) {
$field_config = $source_storage->read('field.field.node.az_publication.field_az_publication_mapped_type');
\Drupal::entityTypeManager()->getStorage('field_config')->create($field_config)->save();
}
// Clear caches after importing the configurations.
\Drupal::service('entity_field.manager')->clearCachedFieldDefinitions();

}

/**
* Map and move data from static text field to dynamic type reference field.
*/
function az_publication_update_1021002(&$sandbox) {
// Initialize or retrieve the batch progress information.
if (!isset($sandbox['progress'])) {
$sandbox['progress'] = 0;
$sandbox['current_node'] = 0;

// Query all node IDs of type 'az_publication'.
$sandbox['nids'] = \Drupal::entityQuery('node')
->condition('type', 'az_publication')
->accessCheck(FALSE)
->execute();

$sandbox['max'] = count($sandbox['nids']);
}

// Define the mapping from old field values to new config entity IDs.
$mapping = [
'article' => 'az_article',
'article-journal' => 'az_article_journal',
'article-magazine' => 'az_article_magazine',
'article-newspaper' => 'az_article_newspaper',
'bill' => 'az_bill',
'book' => 'az_book',
'broadcast' => 'az_broadcast',
'chapter' => 'az_chapter',
'classic' => 'az_classic',
'collection' => 'az_collection',
'dataset' => 'az_dataset',
'document' => 'az_document',
'entry' => 'az_entry',
'entry-dictionary' => 'az_entry_dictionary',
'entry-encyclopedia' => 'az_entry_encyclopedia',
'event' => 'az_event',
'figure' => 'az_figure',
'graphic' => 'az_graphic',
'hearing' => 'az_hearing',
'interview' => 'az_interview',
'legal_case' => 'az_legal_case',
'legislation' => 'az_legislation',
'manuscript' => 'az_manuscript',
'map' => 'az_map',
'motion_picture' => 'az_motion_picture',
'musical_score' => 'az_musical_score',
'pamphlet' => 'az_pamphlet',
'paper-conference' => 'az_paper_conference',
'patent' => 'az_patent',
'performance' => 'az_performance',
'periodical' => 'az_periodical',
'personal_communication' => 'az_personal_communication',
'post' => 'az_post',
'post-weblog' => 'az_post_weblog',
'regulation' => 'az_regulation',
'report' => 'az_report',
'review' => 'az_review',
'review-book' => 'az_review_book',
'software' => 'az_software',
'song' => 'az_song',
'speech' => 'az_speech',
'standard' => 'az_standard',
'thesis' => 'az_thesis',
'treaty' => 'az_treaty',
'webpage' => 'az_webpage',
];

// Process nodes in batches.
// Number of nodes to process per batch.
$limit = 50;
$nids_slice = array_slice($sandbox['nids'], $sandbox['progress'], $limit);
$nodes = Node::loadMultiple($nids_slice);
$time = \Drupal::service('datetime.time');

foreach ($nodes as $node) {
if ($node->hasField('field_az_publication_type') && !$node->get('field_az_publication_type')->isEmpty()) {
$old_value = $node->get('field_az_publication_type')->value;
$new_value = $mapping[$old_value];

// Map and update the new entity reference field.
if (isset($mapping[$old_value])) {
$node->set('field_az_publication_mapped_type', ['target_id' => $mapping[$old_value]]);
$node->setNewRevision(TRUE);
$node->isDefaultRevision(TRUE);
// Construct a detailed message.
$revision_log_message = sprintf(
"Publication type updated from '%s' to '%s' as part of data migration to a customizable type reference field. For more information about how to use this feature, see https://quickstart.arizona.edu/node/220",
$old_value,
$new_value
);
$node->setRevisionLogMessage($revision_log_message);
$node->setRevisionCreationTime($time->getRequestTime());
$node->setRevisionUserId(1);
$node->save();
}
}

$sandbox['progress']++;
$sandbox['current_node'] = $node->id();
}

// Inform the batch API about the progress.
$sandbox['#finished'] = $sandbox['progress'] / $sandbox['max'];
}

/**
* Helper function to return batch info.
*/
function az_publication_batch_info() {
return [
'title' => t('Updating AZ Publication Nodes...'),
'operations' => [
['az_publication_update_1020902', []],
],
'finished' => 'az_publication_batch_finished',
];
}

/**
* Finished callback for the batch.
*/
function az_publication_batch_finished($success, $results, $operations) {
$messenger = \Drupal::messenger();

if ($success) {
$message = \Drupal::translation()->formatPlural(count($results),
'One publication successfully processed.', '@count publications successfully processed.');
}
else {
// Handle the case where the batch did not complete successfully.
// $operations contains the operations that remained unprocessed.
$error_operation = reset($operations);
$message = t('An error occurred while processing %error_operation with arguments: @arguments', [
'%error_operation' => $error_operation[0],
'@arguments' => print_r($error_operation[1], TRUE),
]);
}

$messenger->addMessage($message);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,13 @@ entity.az_author.add_form:
title: 'Add Author'
appears_on:
- entity.az_author.collection
entity.az_publication_type.add_form:
route_name: entity.az_publication_type.add_form
title: 'Add Publication Type'
appears_on:
- entity.az_publication_type.collection
entity.az_citation_style.add_form:
route_name: entity.az_citation_style.add_form
title: 'Add Quickstart Citation Style'
title: 'Add Citation Style'
appears_on:
- entity.az_citation_style.collection
26 changes: 24 additions & 2 deletions modules/custom/az_publication/az_publication.links.task.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,33 @@ az_publication.az_publication_settings_tab:

az_publication.az_publication_settings_secondary_tab:
route_name: az_publication.settings
title: 'Publication Settings'
title: 'General'
parent_id: az_publication.az_publication_settings_tab

az_publication.az_publication_type_secondary_tab:
route_name: entity.az_publication_type.collection
title: 'Types'
parent_id: az_publication.az_publication_settings_tab
weight: 2

entity.az_publication_type.canonical:
route_name: entity.az_publication_type.canonical
base_route: entity.az_publication_type.canonical
title: 'View'

entity.az_publication_type.edit_form:
route_name: entity.az_publication_type.edit_form
base_route: entity.az_publication_type.canonical
title: 'Edit'

entity.az_publication_type.delete_form:
route_name: entity.az_publication_type.delete_form
base_route: entity.az_publication_type.canonical
title: Delete
weight: 10

az_publication.az_citation_styles_secondary_tab:
route_name: entity.az_citation_style.collection
title: 'Citation Styles'
parent_id: az_publication.az_publication_settings_tab
weight: 2
weight: 3
Loading

0 comments on commit ea3b7ab

Please sign in to comment.