Commit 1e623b6c authored by Chris Shantz's avatar Chris Shantz
Browse files

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

parents 85fd63ff 7e3c2da9
......@@ -9,8 +9,8 @@ field_name: field_site_footer_logo
entity_type: node
type: list_string
settings:
allowed_values: []
allowed_values_function: '_uw_ct_site_footer_get_allowed_values'
allowed_values: { }
allowed_values_function: _uw_ct_site_footer_get_allowed_values
module: options
locked: false
cardinality: 1
......
......@@ -35,32 +35,6 @@ class UwSiteFooterEventSubscriber implements EventSubscriberInterface {
*/
protected $urlGenerator;
/**
* {@inheritDoc}
*/
public function getSiteFooterNid() {
// The nid variable.
$nid = "";
// Query to see if there are site footer nids.
$nids = $this->entityTypeManager->getStorage('node')->getQuery()
->condition('type', 'uw_ct_site_footer')->execute();
// If there are nids process them.
if ($nids) {
// Step through each of the nids and get the one out.
// Note there are should only ever be one here.
foreach ($nids as $item) {
$nid = $item;
}
}
// Return back the nid.
return $nid;
}
/**
* {@inheritdoc}
*/
......
......@@ -106,12 +106,18 @@ class SiteFooterBlock extends BlockBase implements ContainerFactoryPluginInterfa
// If not on latest revision, just load the node.
if (end($url) == 'latest') {
// Get all the version ids (vids) for the node.
$vids = $this->entityTypeManager->getStorage('node')->revisionIds($node);
// Get the latest revision (vid) for the node.
$vid = $this->entityTypeManager->getStorage('node')->getLatestRevisionId($nid);
// Load the node based on the lastest revision.
// Load the node based on the latest revision.
$node = $this->entityTypeManager->getStorage('node')
->loadRevision(end($vids));
->loadRevision($vid);
}
// Make sure not to display unpublished/archived node, but display the
// latest node revision when on "Latest version" tab.
if (!$node->isPublished() && end($url) !== 'latest') {
return [];
}
$layout = [];
......
name: 'UW local site footer'
description: 'Creates a local site footer with custom block.'
type: module
core_version_requirement: '^8 || ^9'
core_version_requirement: '^8.9 || ^9'
dependencies:
- drupal:block
- drupal:content_moderation
- drupal:field
- drupal:language
- drupal:layout_builder
- drupal:layout_builder_restrictions
- drupal:layout_discovery
- drupal:menu_ui
- drupal:node
- drupal:options
- drupal:path
- drupal:text
- drupal:user
- drupal:uw_cfg_common
- drupal:workbench_access
- 'drupal:block'
- 'drupal:content_moderation'
- 'drupal:field'
- 'drupal:language'
- 'drupal:layout_builder'
- 'drupal:layout_builder_restrictions'
- 'drupal:layout_discovery'
- 'drupal:menu_ui'
- 'drupal:node'
- 'drupal:options'
- 'drupal:path'
- 'drupal:text'
- 'drupal:user'
- 'drupal:workbench_access'
- 'node_revision_delete:node_revision_delete'
- 'uw_cfg_common:uw_cfg_common'
......@@ -6,6 +6,11 @@
*/
use Drupal\Core\Config\FileStorage;
use Drupal\node\Entity\Node;
/**
* Implements hook_update_N().
*/
/**
* Update config to use allowed values functions and fix existing nodes.
......@@ -22,3 +27,25 @@ function uw_ct_site_footer_update_8101() {
// Perform the revert.
$config_storage->write($import, $source->read($import));
}
/**
* Delete all footers except the one that is in use.
*/
function uw_ct_site_footer_update_8102() {
// Get node IDs for all footers.
$nids = \Drupal::entityQuery('node')
->condition('type', 'uw_ct_site_footer')
->execute();
// Keep one footer by removing it from the list of nid's to be deleted. The
// last one is the one which would currently be displayed.
array_pop($nids);
// Delete all remaining footers.
foreach ($nids as $nid) {
$node = Node::load($nid);
if ($node) {
$node->delete();
}
}
}
......@@ -5,6 +5,9 @@
* Module file.
*/
use Drupal\Core\Form\FormStateInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
/**
* Implements hook_theme().
*/
......@@ -50,3 +53,26 @@ function _uw_ct_site_footer_get_allowed_values() {
// Return the options.
return $options;
}
/**
* Implements hook_form_FORM_ID_alter().
*
* Redirect node/add/uw_ct_site_footer to node/{nid}/edit if a
* uw_ct_site_footer node exists.
*/
function uw_ct_site_footer_form_node_uw_ct_site_footer_form_alter(array &$form, FormStateInterface $form_state, string $form_id): void {
global $base_url;
// Check if any uw_ct_site_footer content nodes exist and get the node ID.
$query = \Drupal::entityQuery('node')
->condition('type', 'uw_ct_site_footer');
$nids = $query->execute();
$nid = reset($nids);
// If a uw_ct_site_footer node exists, redirect to its edit page.
if ($nid) {
$url = $base_url . '/node/' . $nid . '/edit';
$response = new RedirectResponse($url);
$response->send();
}
}
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