media_acquiadam_report.module in Media: Acquia DAM 8
Provide views data for media_acquiadam_report.module.
File
modules/media_acquiadam_report/media_acquiadam_report.moduleView source
<?php
/**
* @file
* Provide views data for media_acquiadam_report.module.
*/
/**
* Implements hook_views_query_alter().
*
* Adds query condition to DAM listing to filter media bundles.
*/
function media_acquiadam_report_views_query_alter($view, $query) {
if ($view
->id() == 'acquia_dam_reporting' && $view
->getDisplay()->display['id'] == 'asset_report') {
// Limit the view to 'acquiadam_asset' media bundles.
$acquiadam_bundles = media_acquiadam_get_bundle_asset_id_fields();
$acquiadam_bundles = array_keys($acquiadam_bundles);
// Add media bundle query condition.
$query
->addWhere('conditions', 'media_field_data.bundle', $acquiadam_bundles, 'in');
}
}
/**
* Implements hook_views_data_alter().
*
* Adds a DAM source id field for use in the DAM listing.
*/
function media_acquiadam_report_views_data_alter(array &$data) {
$data['media']['acquiadam_source_id'] = [
'title' => t('Acquia DAM source id'),
'field' => [
'title' => t('Acquia DAM source id'),
'help' => t('The source id from the field configured in the asset mapping.'),
'id' => 'acquiadam_source_id',
],
];
}
/**
* Implements hook_theme_registry_alter().
*/
function media_acquiadam_report_theme_registry_alter(&$theme_registry) {
// DAM asset URL path.
try {
$dam_url = Drupal::service('media_acquiadam.acquiadam')
->getAccountSubscriptionDetails()->url;
} catch (Exception $x) {
watchdog_exception('media_acquiadam_report', $x);
return;
}
$dam_asset_url = 'https://' . $dam_url . '/cloud/#asset/';
// Views field display template to override.
$view_name_display = 'acquia_dam_reporting__asset_report';
$field = 'field_acquiadam_asset_id';
$template = 'views_view_field__' . $view_name_display . '__' . $field;
$template_hyphen = str_replace('_', '-', $template);
// Add module's template to the theme registry.
$theme_registry[$template] = $theme_registry['views_view_field'];
$theme_registry[$template]['template'] = $template_hyphen;
$theme_registry[$template]['variables']['acquiadam_asset_url'] = $dam_asset_url;
$theme_registry[$template]['path'] = drupal_get_path('module', 'media_acquiadam_report') . '/templates';
}
Functions
Name | Description |
---|---|
media_acquiadam_report_theme_registry_alter | Implements hook_theme_registry_alter(). |
media_acquiadam_report_views_data_alter | Implements hook_views_data_alter(). |
media_acquiadam_report_views_query_alter | Implements hook_views_query_alter(). |