Using an Image Block in Composer

Permalink
I would like to have an image within a page.

Does anyone know how to add an empty image block to Composer?
I have striped the validation out of the default block so I can add an empty image, but viewing the block in composer asks me to edit the block.

Usually I do these sort of image in a page attribute, or within a designer block.

This time I need the image to be in an Image Area has anyone else done this?

TheRealSean
 
TheRealSean replied on at Permalink Reply
TheRealSean
Just by posting these silly questions often means I find the awnser.

By default, the block is displayed with and edit option as no composer file exists.

I created a file called composer.php and copied in the edit.php content

I have tweaked this to fit the area, (I have a template which adjusts the size to fit the area) and I do not want an image link or image swap

This was the code I used
<?php  
defined('C5_EXECUTE') or die("Access Denied.");
$includeAssetLibrary = true; 
$assetLibraryPassThru = array(
   'type' => 'image'
);
   $al = Loader::helper('concrete/asset_library');
$bf = null;
$bfo = null;
if ($controller->getFileID() > 0) { 
   $bf = $controller->getFileObject();
}
if ($controller->getFileOnstateID() > 0) { 
   $bfo = $controller->getFileOnstateObject();
}
facerX replied on at Permalink Reply
facerX
I am trying to accomplish basically the same thing. I want to use the built-in image cropper in a composer template, but I need the block to exist in the the page type without an image selected.

You say you copied the edit.php contents into a file called composer.php and made some alterations; where did you put the composer.php file?
TheRealSean replied on at Permalink Reply
TheRealSean
The composer file goes into the the image folder at the same level as the edit file, if you are using the built in image crop tool though I believe it has a folder called composer with some tools in?

To remove the validation for the image, in the controller you can comment out the following function.

I do not think this gives and error if no image is selected as the controller appears to have the checks in place to ensure an image id is available.

public function getJavaScriptStrings() {
        return array(
            'image-required' => t('You must select an image.')
        );
    }



My composer file uses the following(this is for a custom image block I have created). It take an image and allows for it to be cropped, via defined dimensions but uses the getThumbnail function to do the cropping.

<?php
defined('C5_EXECUTE') or die(_("Access Denied."));
$altText         = $controller->altText;
$thumbnailWidth  = ($controller->thumbnailWidth)?$controller->thumbnailWidth:300;
$thumbnailHeight = ($controller->thumbnailHeight)?$controller->thumbnailHeight:500;
$includeAssetLibrary = true;
$assetLibraryPassThru = array(
    'type' => 'image'
);
$al = Loader::helper('concrete/asset_library');
$bf = null;
if ($controller->getFileID() > 0) {
    $bf = $controller->getFileObject();
}
?>