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.
57 lines
2.0 KiB
57 lines
2.0 KiB
<?php |
|
use Drupal\Core\Entity\EntityInterface; |
|
use Drupal\Core\Url; |
|
/** |
|
* 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; |
|
} |
|
|
|
/** |
|
* Implements hook_entity_operation_alter(). |
|
*/ |
|
function metadata_profile_entity_operation_alter(array &$operations, EntityInterface $entity) { |
|
if ($entity->getEntityTypeId() === 'node_type') { |
|
|
|
$operations['metadata_profile'] = [ |
|
'title' => t('Metadata profile'), |
|
'weight' => 50, |
|
'url' => Url::fromRoute('entity.node_type.metadata_profile', [ |
|
'node_type' => $entity->id(), |
|
]), |
|
]; |
|
} |
|
}
|
|
|