Skip to content

Commit

Permalink
Moved metadata redirect view from config/install to config/optional.
Browse files Browse the repository at this point in the history
  • Loading branch information
kepol committed Dec 2, 2023
1 parent 55dad8b commit 196f416
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 13 deletions.
39 changes: 28 additions & 11 deletions quant.install
Original file line number Diff line number Diff line change
Expand Up @@ -138,25 +138,42 @@ function quant_update_9008() {
// Keep track of what gets saved.
$saved = [];
$installPath = \Drupal::service('extension.list.module')->getPath('quant') . '/config/install/';
$optionalPath = \Drupal::service('extension.list.module')->getPath('quant') . '/config/optional/';
$names = [
'quant_metadata_file',
'quant_metadata_node',
'quant_metadata_redirect',
'quant_metadata_taxonomy'
'quant_metadata_file' => $installPath,
'quant_metadata_node' => $installPath,
'quant_metadata_redirect' => $optionalPath, // Requires redirect module.
'quant_metadata_taxonomy' => $installPath,
];
foreach ($names as $name) {
foreach ($names as $name => $path) {
// Only create if the view doesn't exist.
if (!View::load($name)) {
$view = 'views.view.' . $name;
$configPath = $installPath . '/' . $view . '.yml';
$configPath = $path . '/' . $view . '.yml';
$data = Yaml::parse(file_get_contents($configPath));
\Drupal::configFactory()->getEditable($view)->setData($data)->save(TRUE);
$saved[] = $name;
try {
\Drupal::configFactory()->getEditable($view)->setData($data)->save(TRUE);
$saved[] = $name;
}
catch (\Exception $e) {
// Can happen if dependencies are not met.
}
}
}

if (empty($saved)) {
return 'No views saved.';
// Create message showing status.
$unsaved = [];
foreach $names as $name => $path) {
if (!in_array($name, $saved)) {
$unsaved[] = $name;
}
}
$message = [];
if (!empty($unsaved)) {
$message[] = 'Unsaved views: ' . implode(', ', $unsaved);
}
if (!empty($saved)) {
$message[] = 'Saved views: ' . implode(', ', $saved);
}
return 'Saved views: ' . implode(', ', $saved);
return implode('\n\n', $message);
}
4 changes: 2 additions & 2 deletions src/Plugin/views/field/QuantMetadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ protected function defineOptions() {
'url',
'published',
'content_timestamp',
'date_timestamp'
]
'date_timestamp',
],
];

return $options;
Expand Down

0 comments on commit 196f416

Please sign in to comment.