Created
September 28, 2018 17:34
-
-
Save paulsheldrake/f69e1e4ceeb0ab7c0f2934f560b4e88b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/Plugin/Field/FieldFormatter/PdfDefault.php b/src/Plugin/Field/FieldFormatter/PdfDefault.php | |
index 1995201..7dbfb8d 100755 | |
--- a/src/Plugin/Field/FieldFormatter/PdfDefault.php | |
+++ b/src/Plugin/Field/FieldFormatter/PdfDefault.php | |
@@ -5,8 +5,8 @@ namespace Drupal\pdf\Plugin\Field\FieldFormatter; | |
use Drupal\Component\Utility\UrlHelper; | |
use Drupal\Core\Field\FormatterBase; | |
use Drupal\Core\Field\FieldItemListInterface; | |
+use Drupal\Core\Site\Settings; | |
use Drupal\Core\Form\FormStateInterface; | |
-use jjalvarezl\PDFjsViewerBundle; | |
/** | |
* @FieldFormatter( | |
@@ -165,7 +165,14 @@ class PdfDefault extends FormatterBase { | |
$query = UrlHelper::buildQuery($extra_options); | |
foreach ($items as $delta => $item) { | |
if ($item->entity->getMimeType() == 'application/pdf') { | |
+ // Add flag for item public status. | |
$file_url = file_create_url($item->entity->getFileUri()); | |
+ $is_public = (boolean) $item->getEntity()->field_item_is_public->getValue()[0]['value']; | |
+ if ($is_public) { | |
+ $salt = Settings::getHashSalt(); | |
+ $hash = hash('md5', $item->entity->getFileUri() . $salt . $is_public); | |
+ $file_url .= '?public=' . $hash; | |
+ } | |
$iframe_src = file_create_url(drupal_get_path('module', 'pdf') . '/vendor/pdf.js/web/viewer.html') . '?file=' . rawurlencode($file_url); | |
$iframe_src = !empty($query) && $keep_pdfjs ? $iframe_src . '#' . $query : $iframe_src; | |
$html = [ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment