public static function PageManager::export in Hook Update Deploy Tools 8
Same name and namespace in other branches
- 7 src/PageManager.php \HookUpdateDeployTools\PageManager::export()
Exports a single PageManager page (typically called from Drush).
Parameters
string $page_machine_name: The machine name of the Page Manager page to export.
Return value
string The URI of the item exported, or a failure message.
Overrides ExportInterface::export
File
- src/
PageManager.php, line 249
Class
- PageManager
- Public methods working with Panels.
Namespace
HookUpdateDeployToolsCode
public static function export($page_machine_name) {
$t = get_t();
try {
Check::notEmpty('panel_machine_name', $page_machine_name, TRUE);
$msg_return = '';
$path = HudtInternal::getStoragePath('page_manager');
$machine_name = HudtInternal::normalizeMachineName($page_machine_name);
$file_name = HudtInternal::normalizeFileName($page_machine_name);
$file_uri = DRUPAL_ROOT . '/' . $path . $file_name;
self::canExport();
// Load the page_manager page if it exists.
$page = page_manager_page_load($machine_name);
$handlers = page_manager_load_task_handlers(page_manager_get_task('page'), $machine_name);
if (!empty($page)) {
// It exists, so export it.
$export_contents = page_manager_page_export($page, $handlers);
// Save the file.
$msg_return = HudtInternal::writeFile($file_uri, $export_contents);
}
else {
// Could not be loaded, so nothing to export. Error gracefully.
$vars = array(
'@machine_name' => $machine_name,
);
$msg_error = $t("The PageManager page '@machine_name' could not be loaded. Please check the spelling of the machine name you are trying to export", $vars);
$msg_return = $t('ERROR') . ': ';
$msg_return .= $t("PageManager page not found. Check the spelling of the machine name you are trying to export");
}
} catch (\Exception $e) {
// Any errors from this command do not need to be watchdog logged.
$e->logIt = FALSE;
$vars = array(
'!error' => method_exists($e, 'logMessage') ? $e
->logMessage() : $e
->getMessage(),
);
$msg_error = $t("Caught exception: !error", $vars);
}
if (!empty($msg_error)) {
drush_log($msg_error, 'error');
}
return !empty($msg_return) ? $msg_return : $msg_error;
}