Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/composer/drupal/config_update-2.0…
Browse files Browse the repository at this point in the history
….0-alpha4
  • Loading branch information
trackleft authored Jan 13, 2025
2 parents 67e2f1e + f72f14c commit b2d16ab
Show file tree
Hide file tree
Showing 16 changed files with 781 additions and 2 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"drupal/access_unpublished": "1.6.0",
"drupal/antibot": "2.0.4",
"drupal/asset_injector": "2.21.0",
"drupal/auto_entitylabel": "3.3.0",
"drupal/auto_entitylabel": "3.4.0",
"drupal/better_exposed_filters": "7.0.3",
"drupal/blazy": "3.0.13",
"drupal/block_class": "4.0.0",
Expand All @@ -60,7 +60,7 @@
"drupal/config_split": "2.0.1",
"drupal/config_sync": "3.0.0-alpha3",
"drupal/config_update": "2.0.0-alpha4",
"drupal/core-recommended": "10.3.10",
"drupal/core-recommended": "10.3.11",
"drupal/crop": "2.4.0",
"drupal/ctools": "*",
"drupal/date_ap_style": "2.0.2",
Expand Down
50 changes: 50 additions & 0 deletions modules/custom/az_person/az_person.module
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
* Contains az_person.module.
*/

use Drupal\Core\Entity\EntityFormInterface;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Form\FormStateInterface;

/**
* Implements hook_preprocess_node().
Expand Down Expand Up @@ -34,6 +36,54 @@ function az_person_preprocess_views_view(&$variables) {

}

/**
* Implements hook_form_FORM_ID_alter() for node_az_person_edit_form.
*
* Disables certain fields for imported person data.
*/
function az_person_form_node_az_person_edit_form_alter(&$form, FormStateInterface $form_state, $form_id) {

$form_object = $form_state->getFormObject();
if ($form_object instanceof EntityFormInterface) {
/** @var \Drupal\node\NodeInterface $node */
$node = $form_object->getEntity();
if ($node->hasField('field_az_netid')) {
$netid = $node->get('field_az_netid')->value;
if (!empty($netid)) {
$imported = [];
try {
// See if a migration map exists for this person.
$imported = \Drupal::service('migrate.lookup')->lookup('az_person_profiles_import', [$netid]);
}
catch (\Exception $e) {
// Migration did not exist, or migrate service not found.
// We have no data on this person being imported or not.
}
if (!empty($imported)) {
$person_warning = t('This person has been imported from the Profiles API.');
\Drupal::messenger()->addWarning($person_warning);
$disabled_fields = [
'field_az_fname',
'field_az_lname',
'field_az_netid',
'field_az_email',
'field_az_phones',
'field_az_titles',
'field_az_degrees',
'field_az_address',
'field_az_body',
];
foreach ($disabled_fields as $field) {
if (!empty($form[$field])) {
$form[$field]['#disabled'] = TRUE;
}
}
}
}
}
}
}

/**
* Implements hook_entity_bundle_field_info_alter().
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: 'Quickstart Person Profiles Import'
type: module
description: 'Import people via UA Vitae Profiles.'
core_version_requirement: ^9 || ^10
package: 'The University of Arizona - Experimental'
dependencies:
- az_person
- field
- migrate
- migrate_plus
- migrate_tools
- node
- path
- pathauto
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
az_person_profiles_import.import_tab:
title: 'Import Person'
route_name: az_person_profiles_import.form
parent_id: system.admin_content
description: 'Import a person from the Profiles API'
weight: 102

az_person_profiles_import.settings_tab:
route_name: az_person_profiles_import.settings_form
title: 'Profiles Integration'
base_route: az_core.az_settings
weight: 6
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

/**
* @file
* Contains az_person_profiles_import.module.
*/

use Drupal\Core\Entity\EntityInterface;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\node\Entity\Node;

/**
* Implements hook_entity_presave().
*/
function az_person_profiles_import_node_presave(EntityInterface $entity) {
$fields = [
'field_az_fname',
'field_az_lname',
'field_az_netid',
'field_az_email',
'field_az_body',
'field_az_titles',
'field_az_degrees',
'field_az_phones',
];
// Set a new revision to be created if this is a migrating profile.
// Nodes from migrations are isSyncing().
if (($entity instanceof Node) && ($entity->bundle() === 'az_person') && $entity->isSyncing() && !$entity->isNew()) {
// Create new revision on syncing person records.
$revision_log = 'Updated from profiles import.';
foreach ($fields as $field) {
if ($entity->hasField($field) && !empty($entity->original)) {
// Check if field changed.
$value = $entity->get($field)->getValue();
$original = $entity->original->get($field)->getValue();
if (serialize($value) !== serialize($original)) {
// Field value has changed.
// Get human readable name of field.
$field_info = FieldStorageConfig::loadByName('node', $field);
if (!is_null($field_info)) {
$label = $field_info->getLabel();
// Add mention of field being changed in log message.
$revision_log .= " Modified field " . $label . '.';
}
}
}
}
$entity->setNewRevision(TRUE);
$entity->setRevisionLogMessage($revision_log);
$entity->isDefaultRevision(TRUE);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
az_person_profiles_import.settings_form:
path: '/admin/config/az-quickstart/settings/az-person-profiles-import'
defaults:
_title: 'Profiles Import Settings'
_form: 'Drupal\az_person_profiles_import\Form\AZPersonProfilesImportSettingsForm'
requirements:
_permission: 'administer site configuration'

az_person_profiles_import.form:
path: '/admin/content/profiles/import'
defaults:
_title: 'Import Profiles'
_form: 'Drupal\az_person_profiles_import\Form\AZPersonProfilesImportForm'
requirements:
_permission: 'create az_person content'
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
services:
_defaults:
autoconfigure: true
az_person_profiles_import_subscriber:
class: Drupal\az_person_profiles_import\EventSubscriber\AZPersonProfilesImportEventSubscriber
arguments:
- '@messenger'
- '@entity_type.manager'
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
endpoint: 'https://profiles-api.arizona.edu'
apikey: ''
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Schema for the configuration files of the Quickstart Person Profiles Import module.
az_person_profiles_import.settings:
type: config_object
label: 'Quickstart Person Profiles Import settings'
mapping:
endpoint:
type: string
label: 'Profiles Endpoint'
apikey:
type: string
label: 'API Key'
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
id: az_person_profiles_import
label: Profiles Integration
migration_tags:
- Profiles Integration
source:
plugin: url
data_fetcher_plugin: az_profiles_api_fetcher
data_parser_plugin: az_person_profiles_import_json
urls: []
item_selector: /
ids:
netid:
type: string
constants:
NAME: 'name'

fields:
-
name: netid
selector: 'Person/netid'
-
name: surname
selector: 'Person/surname'
-
name: givenname
selector: 'Person/givenname'
-
name: email
selector: 'Person/email'
-
name: biography
selector: 'Bio/desc'
-
name: titles
selector: 'Titles'
-
name: phone
selector: 'Person/phone'
-
name: office
selector: 'Person/office'
-
name: degrees
selector: 'Degrees'

process:
nid:
-
plugin: entity_lookup
entity_type: node
bundle_key: type
bundle: az_person
value_key: field_az_netid
source: netid
-
plugin: skip_on_empty
method: process
type:
plugin: default_value
default_value: az_person
field_az_fname: givenname
field_az_lname: surname
field_az_netid: netid
field_az_email:
-
plugin: skip_on_empty
method: row
source: email
message: 'is unavailable in the profiles API'
-
plugin: get
field_az_body/value: biography
field_az_body/format:
plugin: default_value
default_value: az_standard
field_az_titles:
plugin: sub_process
source: titles
process:
value: desc
field_az_degrees:
plugin: az_person_degrees
source: degrees
field_az_phones:
plugin: sub_process
source: phone
process:
value: number
field_az_address:
-
plugin: sub_process
source: office
process:
0:
plugin: concat
source:
- building_name
- room_nbr
delimiter: ' '
-
plugin: flatten
-
plugin: concat
delimiter: "\n"
destination:
plugin: entity:node
bundle: az_person

dependencies:
enforced:
module:
- az_person
Loading

0 comments on commit b2d16ab

Please sign in to comment.