Skip to content

Commit

Permalink
Merge branch 'develop' into YALB-1550-single_content_sync
Browse files Browse the repository at this point in the history
  • Loading branch information
codechefmarc authored Sep 8, 2023
2 parents c0b4405 + 440838f commit ba64ccd
Show file tree
Hide file tree
Showing 21 changed files with 333 additions and 141 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ dependencies:
config:
- block_content.type.cta_banner
- field.field.block_content.cta_banner.field_heading
- field.field.block_content.cta_banner.field_heading_level
- field.field.block_content.cta_banner.field_instructions
- field.field.block_content.cta_banner.field_link
- field.field.block_content.cta_banner.field_media
Expand Down Expand Up @@ -39,6 +40,12 @@ content:
maxlength_js: 50
maxlength_js_label: 'Content limited to @limit characters, remaining: <strong>@remaining</strong>'
maxlength_js_enforce: false
field_heading_level:
type: options_select
weight: 16
region: content
settings: { }
third_party_settings: { }
field_instructions:
type: markup
weight: 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ dependencies:
config:
- block_content.type.grand_hero
- field.field.block_content.grand_hero.field_heading
- field.field.block_content.grand_hero.field_heading_level
- field.field.block_content.grand_hero.field_instructions
- field.field.block_content.grand_hero.field_link
- field.field.block_content.grand_hero.field_media
Expand Down Expand Up @@ -39,6 +40,12 @@ content:
maxlength_js: 50
maxlength_js_label: 'Content limited to @limit characters, remaining: <strong>@remaining</strong>'
maxlength_js_enforce: false
field_heading_level:
type: options_select
weight: 10
region: content
settings: { }
third_party_settings: { }
field_instructions:
type: markup
weight: 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ dependencies:
config:
- block_content.type.cta_banner
- field.field.block_content.cta_banner.field_heading
- field.field.block_content.cta_banner.field_heading_level
- field.field.block_content.cta_banner.field_instructions
- field.field.block_content.cta_banner.field_link
- field.field.block_content.cta_banner.field_media
Expand All @@ -27,6 +28,13 @@ content:
third_party_settings: { }
weight: 1
region: content
field_heading_level:
type: list_key
label: hidden
settings: { }
third_party_settings: { }
weight: 6
region: content
field_link:
type: link_separate
label: hidden
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ dependencies:
config:
- block_content.type.grand_hero
- field.field.block_content.grand_hero.field_heading
- field.field.block_content.grand_hero.field_heading_level
- field.field.block_content.grand_hero.field_instructions
- field.field.block_content.grand_hero.field_link
- field.field.block_content.grand_hero.field_media
Expand All @@ -27,6 +28,13 @@ content:
third_party_settings: { }
weight: 1
region: content
field_heading_level:
type: list_key
label: hidden
settings: { }
third_party_settings: { }
weight: 6
region: content
field_link:
type: link_separate
label: hidden
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
uuid: c4cb4f27-4116-41c1-bf7e-3be014652c3a
langcode: en
status: true
dependencies:
config:
- block_content.type.cta_banner
- field.storage.block_content.field_heading_level
module:
- options
id: block_content.cta_banner.field_heading_level
field_name: field_heading_level
entity_type: block_content
bundle: cta_banner
label: 'Heading Level'
description: 'Optionally override heading level for this banner'
required: true
translatable: false
default_value:
-
value: '2'
default_value_callback: ''
settings: { }
field_type: list_string
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
uuid: 7b19e30a-e34c-4869-8522-0ec9074beca3
langcode: en
status: true
dependencies:
config:
- block_content.type.grand_hero
- field.storage.block_content.field_heading_level
module:
- options
id: block_content.grand_hero.field_heading_level
field_name: field_heading_level
entity_type: block_content
bundle: grand_hero
label: 'Heading Level'
description: 'Optionally override heading level for this banner'
required: true
translatable: true
default_value:
-
value: '2'
default_value_callback: ''
settings: { }
field_type: list_string
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
uuid: 55bae3c6-a2a3-4e10-85ac-63cc9eefc787
langcode: en
status: true
dependencies:
module:
- block_content
- options
id: block_content.field_heading_level
field_name: field_heading_level
entity_type: block_content
type: list_string
settings:
allowed_values:
-
value: '1'
label: H1
-
value: '2'
label: H2
allowed_values_function: ''
module: options
locked: false
cardinality: 1
translatable: true
indexes: { }
persist_with_no_fields: false
custom_storage: false
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,3 @@
justify-content: flex-end;
border-top: none;
}

.ys-alert-settings .js-form-type-checkbox {
background-color: var(--darkest-gray);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,3 @@ type: module
description: YaleSites Core Configuation
core_version_requirement: '^9 || ^10'
package: YaleSites
dependencies:
- menu_item_extras
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@
*/

use Drupal\Core\Cache\Cache;
use Drupal\Core\Entity\Entity\EntityFormDisplay;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Render\Element;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Url;
use Drupal\menu_item_extras\Entity\MenuItemExtrasMenuLinkContent;

/**
* @file
Expand Down Expand Up @@ -317,91 +315,3 @@ function ys_core_preprocess_image_widget(&$variables) {
function ys_core_taxonomy_term_update() {
Cache::invalidateTags(['rendered']);
}

/**
* The following functions add menu item extras fields to node add/edit forms.
*
* @see https://www.drupal.org/project/menu_item_extras/issues/2992096#comment-14140361
*/

/**
* Implements hook_form_FORM_ID_alter().
*/
function ys_core_form_node_page_edit_form_alter(&$form, FormStateInterface $form_state, $form_id) {
ys_core_page_form_alter($form, $form_state);
}

/**
* Implements hook_form_FORM_ID_alter().
*/
function ys_core_form_node_page_form_alter(&$form, FormStateInterface $form_state, $form_id) {
ys_core_page_form_alter($form, $form_state);
}

/**
* THe Drupal backend cache renderer service.
*
* @var array $form
* The form array.
* @var Drupal\Core\Form\FormStateInterface $form_state
* The current form state.
*/
function ys_core_page_form_alter(&$form, FormStateInterface $form_state) {

// Add menu link fields to node form.
if ($link = _ys_core_get_link($form_state)) {
$form_display = EntityFormDisplay::load('menu_link_content.' . $link->getMenuName() . '.default');
assert($form_display instanceof EntityFormDisplay);
$form['menu']['link']['extra'] = [
'#type' => 'container',
'#parents' => ['menu', 'extra'],
];
$form_display->buildForm($link, $form['menu']['link']['extra'], $form_state);
// Only keep custom fields, other properties already are in the form.
foreach (Element::children($form['menu']['link']['extra']) as $key) {
if (strpos($key, 'field_') !== 0) {
unset($form['menu']['link']['extra'][$key]);
}
}

foreach (array_keys($form['actions']) as $action) {
if ($action != 'preview' && isset($form['actions'][$action]['#type']) && $form['actions'][$action]['#type'] === 'submit') {
$form['actions'][$action]['#submit'][] = 'ys_core_save_menu_link_fields';
}
}
}
}

/**
* Saves the menu item extras when on the node add/edit pages.
*
* @throws \Drupal\Core\Entity\EntityStorageException
*/
function ys_core_save_menu_link_fields(array $form, FormStateInterface $form_state) {
if ($link = _ys_core_get_link($form_state)) {
$form_display = EntityFormDisplay::load('menu_link_content.' . $link->getMenuName() . '.default');
assert($form_display instanceof EntityFormDisplay);
$form_display->extractFormValues($link, $form['menu']['link']['extra'], $form_state);
$link->save();
}
}

/**
* Gets any menu item extras content.
*
* @return Drupal\menu_item_extras\Entity\MenuItemExtrasMenuLinkContent
* Menu item extras content.
*/
function _ys_core_get_link(FormStateInterface $form_state) {
/** @var Drupal\node\Entity $form_state */
$node = $form_state->getFormObject()->getEntity();
$defaults = menu_ui_get_menu_link_defaults($node);
if ($mlid = $defaults['entity_id']) {
return MenuItemExtrasMenuLinkContent::load($mlid);
}
return MenuItemExtrasMenuLinkContent::create($defaults);
}

/**
* End allow menu item extras fields to be included on node add and edit forms.
*/
Loading

0 comments on commit ba64ccd

Please sign in to comment.