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.
99 lines
3.6 KiB
99 lines
3.6 KiB
<?php |
|
|
|
/** |
|
* @file |
|
* Primary module hooks for OCFL Storage module. |
|
*/ |
|
|
|
use Drupal\Core\Routing\RouteMatchInterface; |
|
use Drupal\node\NodeInterface; |
|
|
|
/** |
|
* Implements hook_node_insert(). |
|
*/ |
|
function ocfl_storage_node_insert(NodeInterface $node) { |
|
\Drupal::service('ocfl_storage.ocfl_service')->saveNodeToOcfl($node); |
|
} |
|
|
|
/** |
|
* Implements hook_node_update(). |
|
*/ |
|
function ocfl_storage_node_update(NodeInterface $node) { |
|
\Drupal::service('ocfl_storage.ocfl_service')->saveNodeToOcfl($node); |
|
} |
|
|
|
/** |
|
* Implements hook_node_delete(). |
|
* |
|
* Note: Actual OCFL implementations typically mark objects as deleted or |
|
* create a new version indicating deletion, rather than physically removing them. |
|
* For this simplified module, we'll just log the deletion. |
|
*/ |
|
function ocfl_storage_node_delete(NodeInterface $node) { |
|
\Drupal::logger('ocfl_storage')->notice('Node %title (%nid) deleted. OCFL object will not be physically removed by this module, but a new version could be created to reflect deletion.', [ |
|
'%title' => $node->label(), |
|
'%nid' => $node->id(), |
|
]); |
|
} |
|
|
|
/** |
|
* Implements hook_help(). |
|
*/ |
|
function ocfl_storage_help($route_name, RouteMatchInterface $route_match) { |
|
switch ($route_name) { |
|
case 'help.page.ocfl_storage': |
|
$output = '<h3>' . t('About') . '</h3>'; |
|
$output .= '<p>' . t('The OCFL Storage module provides a simplified, OCFL-like file system storage for uploaded files and node metadata. It aims to demonstrate how content could be versioned and managed in a structured way outside of Drupal\'s default file system.') . '</p>'; |
|
$output .= '<h3>' . t('Usage') . '</h3>'; |
|
$output .= '<p>' . t('When a node is saved or updated, this module attempts to store its fields (as JSON metadata) and any attached files within an OCFL-like structure in your Drupal private files directory. You can browse the stored objects via the "Browse OCFL Objects" link under Content.') . '</p>'; |
|
return $output; |
|
|
|
case 'ocfl_storage.browse': |
|
return '<p>' . t('This page lists all OCFL-like objects currently stored by the module.') . '</p>'; |
|
|
|
case 'ocfl_storage.object_view': |
|
return '<p>' . t('Details for a specific OCFL-like object, including its versions and contents.') . '</p>'; |
|
} |
|
} |
|
|
|
/** |
|
* Implements hook_menu_links_alter(). |
|
*/ |
|
function ocfl_storage_menu_links_alter(&$links) { |
|
if (isset($links['system.admin_content'])) { |
|
$links['ocfl_storage.browse'] = [ |
|
'title' => t('Browse OCFL Objects'), |
|
'route_name' => 'ocfl_storage.browse', |
|
'parent' => 'system.admin_content', |
|
'weight' => 100, |
|
'expanded' => FALSE, |
|
]; |
|
} |
|
} |
|
|
|
/** |
|
* Implements hook_local_tasks_alter(). |
|
*/ |
|
function ocfl_storage_local_tasks_alter(&$local_tasks, $route_name) { |
|
if ($route_name == 'ocfl_storage.browse') { |
|
// Add a tab for the main browse page if needed. |
|
$local_tasks['ocfl_storage.browse']['title'] = t('Browse Objects'); |
|
$local_tasks['ocfl_storage.browse']['base_route'] = 'ocfl_storage.browse'; |
|
} |
|
if ($route_name == 'ocfl_storage.object_view') { |
|
// Add a tab for the object view page. |
|
$local_tasks['ocfl_storage.object_view']['title'] = t('Object Details'); |
|
$local_tasks['ocfl_storage.object_view']['base_route'] = 'ocfl_storage.object_view'; |
|
} |
|
} |
|
|
|
/** |
|
* Implements hook_entity_type_alter(). |
|
* |
|
* This hook is used to define a custom parameter converter for OCFL object IDs. |
|
*/ |
|
function ocfl_storage_entity_type_alter(array &$entity_types) { |
|
if (isset($entity_types['ocfl_object_id'])) { |
|
$entity_types['ocfl_object_id']->setHandlerClass('param_converter', 'Drupal\ocfl_storage\ParamConverter\OcflObjectIdConverter'); |
|
} |
|
}
|
|
|