Merge pull request #728 from bolt/hotfix/extras-only-values

Make 'extras' only return values for Image, not the entire ImageField object
This commit is contained in:
Bob den Otter
2019-11-18 21:42:35 +01:00
committed by GitHub
3 changed files with 6 additions and 6 deletions

View File

@@ -34,7 +34,7 @@ trait ContentExtrasTrait
return [
'title' => $this->contentExtension->getTitle($content),
'image' => $this->contentExtension->getImage($content),
'image' => $this->contentExtension->getImage($content, true),
'excerpt' => $this->contentExtension->getExcerpt($content),
'link' => $this->contentExtension->getLink($content),
'editLink' => $this->contentExtension->getEditLink($content),

View File

@@ -125,13 +125,13 @@ class ContentExtension extends AbstractExtension
}
/**
* @return ImageField|string|null
* @return ImageField|array|null
*/
public function getImage(Content $content, bool $onlyPath = false)
public function getImage(Content $content, bool $onlyValues = false)
{
foreach ($content->getFields() as $field) {
if ($field instanceof ImageField) {
return $onlyPath ? $field->getPath() : $field;
return $onlyValues ? $field->getValue() : $field;
}
}

View File

@@ -24,7 +24,7 @@ use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface;
class ContentExtensionSpec extends ObjectBehavior
{
public const TEST_TITLE = 'test title';
public const TEST_IMAGE = 'kitten.jpg';
public const TEST_IMAGE = [];
public const TEST_EXCERPT = 'test excerpt';
public const TEST_LINK = 'test/link';
public const TEST_FULL_LINK = 'http://localhost/test/link';
@@ -85,7 +85,7 @@ class ContentExtensionSpec extends ObjectBehavior
public function it_gets_image_path(Content $content, ImageField $field, Field $otherField): void
{
$field->getPath()->shouldBeCalled()->willReturn(self::TEST_IMAGE);
$field->getValue()->shouldBeCalled()->willReturn(self::TEST_IMAGE);
$content->getFields()->shouldBeCalled()->willReturn(new ArrayCollection([
$otherField->getWrappedObject(),
$field->getWrappedObject(),