Image in MemberExtension doesn´t shown in frontend

Silverstripe Version:
4.0.2.

Hey guys,
are there any specialties around the MemberExtension with images?
I have the very wired phenomenon, that a single image which I add via dataextension to my Member-Class doesn´t shown up in the frontend-template.

MyMemberExtension.php:

<?php
use SilverStripe\ORM\DataExtension;
use SilverStripe\Assets\Image;
use SilverStripe\Security\Member;

class MyMemberExtension extends DataExtension{

	private static $db = [
		'hobbies' 			=> 'Text',
		'description' 			=> 'Text'
	];

	private static $has_one = [
		'profilImage' 			=> Image::class,
		'committeeImage'	=> Image::class
	];

	private static $owns = [
		'profilImage',
		'committeeImage',
	];

CommitteePage.php

<?php

use SilverStripe\View\Requirements;
use SilverStripe\Security\Member;
use SilverStripe\ORM\ArrayList;

class CommitteePage extends Page{

	public function getCommitteeMembers(){
		$Members = Member::get()->filter(['isInCommittee' => true]);

		return $Members;
	}

}

class CommitteePageController extends PageController{
	
}

CommitteePage.ss

<% loop $CommitteeMembers %>

<div class="round-image">
$profilImage
</div>

<div>
$hobbies
</div>

<% end_loop %>

app.yml:

SilverStripe\Security\Member:
       extensions:
            - MyMemberExtension

All works, but “the round-image”-divs are blank. I can´t see any differences what I made and this link: Extensions – SilverStripe Documentation

Any ideas?

I don’t think that Member is versioned, so you’re probably falling foul of the issue described here: Silverstripe 4 gotchas

Assuming the above is true, and this is just a publishing issue, if you add the following method to your extension, the images should get published when you save the record:

public function onBeforeWrite() 
{

        if($this->owner->profilImage() && $this->owner->profilImage()->exists()) {
            $this->owner->profilImage()->publishSingle();
        }
      
        parent::onBeforeWrite();
}
1 Like

Great! Your code fixed the problem. The publishing was the problem.

1 Like

Since 4.1.0 came out yesterday, ownership should work also with non versioned DataObjects. Here is what changed: https://www.silverstripe.org/blog/open-source-four-point-won/.

1 Like