2

I'm trying to emulate what Assets does, in which a thumbnail of the asset is shown along side the title of the asset. When I alter the _toString() method of the model, what I get is the URL instead of the image (the URL is being added to the data-label attribute of the containing div).

Is there a way to accomplish what I'm after?

The Element Type's title is displayed, but no image

1

(Hopefully it is okay for me to answer my own question)

In the ElementType file, the getSources method needs to have the hasThumbs key set, as follows:

public function getSources($context = null)
{
    $sources = array(
        '*' => array(
            'label'    => Craft::t('All assets'),
            'hasThumbs' => true,
        )
    );
}

In your Model file you have to have a getThumbUrl method defined, as follows:

public function getThumbUrl()
{
    return $this->thumbnailUrl;
}

This results in a small thumbnail next to the title of your element, as seen in the screenshot:

enter image description here

The Craft 2 Class Reference helped put this together for me.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.