Programmatically add Page Thumbnail as a Page Attribute
Permalink
Hi,
I developed a Package to create Gallery Pages containing a Gallery Block. It works like that, that there is a Item in de C5 Header Menu. When you hit that button, the form to add a new Gallery Page opens. You can enter the neccessary informations and you can also select an Image to be set as the page thumbnail.
Here is the code to select the image:
<div class="ccm-block-field group"> <label class="checkbox-label" for="field_album_thumbnail"><?php echo t('Album Thumbnail'); ?></label>
<?php echo $al->image('field_album_thumbnail', 'field_album_thumbnail', t('Select Image'), $field_album_thumbnail); ?>
<span class="field-hint"><?php echo "(".t('Adds a thumbnail Image to the Album List entry').")"; ?></span>
</div>
When the user hits the button to add the page, an ajax call to a file within the tools folder in my package is made. In that file, the Page is getting created and its attributes are being set. That works perfectly, but only the selected image is just not getting set. Here is the code to create the page and set the image:
$albumThumbnail = $_REQUEST['field_album_thumbnail'];
$ctGallery=CollectionType::getByHandle('gre_gallery');
$parentGallery = Page::getByPath('/anlaesse/gallery');
$data=array();
$albumPage = $parentGallery->add($ctGallery,$data);
if($albumThumbnail != '0'){
$albumPage->setAttribute('album_thumbnail', $albumThumbnail);
}
Is it correct to set the file id as the page attribute or do i have to get the file object itself to set it as the attribute?
Thanks and with best regards
Jan
I developed a Package to create Gallery Pages containing a Gallery Block. It works like that, that there is a Item in de C5 Header Menu. When you hit that button, the form to add a new Gallery Page opens. You can enter the neccessary informations and you can also select an Image to be set as the page thumbnail.
Here is the code to select the image:
<div class="ccm-block-field group"> <label class="checkbox-label" for="field_album_thumbnail"><?php echo t('Album Thumbnail'); ?></label>
<?php echo $al->image('field_album_thumbnail', 'field_album_thumbnail', t('Select Image'), $field_album_thumbnail); ?>
<span class="field-hint"><?php echo "(".t('Adds a thumbnail Image to the Album List entry').")"; ?></span>
</div>
When the user hits the button to add the page, an ajax call to a file within the tools folder in my package is made. In that file, the Page is getting created and its attributes are being set. That works perfectly, but only the selected image is just not getting set. Here is the code to create the page and set the image:
$albumThumbnail = $_REQUEST['field_album_thumbnail'];
$ctGallery=CollectionType::getByHandle('gre_gallery');
$parentGallery = Page::getByPath('/anlaesse/gallery');
$data=array();
$albumPage = $parentGallery->add($ctGallery,$data);
if($albumThumbnail != '0'){
$albumPage->setAttribute('album_thumbnail', $albumThumbnail);
}
Is it correct to set the file id as the page attribute or do i have to get the file object itself to set it as the attribute?
Thanks and with best regards
Jan
Recently I started to develop Packages a lot and often, it took me a lot of time to figure out, how to do something Programmatically..Will there be an extended Documentation at some Point? Specially about Creating Pages, Pages Types, Attributes.. That would be really Helpful..
Thanks
Jan