From 067550794fd9db2ac9d1de8eb0c879598da1d9a7 Mon Sep 17 00:00:00 2001 From: Nigel Banks Date: Mon, 19 Oct 2020 15:38:12 +0000 Subject: [PATCH] Fix for media_source_mimetype to allow entities to display when not specified. --- .../Condition/MediaSourceHasMimetype.php | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/Plugin/Condition/MediaSourceHasMimetype.php b/src/Plugin/Condition/MediaSourceHasMimetype.php index ba16bb35..86450750 100644 --- a/src/Plugin/Condition/MediaSourceHasMimetype.php +++ b/src/Plugin/Condition/MediaSourceHasMimetype.php @@ -44,20 +44,24 @@ class MediaSourceHasMimetype extends ConditionPluginBase { * {@inheritdoc} */ public function evaluate() { - foreach ($this->getContexts() as $context) { - if ($context->hasContextValue()) { - $entity = $context->getContextValue(); - $mid = $entity->id(); - if ($mid && !empty($this->configuration['mimetype'])) { - $source = $entity->getSource(); + if (empty($this->configuration['mimetype']) && !$this->isNegated()) { + return TRUE; + } + $media = $this->getContext('media'); + if ($media->hasContextValue()) { + $entity = $media->getContextValue(); + $mid = $entity->id(); + if ($mid) { + $source = $entity->getSource(); + if ($source) { $source_file = File::load($source->getSourceFieldValue($entity)); if ($this->configuration['mimetype'] == $source_file->getMimeType()) { - return !$this->isNegated(); + return TRUE; } } } } - return $this->isNegated(); + return FALSE; } /**