Skip to content

Commit

Permalink
Relayout of Training/Workshops and Service Catalog (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
redndahead authored Feb 13, 2024
1 parent 760471b commit 717fadd
Show file tree
Hide file tree
Showing 24 changed files with 1,497 additions and 397 deletions.
3 changes: 1 addition & 2 deletions .gitpod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,7 @@ tasks:
drush then $THEME_NAME &&
drush cset system.theme default $THEME_NAME -y &&
drush config:pages-set-field-value stanford_basic_site_settings su_site_dropdowns 1 &&
drush php-eval '\Drupal\node\Entity\Node::load(13)->setPublished()->save();' &&
drush php-eval '\Drupal\menu_link_content\Entity\MenuLinkContent::create(["title" => "Submenu link", "link" => ["uri" => "https://google.com"], "menu_name" => "main", "parent" => "menu_link_field:node_field_menulink_e18a741f-7d86-492a-a02f-7ca73989ca13_und", "expanded" => TRUE, "weight" => 0])->save();'
drush php-script set-default-content --script-path=$GITPOD_REPO_ROOT/docroot/themes/custom/$THEME_NAME
command: |
export THEME_NAME=${PWD##*/} &&
export PREVIEW_FULL_URL=`gp url 8001` &&
Expand Down
2 changes: 1 addition & 1 deletion dist/css/main.css

Large diffs are not rendered by default.

321 changes: 241 additions & 80 deletions dist/js/airtable-list-builder.js

Large diffs are not rendered by default.

13 changes: 4 additions & 9 deletions gsb_research_hub_subtheme.libraries.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,8 @@ airtable-list-builder:
js:
dist/js/airtable-list-builder.js: {}
//cdnjs.cloudflare.com/ajax/libs/jquery.isotope/3.0.6/isotope.pkgd.min.js: {type: external, minified: true}
# dist/css/print.css: { media: print }
# base:
# dist/css/base.css: { weight: 100 }
# layout:
# dist/css/layout.css: {}
# component:
# dist/css/components.css: {}
# state:
# dist/css/state.css: {}
//cdnjs.cloudflare.com/ajax/libs/chosen/1.8.7/chosen.jquery.min.js: {type: external, minified: true}
css:
theme:
//cdnjs.cloudflare.com/ajax/libs/chosen/1.4.2/chosen.min.css: {}

26 changes: 25 additions & 1 deletion gsb_research_hub_subtheme.theme
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function gsb_research_hub_subtheme_theme_suggestions_block_alter(array &$suggest
* Implements hook_theme_suggestions_HOOK_alter().
*/
function gsb_research_hub_subtheme_theme_suggestions_paragraph_alter(array &$suggestions, array $variables) {
if (isset($variables['elements']['su_wysiwyg_text'])) {
if (isset($variables['elements']['su_wysiwyg_text']) && isset($variables['elements']['su_wysiwyg_text']['#object'])) {
$paragraph = $variables['elements']['su_wysiwyg_text']['#object'];
$jsonConfig = Json::decode(strip_tags($paragraph->su_wysiwyg_text->value));
if (!is_null($jsonConfig) && isset($jsonConfig['type']) && $jsonConfig['type'] == 'airtable') {
Expand All @@ -46,6 +46,30 @@ function gsb_research_hub_subtheme_preprocess_paragraph(&$variables) {
$jsonConfig = Json::decode(strip_tags($paragraph->su_wysiwyg_text->value));
if (!is_null($jsonConfig) && isset($jsonConfig['type']) && $jsonConfig['type'] == 'airtable') {
$variables['#attached']['library'][] = 'gsb_research_hub_subtheme/airtable-list-builder';

$sl_env_conf = [
'dev' => [
'snaplogicURL' => 'https://snaplogic-dev.stanford.edu/api/1/rest/feed-master/queue/StanfordDev',
'snaplogicToken' => 'iQ7GGRoNRcGi8iZf28xSgDgaDDUslteL',
],
'test' => [
'snaplogicURL' => 'https://snaplogic-uat.stanford.edu/api/1/rest/feed-master/queue/StanfordUAT',
'snaplogicToken' => 'J4G3SZC0cFVVZLr93TAJtm8Lnj6Jkuop',
],
'prod' => [
'snaplogicURL' => 'https://snaplogic.stanford.edu/api/1/rest/feed-master/queue/StanfordProd',
'snaplogicToken' => '0mdOOeXqOuQdFUxwt9ngJ3KSlxh7v1z2',
],
];

$sl_env = theme_get_setting('gsb_research_hub_subtheme_sl_env', 'gsb_research_hub_subtheme');

$jsVars = is_null($sl_env) ? $sl_env_conf['prod'] : $sl_env_conf[$sl_env];
if (isset($jsonConfig['variables'])) {
$jsVars = array_merge($jsonConfig['variables'], $jsVars);
}

$variables['#attached']['drupalSettings']['gsbResearchHubSubtheme'] = $jsVars;
}
}
}
Expand Down
100 changes: 100 additions & 0 deletions set-default-content.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
<?php
/*******************
** Enable Person **
*******************/
\Drupal\node\Entity\Node::load(13)->setPublished()->save();

/****************
** Menu Items **
****************/
// External Link
\Drupal\menu_link_content\Entity\MenuLinkContent::create(["title" => "Submenu link", "link" => ["uri" => "https://google.com"], "menu_name" => "main", "parent" => "menu_link_field:node_field_menulink_e18a741f-7d86-492a-a02f-7ca73989ca13_und", "expanded" => TRUE, "weight" => 0])->save();


/********************
** Airtable Items **
********************/
$at_menu = \Drupal\menu_link_content\Entity\MenuLinkContent::create(["title" => "Airtable", "link" => ["uri" => "internal:/"], "menu_name" => "main", "parent" => "", "expanded" => TRUE, "weight" => 0]);
$at_menu->save();
$at_menu_id = "menu_link_content:" . $at_menu->uuid();
$airtable_pages = [
[
'title' => 'Service Catalog',
'wysiwyg_text' => '{"type":"airtable","view": "service_catalog"}',
'menu_parent' => $at_menu_id,
],
[
'title' => 'Past Trainings & Workshops',
'wysiwyg_text' => '{"type":"airtable","view": "training_past"}',
'menu_parent' => $at_menu_id,
],
[
'title' => 'Upcoming Trainings & Workshops',
'wysiwyg_text' => '{"type":"airtable","view": "training_upcoming"}',
'menu_parent' => $at_menu_id,
],
[
'title' => 'All Training',
'wysiwyg_text' => '{"type":"airtable","view": "training"}',
'menu_parent' => '',
],
];


foreach ($airtable_pages as $page) {
// Create Service Catalog Node
$at_node = \Drupal::entityTypeManager()->getStorage("node")->create([
"type" => "stanford_page",
"title" => $page['title'],
]);
$at_node->save();

// Create layout for paragraph for Service Catalog.
$at_paragraph_layout = \Drupal::entityTypeManager()->getStorage("paragraph")->create([
"type" => "stanford_layout",
"parent_id" => $at_node->id(),
"parent_type" => "node",
"parent_field_name" => "su_page_components",
]);

$at_paragraph_layout->setBehaviorSettings("layout_paragraphs", [
"layout" => "layout_paragraphs_1_column",
"config" => [
"label" => ""
],
"parent_uuid" => "",
"region" => ""
]);
$at_paragraph_layout->save();

// Create paragraph for Service Catalog
$at_paragraph = \Drupal::entityTypeManager()->getStorage("paragraph")->create([
"type" => "stanford_wysiwyg",
"parent_id" => $at_node->id(),
"parent_type" => "node",
"parent_field_name" => "su_page_components",
"su_wysiwyg_text" => $page['wysiwyg_text'],
]);

$at_paragraph->setBehaviorSettings("layout_paragraphs", [
"parent_uuid" => $at_paragraph_layout->uuid(),
"region" => "main"
]);
$at_paragraph->save();

// Add paragraph to service catalog node.
$at_node->su_page_components = [
[
"target_id" => $at_paragraph_layout->id(),
"target_revision_id" => $at_paragraph_layout->getRevisionId()
],
[
"target_id" => $at_paragraph->id(),
"target_revision_id" => $at_paragraph->getRevisionId()
]
];
$at_node->save();

// Set Menu
\Drupal\menu_link_content\Entity\MenuLinkContent::create(["title" => $page['title'], "link" => ["uri" => "internal:/node/" . $at_node->id()], "menu_name" => "main", "parent" => $page['menu_parent'], "expanded" => TRUE, "weight" => 0])->save();
}
11 changes: 11 additions & 0 deletions src/assets/svg/arrow-down.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 717fadd

Please sign in to comment.