Getting reference to the current page when adding Page Data

Topics: General
Jan 19, 2011 at 10:58 PM

Consider this

I have a Meta Type named Gallery with the following fields

  • Folder -> points to a folder in the media archive

I then have a Datafolder type named Image with the following fields

  • Description -> a free text field
  • Image -> points to a file in the media archive

What i want is to have the ImageSelector-widget for my Image.Image be filtered on the Gallery.Folder value defined on the given page im adding Image's to.

I've so far come up with a C# function like this i can use as filter, but i don't know how to pass the Page im adding the Image to as input to my function

namespace local.c1.test
{
   public static class InlineMethodFunction
   {
      public static string GetGalleryFolder(DataReference<IPage> data)
      {
         var page = data.Data;
         var mGallery = DataFacade.GetData<gallery>().Single(g =>  g.PageId == page.Id);
         var folder = DataFacade.GetData<IMediaFileFolder>().Single(f => f.KeyPath == mGallery.Gallery);

         return folder.Id.ToString();
      }
   }
}

<f:widgetfunction name="Composite.Widgets.ImageSelector">
   <f:param name="MediaFileFolderReference">
      <f:function name="Composite.Data.Types.IMediaFileFolder.GetDataReference">
         <f:param name="KeyValue">
            <f:function name="local.c1.test.GetGalleryFolder">
               <f:param name="data" value="HOW_DO_I_GET_THE_CORRECT_REFERENCE !?" />
            </f:function>
         </f:param>
      </f:function>
   </f:param>
</f:widgetfunction>

Coordinator
Jan 19, 2011 at 11:48 PM
Edited Jan 19, 2011 at 11:49 PM

Hmmm... this doesn't work, but it actually should (omg that sounds lame); I would expect that you could start out by adding

    <cms:binding name="PageId" type="System.Guid" />

to the bindings section in your types form markup and then pass this PageId on using

<f:function name="local.c1.test.GetGalleryFolder">
   <f:param name="data">
      <cms:read source="PageId" />
   </f:param>
</f:function>
(the conversion from Guid to DataReference<IPage> which your function expect will be done implicitly by the plumbing).

The helper class in Composite C1 that convert your 'Image' type fields into individual bindings could (should) add the PageId field as a binding as well, but it doesn't. Bummer. Feel free to poke around the source and locate the bastard code line. I'd also like that field back.

Jan 20, 2011 at 7:02 PM
Edited Jan 20, 2011 at 7:11 PM

Im not sure we're on the same page here... where i need to apply the filter is in the Widget configurator for my "Page datafolders" types Image field, not in the Form markup itself. I see no reference to the "Form field presentation-widget" in the Form Markup, and when i use <cms:read /> in the widget configurator i of course get a "cms is a undeclared prefix".

If i then add the cms-namespace to the configuration source i get this error instead

The element 'param' in namespace 'http://www.composite.net/ns/function/1.0' has invalid child element 'read' in namespace 'http://www.composite.net/ns/management/bindingforms/1.0'. List of possible elements expected: 'function, paramelement' in namespace 'http://www.composite.net/ns/function/1.0'.

All i see in my Form Markup is this DataReferenceTreeSelector, but i don't see how i should be able to pass a cms:bind command into my filter?

<DataReferenceTreeSelector Label="Image" Help="" Handle="Composite.Management.ImageSelectorDialog" SearchToken="Composite.Plugins.Elements.ElementProviders.MediaFileProviderElementProvider.MediaFileSearchToken,Composite|MimeTypes=',\ \'image/gif\',\ \'image/jpeg\',\ \'image/png\',\ \'image/bmp\'', Extensions=null, Folder=null, HideSubfolders='False', Keyword=null" DataType="Composite.Data.Types.IImageFile,Composite" NullValueAllowed="false">
   <DataReferenceTreeSelector.Selected>
      <cms:bind source="Image" />
   </DataReferenceTreeSelector.Selected>
</DataReferenceTreeSelector>

Jan 20, 2011 at 8:47 PM

Did edit some source code so i'm actually able to pass the PageId like this

<DataReferenceTreeSelector Label="Image" Help="" Handle="Composite.Management.ImageSelectorDialog" SearchToken="Composite.Plugins.Elements.ElementProviders.MediaFileProviderElementProvider.MediaFileSearchToken,Composite|MimeTypes=',\ \'image/gif\',\ \'image/jpeg\',\ \'image/png\',\ \'image/bmp\'', Extensions=null, Folder=null, HideSubfolders='False', Keyword=null" DataType="Composite.Data.Types.IImageFile,Composite" NullValueAllowed="false">
   <DataReferenceTreeSelector.Selected>
      <cms:bind source="Image" />
   </DataReferenceTreeSelector.Selected>
   <DataReferenceTreeSelector.PageId>
      <cms:bind source="PageId" />
   </DataReferenceTreeSelector.PageId>
</DataReferenceTreeSelector>
i can then retrieve in my DataReferenceTreeSelector control on the server but i have no idea how that helps me... ?