Commit 85fd63ff authored by Chris Shantz's avatar Chris Shantz
Browse files

Merge branch '1.0.x' into prod/1.0.x

parents c6cecb89 d569c6b0
......@@ -14,9 +14,9 @@ dependencies:
module:
- layout_builder
- layout_builder_restrictions
- layout_discovery
- options
- user
- uw_cfg_common
third_party_settings:
layout_builder:
allow_custom: true
......
......@@ -9,197 +9,8 @@ field_name: field_site_footer_logo
entity_type: node
type: list_string
settings:
allowed_values:
-
value: '1'
label: 'Site name (no logo)'
-
value: UWaterloo_logo
label: 'University of Waterloo'
-
value: UWaterloo_Health
label: 'Health'
-
value: UWaterloo_Health_Kinesiology
label: 'Health - Kinesiology'
-
value: UWaterloo_Health_PublicHealth
label: 'Health - Public Health'
-
value: UWaterloo_Health_Recreation_Lesiure
label: 'Health - Recreation and Leisure Studies'
-
value: UWaterloo_Arts
label: Arts
-
value: UWaterloo_Arts_Anthropology
label: 'Arts - Anthropology'
-
value: UWaterloo_Arts_Classical_Studies
label: 'Arts - Classical Studies'
-
value: UWaterloo_Arts_Drama_Speech_Communication
label: 'Arts - Drama Speech Communication'
-
value: UWaterloo_Arts_Economics
label: 'Arts - Economics'
-
value: UWaterloo_Arts_English_Language_Literature
label: 'Arts - English Language Literature'
-
value: UWaterloo_Arts_FineArts
label: 'Arts - Fine Arts'
-
value: UWaterloo_Arts_French
label: 'Arts - French'
-
value: UWaterloo_Arts_Germanic_Slavic_Studies
label: 'Arts - Germanic Slavic Studies'
-
value: UWaterloo_Arts_History
label: 'Arts - History'
-
value: UWaterloo_Arts_Philosophy
label: 'Arts - Philosophy'
-
value: UWaterloo_Arts_Political_Science
label: 'Arts - Political Science'
-
value: UWaterloo_Arts_Psychology
label: 'Arts - Psychology'
-
value: UWaterloo_Arts_Religious_Studies
label: 'Arts - Religious Studies'
-
value: UWaterloo_Arts_School_of_Accounting_and_Finance
label: 'Arts - School of Accounting and Finance'
-
value: UWaterloo_Arts_Sociology_and_Legal_Studies
label: 'Arts - Sociology and Legal Studies'
-
value: UWaterloo_Arts_Spanish_and_Latin_American_Studies
label: 'Arts - Spanish and Latin American Studies'
-
value: UWaterloo_Engineering
label: Engineering
-
value: UWaterloo_Engineering_wordmark
label: 'Engineering wordmark'
-
value: UWaterloo_Engineering_Architecture
label: 'Engineering - Architecture'
-
value: UWaterloo_Engineering_Chemical_Engineering
label: 'Engineering - Chemical Engineering'
-
value: UWaterloo_Engineering_Civil_Environmental_Engineering
label: 'Engineering - Civil Environmental Engineering'
-
value: UWaterloo_Engineering_Electrical_Computer_Engineering
label: 'Engineering - Electrical Computer Engineering'
-
value: UWaterloo_Engineering_Management_Sciences
label: 'Engineering - Management Sciences'
-
value: UWaterloo_Engineering_Mechanical_Engineering
label: 'Engineering - Mechanical Engineering'
-
value: UWaterloo_Engineering_Systems_Design_Engineering
label: 'Engineering - Systems Design Engineering'
-
value: UWaterloo_Environment
label: Environment
-
value: UWaterloo_Environment_Environment_Enterprise_Development
label: 'Environment - Environment Enterprise Development'
-
value: UWaterloo_Environment_Enviromental_Resources_and_Sustainability
label: 'Environment - Enviromental Resources and Sustainability'
-
value: UWaterloo_Environment_Geography_Environmental_and_Management
label: 'Environment - Geography Environmental and Management'
-
value: UWaterloo_Environment_Knowledge_Intergration
label: 'Environment - Knowledge Intergration'
-
value: UWaterloo_Environment_Planning
label: 'Environment - Planning'
-
value: UWaterloo_Mathematics
label: Mathematics
-
value: UWaterloo_Math_Applied_Math
label: 'Mathematics - Applied Math'
-
value: UWaterloo_Math_Combinatorics_and_Optimization
label: 'Mathematics - Combinatorics and Optimization'
-
value: UWaterloo_Math_Computer_Science
label: 'Mathematics - Computer Science'
-
value: UWaterloo_Math_Pure_Math
label: 'Mathematics - Pure Math'
-
value: UWaterloo_Math_Statistics_Actuarial_Science
label: 'Mathematics - Statistics Actuarial Science'
-
value: UWaterloo_Science
label: Science
-
value: UWaterloo_Science_Biology
label: 'Science - Biology'
-
value: UWaterloo_Science_Chemistry
label: 'Science - Chemistry'
-
value: UWaterloo_Science_Earth_and_Environmental_Science
label: 'Science - Earth and Environmental Science'
-
value: UWaterloo_Science_Optometry_and_Vision_Science
label: 'Science - Optometry and Vision Science'
-
value: UWaterloo_Sciecne_Pharmacy
label: 'Science - Pharmacy'
-
value: UWaterloo_Science_Physics_and_Astronomy
label: 'Science - Physics and Astronomy'
-
value: conrad_grebel
label: 'Conrad Grebel'
-
value: renison_university_college
label: 'Renison University College'
-
value: st_jeromes_university
label: 'St. Jerome''s University'
-
value: st_pauls
label: 'St. Paul''s University College'
-
value: McMaster_University
label: 'McMaster University'
-
value: Survey_Research_Centre
label: 'Survey Research Centre'
-
value: University_of_Guelph
label: 'University of Guelph'
-
value: Waterloo_Centre_for_Microbial_Research
label: 'Waterloo Centre for Microbial Research'
-
value: Waterloo_Institute_for_Complexity_and_Innovation
label: 'Waterloo Institute for Complexity and Innovation'
-
value: Water_Institute
label: 'Water Institute'
-
value: Western_University
label: 'Western University'
-
value: Wilfrid_Laurier_University
label: 'Wilfrid Laurier University'
allowed_values_function: ''
allowed_values: []
allowed_values_function: '_uw_ct_site_footer_get_allowed_values'
module: options
locked: false
cardinality: 1
......
......@@ -2,20 +2,15 @@
namespace Drupal\uw_ct_site_footer\EventSubscriber;
use Drupal\Component\Serialization\Json;
use Drupal\Core\Cache\Cache;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Http\ClientFactory;
use Drupal\Core\Routing\UrlGeneratorInterface;
use Drupal\core_event_dispatcher\Event\Entity\EntityDeleteEvent;
use Drupal\core_event_dispatcher\Event\Entity\EntityInsertEvent;
use Drupal\core_event_dispatcher\Event\Entity\EntityUpdateEvent;
use Drupal\core_event_dispatcher\Event\Form\FormAlterEvent;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\hook_event_dispatcher\HookEventDispatcherInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
/**
* Class UwSiteFooterEventSubscriber.
......@@ -40,75 +35,6 @@ class UwSiteFooterEventSubscriber implements EventSubscriberInterface {
*/
protected $urlGenerator;
/**
* Http client factory.
*
* @var \Drupal\Core\Http\ClientFactory
*/
protected $clientFactory;
/**
* Alter form.
*
* @param \Drupal\core_event_dispatcher\Event\Form\FormAlterEvent $event
* The event.
*/
public function alterForm(FormAlterEvent $event): void {
// Get the form from the event.
$form = &$event->getForm();
if ($form['#form_id'] == 'node_uw_ct_site_footer_form') {
// Get the form state.
$form_state = $event->getFormState();
// Get content type from $form.
$bundle = $form['#process'][1][0]->get('bundle');
// Get uw_ct_site_footer node id if exists, otherwise empty string.
$nid = $this->getSiteFooterNid();
// If the content type is uw_ct_site_footer and it is
// node/add/uw_ct_site_footer page, and one uw_ct_site_footer node exists,
// redirect to node/{nid}/edit page.
if ($bundle == 'uw_ct_site_footer' && $form_state->get('value') == NULL && $nid) {
$url = $this->urlGenerator->generateFromRoute('entity.node.edit_form', ['node' => $nid], ['absolute' => TRUE]);
$response = new RedirectResponse($url);
$response->send();
return;
}
// The client to get from the API.
$client = $this->clientFactory->fromOptions([
'base_uri' => 'https://uwaterloo.ca/brand/',
]);
// The response from the API.
$response = $client->get('api/v1.0/uw-logos-site-footers');
// Decode API to JSON.
$site_logos = Json::decode($response->getBody());
// Set the default and no site footer logo option.
$options[0] = 'Site name (no logo)';
// Step through each for the site footer logos from API set options.
foreach ($site_logos as $site_logo) {
$options[$site_logo['nid']] = $site_logo['title'];
}
// Ensure that the new options are also added to the allowed_values list.
$fieldStorage = FieldStorageConfig::loadByName('node', 'field_site_footer_logo');
$fieldStorage->setSetting('allowed_values', $options);
$fieldStorage->save();
// Set the options in the form.
$form['field_site_footer_logo']['widget']['#options'] = $options;
}
}
/**
* {@inheritDoc}
*/
......@@ -140,7 +66,6 @@ class UwSiteFooterEventSubscriber implements EventSubscriberInterface {
*/
public static function getSubscribedEvents() {
return [
HookEventDispatcherInterface::FORM_ALTER => 'alterForm',
HookEventDispatcherInterface::ENTITY_INSERT => 'entityInsert',
HookEventDispatcherInterface::ENTITY_UPDATE => 'entityUpdate',
HookEventDispatcherInterface::ENTITY_DELETE => 'entityDelete',
......@@ -154,13 +79,10 @@ class UwSiteFooterEventSubscriber implements EventSubscriberInterface {
* Entity Type Manager, used to load entities.
* @param \Drupal\Core\Routing\UrlGeneratorInterface $urlGenerator
* Url Generator used to create url.
* @param \Drupal\Core\Http\ClientFactory $clientFactory
* Http requests using this factory.
*/
public function __construct(EntityTypeManagerInterface $entityTypeManager, UrlGeneratorInterface $urlGenerator, ClientFactory $clientFactory) {
public function __construct(EntityTypeManagerInterface $entityTypeManager, UrlGeneratorInterface $urlGenerator) {
$this->entityTypeManager = $entityTypeManager;
$this->urlGenerator = $urlGenerator;
$this->clientFactory = $clientFactory;
}
/**
......
<?php
/**
* @file
* Install, update and uninstall for site footer content type.
*/
use Drupal\Core\Config\FileStorage;
/**
* Update config to use allowed values functions and fix existing nodes.
*/
function uw_ct_site_footer_update_8101() {
// Get all the info about the feature revert, but we are
// going to do this independently without calling drush fra.
$config_path = drupal_get_path('module', 'uw_ct_site_footer') . '/config/install';
$source = new FileStorage($config_path);
$config_storage = \Drupal::service('config.storage');
$import = 'field.storage.node.field_site_footer_logo';
// Perform the revert.
$config_storage->write($import, $source->read($import));
}
......@@ -17,3 +17,36 @@ function uw_ct_site_footer_theme($existing, $type, $theme, $path) {
],
];
}
/**
* Helper function to get the allowed values from the brand site.
*
* @return array
* Array of site footer logos from the brand site.
*/
function _uw_ct_site_footer_get_allowed_values() {
// Brand API client.
$api = \Drupal::httpClient();
// The URL for the API call.
$url = 'https://uwaterloo.ca/brand/api/v1.0/uw-logos-site-footers';
// Get the response from the API.
$response = $api->get($url);
// Decode the categories from the API call.
$site_logos = json_decode($response->getBody());
// Set the first option as no logo.
$options[0] = 'Site name (no logo)';
// Step through each of the logos from the brand site,
// and set up options array.
foreach ($site_logos as $site_logo) {
$options[$site_logo->nid] = $site_logo->title;
}
// Return the options.
return $options;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment