Skip to content
Snippets Groups Projects
Commit 26e1951d authored by Adam Zimmermann's avatar Adam Zimmermann
Browse files

Issue #3380278 by adamzimmermann, apotek: Schema missing for `asset_formats` key in module settings

parent 6cde0266
No related branches found
Tags 10.3.6
No related merge requests found
......@@ -138,13 +138,10 @@ tag_types:
content_types:
- Photograph: { }
- Book:
use_datatable: true
- 'File Cabinet': { }
asset_formats:
TRX:
- 'Example 1'
TR1:
- 'Example 2'
use_datatable: true
asset_format: TR1
- 'File Cabinet':
asset_format: TRX
base_path: 'https://example.orangelogic.com'
client_id: XXX
query_string: UseSession=ABC123
......
......@@ -26,18 +26,6 @@ orange_dam.settings:
sequence:
type: orange_dam.content_type
label: 'Content Type'
asset_formats:
type: mapping
label: 'Content Type <> Asset Format Mapping'
mapping:
label: 'Asset Format'
type: string
content_types:
type: sequence
label: 'Content Types'
sequence:
type: string
label: 'Content Type'
asset_url_follow_latest:
type: boolean
label: Asset URL should always retrieve the latest version
......@@ -79,3 +67,6 @@ orange_dam.content_type:
use_datatable:
type: boolean
label: 'Augment with Data Table data'
asset_format:
type: string
label: 'Orange DAM asset format for the content type'
......@@ -24,3 +24,24 @@ function orange_dam_update_94101() {
}
}
}
/**
* Update asset_formats config to be part of content_types config.
*/
function orange_dam_update_94102() {
$config = \Drupal::configFactory()->getEditable('orange_dam.settings');
$content_types = $config->get('content_types');
$asset_formats = $config->get('asset_formats');
if ($content_types && is_array($content_types) && !empty($content_types)) {
foreach ($asset_formats as $format_id => $asset_format) {
if (is_array($asset_format)) {
foreach ($asset_format as $content_type) {
$content_types[$content_type]['asset_format'] = $format_id;
}
}
$config->set('content_types', $content_types)->save();
}
}
$config->clear('asset_formats');
$config->save();
}
......@@ -31,6 +31,7 @@ services:
class: Drupal\orange_dam\OrangeDamConfigurationManager
arguments:
- '@config.factory'
- '@logger.factory'
# Manages preparing content for migrations and building the migration queues.
orange_dam.migration_data_manager:
......
......@@ -3,6 +3,8 @@
namespace Drupal\orange_dam;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Logger\LoggerChannelFactoryInterface;
use Drupal\jfkl_orange_dam\OrangeDamContentManager;
/**
* Manages the retrieval and validation of configuration.
......@@ -19,6 +21,7 @@ class OrangeDamConfigurationManager {
*/
public function __construct(
protected ConfigFactoryInterface $configFactory,
protected LoggerChannelFactoryInterface $loggerChannelFactory,
) {}
/**
......@@ -69,22 +72,44 @@ class OrangeDamConfigurationManager {
}
/**
* Get an array of allowed asset formats.
* Get a list of asset formats keyed by their associated content type.
*
* @return string[]
* An array of allowed asset formats.
* A list of asset formats keyed by their associated content type.
*/
public function getAssetFormats(): array {
// Retrieve and validate the asset format configuration.
$asset_formats = $this->configFactory
->get(static::ORANGE_DAM_CONFIG)
->get('asset_formats');
if (empty($asset_formats)) {
throw new \Exception(
'Missing "orange_dam.settings asset_formats" configuration.'
);
$content_types = $this->getContentTypes();
$content_type_formats = [];
foreach ($content_types as $content_type => $content_type_configuration) {
if (isset($content_type_configuration['asset_format'])) {
$content_type_formats[$content_type] = $content_type_configuration['asset_format'];
}
}
return $content_type_formats;
}
/**
* Determine the asset format to use for a given content type.
*
* @param string $content_type
* The content type.
*
* @return string|false
* The asset format or FALSE if one was unable to be found.
*
* @throws \Exception
*/
public function getAssetFormat(string $content_type) {
$asset_formats = $this->getAssetFormats();
if (isset($asset_formats[$content_type])) {
return $asset_formats[$content_type];
}
return $asset_formats;
// Log a warning if no match was found.
$this->loggerChannelFactory->get(OrangeDamContentManager::LOGGER_CHANNEL)->warning(
'Unable to find an asset type mapping for content type :content_type.', [
':content_type' => $content_type,
]);
return FALSE;
}
}
......@@ -415,7 +415,7 @@ class OrangeDamQueueDataManager implements OrangeDamQueueDataManagerInterface {
return FALSE;
}
// Get the asset format and verify that a value was found.
$asset_format = $this->getAssetFormat($content_type);
$asset_format = $this->orangeDamConfiguration->getAssetFormat($content_type);
if (!$asset_format) {
return FALSE;
}
......@@ -426,31 +426,4 @@ class OrangeDamQueueDataManager implements OrangeDamQueueDataManagerInterface {
);
}
/**
* Determine the asset format to use for a given content type.
*
* @param string $content_type
* The content type.
*
* @return string|false
* The asset URL or FALSE if one was unable to be generated.
*
* @throws \Exception
*/
public function getAssetFormat(string $content_type) {
$asset_formats = $this->orangeDamConfiguration->getAssetFormats();
// Map the content type to the asset format.
foreach ($asset_formats as $asset_format => $content_types) {
if (in_array($content_type, $content_types)) {
return $asset_format;
}
}
// Log a warning if no match was found.
$this->logger->warning(
'Unable to find an asset type mapping for content type :content_type.', [
':content_type' => $content_type,
]);
return FALSE;
}
}
......@@ -24,7 +24,7 @@ class OrangeDamAssetFormat extends OrangeDamProcessBase {
* {@inheritdoc}
*/
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
return $this->orangeDamQueueDataManager->getAssetFormat($value) ?: '';
return $this->orangeDamConfigurationManager->getAssetFormat($value) ?: '';
}
}
......@@ -6,6 +6,7 @@ use Drupal\Core\Logger\LoggerChannelFactoryInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\migrate\ProcessPluginBase;
use Drupal\orange_dam\OrangeDamApi;
use Drupal\orange_dam\OrangeDamConfigurationManager;
use Drupal\orange_dam\OrangeDamQueueDataManager;
use Symfony\Component\DependencyInjection\ContainerInterface;
......@@ -31,6 +32,7 @@ abstract class OrangeDamProcessBase extends ProcessPluginBase implements Contain
protected LoggerChannelFactoryInterface $loggerChannelFactory,
protected OrangeDamQueueDataManager $orangeDamQueueDataManager,
protected OrangeDamApi $orangeDamApi,
protected OrangeDamConfigurationManager $orangeDamConfigurationManager,
) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->logger = $this->loggerChannelFactory->get('orange_dam.migration');
......@@ -47,6 +49,7 @@ abstract class OrangeDamProcessBase extends ProcessPluginBase implements Contain
$container->get('logger.factory'),
$container->get('orange_dam.queue_data_manager'),
$container->get('orange_dam.api'),
$container->get('orange_dam.configuration_manager'),
);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment