From fa18ea23dfacb38462d0bd3cc9690440b4d86386 Mon Sep 17 00:00:00 2001 From: Diego Pino Navarro Date: Thu, 9 Dec 2021 16:48:18 -0300 Subject: [PATCH] Initialize $embargo cache tags sooner If an ADO has no media, wrong metadata, etc, and we can not show anything we still are merging the cache tags, so put the to [] sooner --- src/Controller/MetadataExposeDisplayController.php | 4 ++-- src/Plugin/Field/FieldFormatter/Strawberry3DFormatter.php | 4 ++-- src/Plugin/Field/FieldFormatter/StrawberryAudioFormatter.php | 4 ++-- src/Plugin/Field/FieldFormatter/StrawberryMediaFormatter.php | 4 ++-- .../Field/FieldFormatter/StrawberryMetadataTwigFormatter.php | 5 +++-- src/Plugin/Field/FieldFormatter/StrawberryPagedFormatter.php | 5 +++-- .../Field/FieldFormatter/StrawberryPannellumFormatter.php | 5 +++-- src/Plugin/Field/FieldFormatter/StrawberryPdfFormatter.php | 4 ++-- src/Plugin/Field/FieldFormatter/StrawberryVideoFormatter.php | 4 ++-- src/Plugin/Field/FieldFormatter/StrawberryWarcFormatter.php | 4 ++-- 10 files changed, 23 insertions(+), 20 deletions(-) diff --git a/src/Controller/MetadataExposeDisplayController.php b/src/Controller/MetadataExposeDisplayController.php index 2328c908..03805c05 100644 --- a/src/Controller/MetadataExposeDisplayController.php +++ b/src/Controller/MetadataExposeDisplayController.php @@ -141,6 +141,8 @@ public function castViaTwig( ); } $context = []; + $embargo_context = []; + $embargo_tags = []; if ($sbf_fields = $this->strawberryfieldUtility->bearsStrawberryfield( $node )) { @@ -210,11 +212,9 @@ public function castViaTwig( } $embargo_info = $this->embargoResolver->embargoInfo($node->uuid(), $jsondata); - $embargo_context = []; // This one is for the Twig template // We do not need the IP here. No use of showing the IP at all? $context_embargo = ['data_embargo' => ['embargoed' => false, 'until' => NULL]]; - $embargo_tags = []; if (is_array($embargo_info)) { $embargoed = $embargo_info[0]; $context_embargo['data_embargo']['embargoed'] = $embargoed; diff --git a/src/Plugin/Field/FieldFormatter/Strawberry3DFormatter.php b/src/Plugin/Field/FieldFormatter/Strawberry3DFormatter.php index 3850845c..85572592 100644 --- a/src/Plugin/Field/FieldFormatter/Strawberry3DFormatter.php +++ b/src/Plugin/Field/FieldFormatter/Strawberry3DFormatter.php @@ -127,6 +127,8 @@ public function viewElements(FieldItemListInterface $items, $langcode) { $upload_keys = explode(',', $upload_keys_string); $upload_keys = array_filter($upload_keys); $upload_keys = array_map('trim', $upload_keys); + $embargo_context = []; + $embargo_tags = []; $embargo_upload_keys_string = strlen(trim($this->getSetting('embargo_json_key_source'))) > 0 ? trim($this->getSetting('embargo_json_key_source')) : NULL; $embargo_upload_keys_string = explode(',', $embargo_upload_keys_string); @@ -170,8 +172,6 @@ public function viewElements(FieldItemListInterface $items, $langcode) { }*/ $embargo_info = $this->embargoResolver->embargoInfo($items->getEntity()->uuid(), $jsondata); // Check embargo - $embargo_context = []; - $embargo_tags = []; if (is_array($embargo_info)) { $embargoed = $embargo_info[0]; $embargo_tags[] = 'format_strawberryfield:all_embargo'; diff --git a/src/Plugin/Field/FieldFormatter/StrawberryAudioFormatter.php b/src/Plugin/Field/FieldFormatter/StrawberryAudioFormatter.php index 9eebbad3..10e55976 100644 --- a/src/Plugin/Field/FieldFormatter/StrawberryAudioFormatter.php +++ b/src/Plugin/Field/FieldFormatter/StrawberryAudioFormatter.php @@ -127,6 +127,8 @@ public function viewElements(FieldItemListInterface $items, $langcode) { $upload_keys_string = strlen(trim($this->getSetting('upload_json_key_source'))) > 0 ? trim($this->getSetting('upload_json_key_source')) : NULL; $upload_keys = explode(',', $upload_keys_string); $upload_keys = array_filter($upload_keys); + $embargo_context = []; + $embargo_tags = []; $embargo_upload_keys_string = strlen(trim($this->getSetting('embargo_json_key_source'))) > 0 ? trim($this->getSetting('embargo_json_key_source')) : NULL; $embargo_upload_keys_string = explode(',', $embargo_upload_keys_string); @@ -187,8 +189,6 @@ public function viewElements(FieldItemListInterface $items, $langcode) { $embargo_info = $this->embargoResolver->embargoInfo($items->getEntity()->uuid(), $jsondata); // Check embargo - $embargo_context = []; - $embargo_tags = []; if (is_array($embargo_info)) { $embargoed = $embargo_info[0]; $embargo_tags[] = 'format_strawberryfield:all_embargo'; diff --git a/src/Plugin/Field/FieldFormatter/StrawberryMediaFormatter.php b/src/Plugin/Field/FieldFormatter/StrawberryMediaFormatter.php index 788af131..3bc814b8 100644 --- a/src/Plugin/Field/FieldFormatter/StrawberryMediaFormatter.php +++ b/src/Plugin/Field/FieldFormatter/StrawberryMediaFormatter.php @@ -169,6 +169,8 @@ public function viewElements(FieldItemListInterface $items, $langcode) { $upload_keys = explode(',', $upload_keys_string); $upload_keys = array_filter($upload_keys); $upload_keys = array_map('trim', $upload_keys); + $embargo_context = []; + $embargo_tags = []; $embargo_upload_keys_string = strlen(trim($this->getSetting('embargo_json_key_source'))) > 0 ? trim($this->getSetting('embargo_json_key_source')) : NULL; $embargo_upload_keys_string = explode(',', $embargo_upload_keys_string); @@ -204,8 +206,6 @@ public function viewElements(FieldItemListInterface $items, $langcode) { $embargo_info = $this->embargoResolver->embargoInfo($items->getEntity() ->uuid(), $jsondata); // Check embargo - $embargo_context = []; - $embargo_tags = []; if (is_array($embargo_info)) { $embargoed = $embargo_info[0]; $embargo_tags[] = 'format_strawberryfield:all_embargo'; diff --git a/src/Plugin/Field/FieldFormatter/StrawberryMetadataTwigFormatter.php b/src/Plugin/Field/FieldFormatter/StrawberryMetadataTwigFormatter.php index 9eaccf52..38b5b9b8 100755 --- a/src/Plugin/Field/FieldFormatter/StrawberryMetadataTwigFormatter.php +++ b/src/Plugin/Field/FieldFormatter/StrawberryMetadataTwigFormatter.php @@ -194,6 +194,8 @@ public function viewElements(FieldItemListInterface $items, $langcode) { $usemetadatalabel = $this->getSetting('metadatadisplayentity_uselabel'); $metadatadisplayentity_uuid = $this->getSetting('metadatadisplayentity_uuid'); $nodeid = $items->getEntity()->id(); + $embargo_context = []; + $embargo_tags = []; foreach ($items as $delta => $item) { $main_property = $item->getFieldDefinition()->getFieldStorageDefinition()->getMainPropertyName(); @@ -229,11 +231,10 @@ public function viewElements(FieldItemListInterface $items, $langcode) { return $elements[$delta] = ['#markup' => $message]; } $embargo_info = $this->embargoResolver->embargoInfo($items->getEntity()->uuid(), $jsondata); - $embargo_context = []; // This one is for the Twig template // We do not need the IP here. No use of showing the IP at all? $context_embargo = ['data_embargo' => ['embargoed' => false, 'until' => NULL]]; - $embargo_tags = []; + if (is_array($embargo_info)) { $embargoed = $embargo_info[0]; $context_embargo['data_embargo']['embargoed'] = $embargoed; diff --git a/src/Plugin/Field/FieldFormatter/StrawberryPagedFormatter.php b/src/Plugin/Field/FieldFormatter/StrawberryPagedFormatter.php index 27e83d1c..62bd8d69 100644 --- a/src/Plugin/Field/FieldFormatter/StrawberryPagedFormatter.php +++ b/src/Plugin/Field/FieldFormatter/StrawberryPagedFormatter.php @@ -378,6 +378,8 @@ public function processElementforMetadatadisplays($delta, array $jsondata, Field $max_width = $this->getSetting('max_width'); $max_width_css = empty($max_width) || $max_width == 0 ? '100%' : $max_width .'px'; $max_height = $this->getSetting('max_height'); + $embargo_context = []; + $embargo_tags = []; if ($this->getSetting('metadatadisplayentity_uuid')) { /* @var $metadatadisplayentity \Drupal\format_strawberryfield\Entity\MetadataDisplayEntity */ @@ -395,11 +397,10 @@ public function processElementforMetadatadisplays($delta, array $jsondata, Field StrawberryfieldJsonHelper::orderSequence($jsondata, $mainkey, $ordersubkey); $embargo_info = $this->embargoResolver->embargoInfo($item->getEntity()->uuid(), $jsondata); - $embargo_context = []; // This one is for the Twig template // We do not need the IP here. No use of showing the IP at all? $context_embargo = ['data_embargo' => ['embargoed' => false, 'until' => NULL]]; - $embargo_tags = []; + if (is_array($embargo_info)) { $embargoed = $embargo_info[0]; $context_embargo['data_embargo']['embargoed'] = $embargoed; diff --git a/src/Plugin/Field/FieldFormatter/StrawberryPannellumFormatter.php b/src/Plugin/Field/FieldFormatter/StrawberryPannellumFormatter.php index a82515e6..9a562601 100644 --- a/src/Plugin/Field/FieldFormatter/StrawberryPannellumFormatter.php +++ b/src/Plugin/Field/FieldFormatter/StrawberryPannellumFormatter.php @@ -263,6 +263,8 @@ public function viewElements(FieldItemListInterface $items, $langcode) { $upload_keys = explode(',', $upload_keys_string); $upload_keys = array_filter($upload_keys); $upload_keys = array_map('trim', $upload_keys); + $embargo_context = []; + $embargo_tags = []; $embargo_upload_keys_string = strlen(trim($this->getSetting('embargo_json_key_source'))) > 0 ? trim($this->getSetting('embargo_json_key_source')) : NULL; $embargo_upload_keys_string = explode(',', $embargo_upload_keys_string); @@ -297,11 +299,10 @@ public function viewElements(FieldItemListInterface $items, $langcode) { } $embargo_info = $this->embargoResolver->embargoInfo($item->getEntity()->uuid(), $jsondata); - $embargo_context = []; // This one is for the Twig template // We do not need the IP here. No use of showing the IP at all? $context_embargo = ['data_embargo' => ['embargoed' => false, 'until' => NULL]]; - $embargo_tags = []; + if (is_array($embargo_info)) { $embargoed = $embargo_info[0]; $context_embargo['data_embargo']['embargoed'] = $embargoed; diff --git a/src/Plugin/Field/FieldFormatter/StrawberryPdfFormatter.php b/src/Plugin/Field/FieldFormatter/StrawberryPdfFormatter.php index 685a08b8..a94bd48e 100644 --- a/src/Plugin/Field/FieldFormatter/StrawberryPdfFormatter.php +++ b/src/Plugin/Field/FieldFormatter/StrawberryPdfFormatter.php @@ -158,6 +158,8 @@ public function viewElements(FieldItemListInterface $items, $langcode) { $upload_keys_string = strlen(trim($this->getSetting('upload_json_key_source'))) > 0 ? trim($this->getSetting('upload_json_key_source')) : NULL; $upload_keys = explode(',', $upload_keys_string); $upload_keys = array_filter($upload_keys); + $embargo_context = []; + $embargo_tags = []; $embargo_upload_keys_string = strlen(trim($this->getSetting('embargo_json_key_source'))) > 0 ? trim($this->getSetting('embargo_json_key_source')) : NULL; $embargo_upload_keys_string = explode(',', $embargo_upload_keys_string); @@ -209,11 +211,9 @@ public function viewElements(FieldItemListInterface $items, $langcode) { }, }*/ $embargo_info = $this->embargoResolver->embargoInfo($items->getEntity()->uuid(), $jsondata); - $embargo_context = []; // This one is for the Twig template // We do not need the IP here. No use of showing the IP at all? $context_embargo = ['data_embargo' => ['embargoed' => false, 'until' => NULL]]; - $embargo_tags = []; if (is_array($embargo_info)) { $embargoed = $embargo_info[0]; $context_embargo['data_embargo']['embargoed'] = $embargoed; diff --git a/src/Plugin/Field/FieldFormatter/StrawberryVideoFormatter.php b/src/Plugin/Field/FieldFormatter/StrawberryVideoFormatter.php index c3c206a7..1d0d452d 100644 --- a/src/Plugin/Field/FieldFormatter/StrawberryVideoFormatter.php +++ b/src/Plugin/Field/FieldFormatter/StrawberryVideoFormatter.php @@ -156,6 +156,8 @@ public function viewElements(FieldItemListInterface $items, $langcode) { $upload_keys_string = strlen(trim($this->getSetting('upload_json_key_source'))) > 0 ? trim($this->getSetting('upload_json_key_source')) : NULL; $upload_keys = explode(',', $upload_keys_string); $upload_keys = array_filter($upload_keys); + $embargo_context = []; + $embargo_tags = []; $embargo_upload_keys_string = strlen(trim($this->getSetting('embargo_json_key_source'))) > 0 ? trim($this->getSetting('embargo_json_key_source')) : NULL; $embargo_upload_keys_string = explode(',', $embargo_upload_keys_string); @@ -221,8 +223,6 @@ public function viewElements(FieldItemListInterface $items, $langcode) { $embargo_info = $this->embargoResolver->embargoInfo($items->getEntity() ->uuid(), $jsondata); // Check embargo - $embargo_context = []; - $embargo_tags = []; if (is_array($embargo_info)) { $embargoed = $embargo_info[0]; $embargo_tags[] = 'format_strawberryfield:all_embargo'; diff --git a/src/Plugin/Field/FieldFormatter/StrawberryWarcFormatter.php b/src/Plugin/Field/FieldFormatter/StrawberryWarcFormatter.php index 562112c6..805b16cc 100644 --- a/src/Plugin/Field/FieldFormatter/StrawberryWarcFormatter.php +++ b/src/Plugin/Field/FieldFormatter/StrawberryWarcFormatter.php @@ -154,6 +154,8 @@ public function viewElements(FieldItemListInterface $items, $langcode) { $nodeid = $items->getEntity()->id(); $number_media = $this->getSetting('number_media') ?? 1; $key = $this->getSetting('json_key_source'); + $embargo_context = []; + $embargo_tags = []; $nodeuuid = $items->getEntity()->uuid(); $nodeid = $items->getEntity()->id(); @@ -195,8 +197,6 @@ public function viewElements(FieldItemListInterface $items, $langcode) { $embargo_info = $this->embargoResolver->embargoInfo($items->getEntity() ->uuid(), $jsondata); // Check embargo - $embargo_context = []; - $embargo_tags = []; if (is_array($embargo_info)) { $embargoed = $embargo_info[0]; $embargo_tags[] = 'format_strawberryfield:all_embargo';