diff --git a/quant.module b/quant.module
index 77f469e9..8f5c9a90 100644
--- a/quant.module
+++ b/quant.module
@@ -412,6 +412,10 @@ function quant_modules_uninstalled($modules) {
* The path alias.
*/
function quant_path_alias_presave(EntityInterface $pathAlias) {
+ if (!$pathAlias || !$pathAlias->original) {
+ return;
+ }
+
// Original path alias.
$original_path = $pathAlias->original->get('path')->value;
$original_alias = $pathAlias->original->get('alias')->value;
diff --git a/src/Utility.php b/src/Utility.php
index 19ebae44..3124123f 100644
--- a/src/Utility.php
+++ b/src/Utility.php
@@ -127,55 +127,63 @@ public static function inList($item, array $list) {
* The markup with the page info.
*/
public static function getPageInfo(array $urls = NULL) : string {
- // Default to the current page.
- if (!$urls) {
- $urls = [self::getUrl()];
- }
-
- $client = \Drupal::service('quant_api.client');
- $response = $client->getUrlMeta($urls);
-
- if (isset($response['global_meta']['records'])) {
- // Show meta information for the pages in Quant.
- $found_urls = [];
- $output = '
';
- $output .= '
' . t('Quant Page Info') . '
';
- foreach ($response['global_meta']['records'] as $record) {
- $found_urls[] = $url = $record['meta']['url'];
- $output .= '
';
- $output .= '
Page info for ' . $url . '';
- $output .= '
';
- $output .= '- Published: ' . ($record['meta']['published'] ? t('Yes') : t('No')) . '
';
- $output .= '- Revisions: ' . $record['meta']['revision_count'] . '
';
- $date = DrupalDateTime::createFromTimestamp($record['meta']['content_timestamp'])->format('Y-m-d H:i:s');
- $output .= '- Updated: ' . $date . '
';
- $date = DrupalDateTime::createFromTimestamp($record['meta']['date_timestamp'])->format('Y-m-d H:i:s');
- $output .= '- Synced: ' . $date . '
';
- $output .= '
';
- $output .= '
';
+ try {
+ // Default to the current page.
+ if (!$urls) {
+ $urls = [self::getUrl()];
}
- // Note any URLs that were not in Quant.
- if (count($urls) != count($found_urls)) {
- if (count($urls) === 1) {
- $output .= '
' . t('Page info could not be found for this URL:') . '';
+ $client = \Drupal::service('quant_api.client');
+ $response = $client->getUrlMeta($urls);
+
+ if (isset($response['global_meta']['records'])) {
+ // Show meta information for the pages in Quant.
+ $found_urls = [];
+ $output = '
';
+ $output .= '
' . t('Quant Page Info') . '
';
+ foreach ($response['global_meta']['records'] as $record) {
+ $found_urls[] = $url = ($record['meta']['url'] ?? 'Url unknown');
+ $output .= '
';
+ $output .= '
Page info for ' . $url . '';
+ $output .= '
';
+ // @todo Fix underlying data per issue #3412934.
+ $output .= '- Published: ' . (($record['meta']['published'] ?? FALSE) ? t('Yes') : t('No')) . '
';
+ $output .= '- Revisions: ' . ($record['meta']['revision_count'] ?? 0) . '
';
+ $date = DrupalDateTime::createFromTimestamp($record['meta']['content_timestamp'] ?? 0)->format('Y-m-d H:i:s');
+ $output .= '- Updated: ' . $date . '
';
+ $date = DrupalDateTime::createFromTimestamp($record['meta']['date_timestamp'] ?? 0)->format('Y-m-d H:i:s');
+ $output .= '- Synced: ' . $date . '
';
+ $output .= '
';
+ $output .= '
';
}
- else {
- $output .= '
' . t('Page info could not be found for the following URLs:') . '';
+
+ // Note any URLs that were not in Quant.
+ if (count($urls) != count($found_urls)) {
+ if (count($urls) === 1) {
+ $output .= '
' . t('Page info could not be found for this URL:') . '';
+ }
+ else {
+ $output .= '
' . t('Page info could not be found for the following URLs:') . '';
+ }
+ $output .= '
';
}
- $output .= '';
- }
- foreach ($urls as $url) {
- if (!in_array($url, $found_urls)) {
- $output .= '- ' . $url . '
';
+ foreach ($urls as $url) {
+ if (!in_array($url, $found_urls)) {
+ $output .= '- ' . $url . '
';
+ }
+ $output .= '
';
}
- $output .= '
';
+
+ $output .= '
';
}
- $output .= '
';
+ return $output;
+ }
+ catch (\Exception $e) {
+ \Drupal::logger('quant')->error($e->getMessage());
+ return '';
}
- return $output;
}
}