diff --git a/config/install/views.view.quant_metadata_redirect.yml b/config/optional/views.view.quant_metadata_redirect.yml similarity index 100% rename from config/install/views.view.quant_metadata_redirect.yml rename to config/optional/views.view.quant_metadata_redirect.yml diff --git a/quant.install b/quant.install index a9201c2e..96aec40e 100644 --- a/quant.install +++ b/quant.install @@ -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); } diff --git a/src/Plugin/views/field/QuantMetadata.php b/src/Plugin/views/field/QuantMetadata.php index ea420a5f..6ca1aa51 100644 --- a/src/Plugin/views/field/QuantMetadata.php +++ b/src/Plugin/views/field/QuantMetadata.php @@ -63,8 +63,8 @@ protected function defineOptions() { 'url', 'published', 'content_timestamp', - 'date_timestamp' - ] + 'date_timestamp', + ], ]; return $options;