You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
1.5 KiB
40 lines
1.5 KiB
<?php |
|
|
|
/** |
|
* Implements hook_entity_type_alter(). |
|
* |
|
* Adds the Metadata Profile tab to the entity configuration page. |
|
*/ |
|
function metadata_profile_entity_type_alter(array &$entity_types) { |
|
/** @var \Drupal\Core\Entity\EntityTypeInterface $entity_type */ |
|
foreach ($entity_types as $entity_type) { |
|
if ($entity_type->getBundleOf() && $entity_type->hasLinkTemplate('edit-form')) { |
|
$entity_type->setLinkTemplate('metadata-profile', $entity_type->getLinkTemplate('edit-form') . "/metadata-profile"); |
|
$entity_type->setLinkTemplate('metadata-download', $entity_type->getLinkTemplate('edit-form') . "/metadata-profile/download"); |
|
} |
|
} |
|
} |
|
|
|
/** |
|
* Implements hook_file_download(). |
|
*/ |
|
function metadata_profile_file_download($uri){ |
|
$stream_wrapper_manager = \Drupal::service('stream_wrapper_manager'); |
|
$scheme = $stream_wrapper_manager->getScheme($uri); |
|
$target = $stream_wrapper_manager->getTarget($uri); |
|
|
|
if ($scheme == 'temporary' && $target) { |
|
$request = \Drupal::request(); |
|
$route = $request->attributes->get('_route'); |
|
// Check if we were called by Profile download route. |
|
// No additional access checking needed here: route requires |
|
// "export configuration" permission, token is validated by the controller. |
|
// @see \Drupal\features\Controller\FeaturesController::downloadExport() |
|
if (str_ends_with($route, 'metadata_profile.download')) { |
|
return [ |
|
'Content-disposition' => 'attachment; filename="' . $target . '"', |
|
]; |
|
} |
|
} |
|
return NULL; |
|
}
|
|
|