I have a question that I am struggeling with. A positive answer would help me to remove a piece of unwanted customization.
Is it possible to add metadata from the event system to a component where the field is not present in the metadata schema? The reason I ask this, is that I am creating a dynamic implementation where content is retrieved using metadata.
Some of the fields I would like to display are in the content tab of the component. This to make sure the Content Managers can find these fields. Because of this, I would like to add these fields to metadata during publishing. This to make this content available as metadata in the Broker database, where I can use the Broker API to retrieve these fields.
I have read a post on setting a value in a page's metadata by using the following fragment that Nuno provided:
Itemfields meta = new ItemFields(page.Metadata, page.MetadataSchema);
SingleLineTextField categorisationField = (SingleLineTextField)meta["categorisation"];
categorisationField.Value = "Some value";
page.Metadata = meta.ToXml();
What I tried was to get the metadata as an XML fragment, and manually add the node to the metadata section (using the correct schema namespace). I then set the components metadata by using
component.Metadata = metadata;
(where metadata is the XML fragment). The component has/had a metadata schema attached.
So my question is: Does the publisher use the in-memory component representation, where the metadata entry is present, or does it get a new copy of the component when publishing. If the latter is the case, I will need to add a
.save() and beforehand add the field to the schema.
Any thoughts? Is this possible, or is there a good alternative?