Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #61: Fix indentation #66

Merged
merged 3 commits into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
224 changes: 112 additions & 112 deletions collabora_online.module
Original file line number Diff line number Diff line change
Expand Up @@ -33,42 +33,42 @@ use Drupal\media\MediaInterface;
function collabora_online_theme($existing, $type, $theme, $path) {

return [
'collabora_online' => [
'render element' => 'children',
'template' => 'collabora-online',
'variables' => [
'accessToken' => 'test',
'accessTokenTtl' => '86400',
'iFrameStyle' => 'width:95%;',
'closebutton' => '',
'allowfullscreen' => '',
'wopiSrc' => 'http://localhost:9980/',
'wopiClient' => 'https://localhost:9980/',
],
'collabora_online' => [
'render element' => 'children',
'template' => 'collabora-online',
'variables' => [
'accessToken' => 'test',
'accessTokenTtl' => '86400',
'iFrameStyle' => 'width:95%;',
'closebutton' => '',
'allowfullscreen' => '',
'wopiSrc' => 'http://localhost:9980/',
'wopiClient' => 'https://localhost:9980/',
],
// This is the template for the field preview.
'collabora_online_preview' => [
'render element' => 'children',
'template' => 'collabora-online-preview',
'variables' => [
'editorUrl' => 'about:blank',
'fileName' => '',
],
],
// This is the template for the field preview.
'collabora_online_preview' => [
'render element' => 'children',
'template' => 'collabora-online-preview',
'variables' => [
'editorUrl' => 'about:blank',
'fileName' => '',
],
// This is the template for the complete page with embedding.
'collabora_online_full' => [
'template' => 'collabora-online-full',
'variables' => [
'accessToken' => 'test',
'accessTokenTtl' => '86400',
'iFrameStyle' => '',
'closebutton' => '',
'allowfullscreen' => '',
'wopiSrc' => '/wopi/files/123',
'wopiClient' => 'https://localhost:9980/',
],
'file' => 'collabora_online.theme.inc',
],
// This is the template for the complete page with embedding.
'collabora_online_full' => [
'template' => 'collabora-online-full',
'variables' => [
'accessToken' => 'test',
'accessTokenTtl' => '86400',
'iFrameStyle' => '',
'closebutton' => '',
'allowfullscreen' => '',
'wopiSrc' => '/wopi/files/123',
'wopiClient' => 'https://localhost:9980/',
],
'file' => 'collabora_online.theme.inc',
],
];
}

Expand All @@ -79,42 +79,42 @@ function collabora_online_theme($existing, $type, $theme, $path) {
* open the viewer/editor directly.
*/
function collabora_online_entity_operation(EntityInterface $entity) {
if (($entity->getEntityTypeId() != "media") ||
($entity->getSource()->getPluginId() != "file")) {
return [];
}
if (($entity->getEntityTypeId() != "media") ||
($entity->getSource()->getPluginId() != "file")) {
return [];
}

/** @var \Drupal\media\MediaInterface $media */
$media = $entity;
/** @var \Drupal\media\MediaInterface $media */
$media = $entity;

if (!$media->access('preview in collabora')) {
return [];
}
if (!$media->access('preview in collabora')) {
return [];
}

$file = CoolUtils::getFile($media);
$type = CoolUtils::getDocumentType($file);
$file = CoolUtils::getFile($media);
$type = CoolUtils::getDocumentType($file);

if ($type == NULL) {
return [];
}
if ($type == NULL) {
return [];
}

$entries = [
'collabora_online_view' => [
'title' => t("View in Collabora Online"),
'weight' => 50,
'url' => CoolUtils::getEditorUrl($media, FALSE),
],
];
$entries = [
'collabora_online_view' => [
'title' => t("View in Collabora Online"),
'weight' => 50,
'url' => CoolUtils::getEditorUrl($media, FALSE),
],
];

if (CoolUtils::canEdit($file) && $media->access('edit in collabora')) {
$entries['collabora_online_edit'] = [
'title' => t("Edit in Collabora Online"),
'weight' => 50,
'url' => CoolUtils::getEditorUrl($media, TRUE),
];
}
if (CoolUtils::canEdit($file) && $media->access('edit in collabora')) {
$entries['collabora_online_edit'] = [
'title' => t("Edit in Collabora Online"),
'weight' => 50,
'url' => CoolUtils::getEditorUrl($media, TRUE),
];
}

return $entries;
return $entries;
}

/**
Expand All @@ -123,56 +123,56 @@ function collabora_online_entity_operation(EntityInterface $entity) {
* Checks access for the new media operations provided by this module.
*/
function collabora_online_media_access(MediaInterface $media, string $operation, AccountInterface $account): AccessResultInterface {
$type = $media->bundle();
switch ($operation) {
case 'preview in collabora':
if ($media->isPublished()) {
return AccessResult::allowedIfHasPermission($account, "preview $type in collabora")
->addCacheableDependency($media);
}
$preview_own_permission = "preview own unpublished $type in collabora";
$access_result = AccessResult::allowedIfHasPermission($account, $preview_own_permission)
->addCacheableDependency($media);
if (!$access_result->isAllowed()) {
return $access_result;
}
// Use '==' because Drupal sometimes loads integers as strings.
$is_owner = ($account->id() && $account->id() == $media->getOwnerId());
if ($is_owner) {
$access_result = AccessResult::allowed();
}
else {
$access_result = AccessResult::neutral()
->setReason("The user has the '$preview_own_permission' permission, but is not the owner of the media item.");
}
return $access_result
->cachePerUser()
->addCacheableDependency($media);
$type = $media->bundle();
switch ($operation) {
case 'preview in collabora':
if ($media->isPublished()) {
return AccessResult::allowedIfHasPermission($account, "preview $type in collabora")
->addCacheableDependency($media);
}
$preview_own_permission = "preview own unpublished $type in collabora";
$access_result = AccessResult::allowedIfHasPermission($account, $preview_own_permission)
->addCacheableDependency($media);
if (!$access_result->isAllowed()) {
return $access_result;
}
// Use '==' because Drupal sometimes loads integers as strings.
$is_owner = ($account->id() && $account->id() == $media->getOwnerId());
if ($is_owner) {
$access_result = AccessResult::allowed();
}
else {
$access_result = AccessResult::neutral()
->setReason("The user has the '$preview_own_permission' permission, but is not the owner of the media item.");
}
return $access_result
->cachePerUser()
->addCacheableDependency($media);

case 'edit in collabora':
if ($account->hasPermission("edit any $type in collabora")) {
return AccessResult::allowed()
->cachePerPermissions();
}
$edit_own_permission = "edit own $type in collabora";
$access_result = AccessResult::allowedIfHasPermission($account, $edit_own_permission);
if (!$access_result->isAllowed()) {
return $access_result;
}
// Use '==' because Drupal sometimes loads integers as strings.
$is_owner = ($account->id() && $account->id() == $media->getOwnerId());
if (!$is_owner) {
$access_result = AccessResult::neutral()
->setReason("The user has the '$edit_own_permission' permission, but is not the owner of the media item.");
}
else {
$access_result = AccessResult::allowed();
}
return $access_result
->cachePerUser()
->addCacheableDependency($media);
case 'edit in collabora':
if ($account->hasPermission("edit any $type in collabora")) {
return AccessResult::allowed()
->cachePerPermissions();
}
$edit_own_permission = "edit own $type in collabora";
$access_result = AccessResult::allowedIfHasPermission($account, $edit_own_permission);
if (!$access_result->isAllowed()) {
return $access_result;
}
// Use '==' because Drupal sometimes loads integers as strings.
$is_owner = ($account->id() && $account->id() == $media->getOwnerId());
if (!$is_owner) {
$access_result = AccessResult::neutral()
->setReason("The user has the '$edit_own_permission' permission, but is not the owner of the media item.");
}
else {
$access_result = AccessResult::allowed();
}
return $access_result
->cachePerUser()
->addCacheableDependency($media);

default:
return AccessResult::neutral();
}
default:
return AccessResult::neutral();
}
}
6 changes: 3 additions & 3 deletions collabora_online.theme.inc
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use Drupal\Core\Extension\ExtensionPathResolver;
* Theme hook variables.
*/
function template_preprocess_collabora_online_full(array &$variables): void {
/** @var \Drupal\Core\Extension\ExtensionPathResolver $path_resolver */
$path_resolver = \Drupal::service(ExtensionPathResolver::class);
$variables['module_path'] = $path_resolver->getPath('module', 'collabora_online');
/** @var \Drupal\Core\Extension\ExtensionPathResolver $path_resolver */
$path_resolver = \Drupal::service(ExtensionPathResolver::class);
$variables['module_path'] = $path_resolver->getPath('module', 'collabora_online');
}
28 changes: 14 additions & 14 deletions collabora_online.views.inc
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@ declare(strict_types=1);
* Implements hook_views_data_alter().
*/
function collabora_online_views_data_alter(array &$data): void {
$data['media']['collabora_preview'] = [
'title' => t('Link to view in Collabora Online'),
'group' => t('Media'),
'field' => [
'id' => 'media_collabora_preview',
],
];
$data['media']['collabora_edit'] = [
'title' => t('Link to edit in Collabora Online'),
'group' => t('Media'),
'field' => [
'id' => 'media_collabora_edit',
],
];
$data['media']['collabora_preview'] = [
'title' => t('Link to view in Collabora Online'),
'group' => t('Media'),
'field' => [
'id' => 'media_collabora_preview',
],
];
$data['media']['collabora_edit'] = [
'title' => t('Link to edit in Collabora Online'),
'group' => t('Media'),
'field' => [
'id' => 'media_collabora_edit',
],
];
}
34 changes: 17 additions & 17 deletions css/cool.css
Original file line number Diff line number Diff line change
Expand Up @@ -14,30 +14,30 @@
}

.cool-frame__preview {
width: 100%;
height: 100%;
border: 0;
width: 100%;
height: 100%;
border: 0;
}

.cool-frame__iframe {
border: 1px solid;
width: 100%;
height: 100%;
position: absolute;
box-sizing: border-box;
border: 1px solid;
width: 100%;
height: 100%;
position: absolute;
box-sizing: border-box;
}

.cool-editor__dialog {
resize: both;
position: fixed;
top: 250px;
width: 100%;
height: calc(100% - 250px);
/* seems to be a reasonable value to be above of it all */
z-index: 501;
box-sizing: border-box;
resize: both;
position: fixed;
top: 250px;
width: 100%;
height: calc(100% - 250px);
/* seems to be a reasonable value to be above of it all */
z-index: 501;
box-sizing: border-box;
}

.cool-editor__body {
margin: 0;
margin: 0;
}
Loading