Below you see the debug for an object of type FileReference in fluid. In fluid the debug looks like this: <f:debug>{fileReference}</f:debug>
The question is how do I access the properties highlighted in green, being width, height, and hovertext.
The original file is an image, so width & height are default T3 properties, hovertext has been added by my extension with it's own getter/setter.
I tried the following:
{fileReference.width}
{fileReference.mergedProperties.width}
{fileReference.originalResource.width}
No luck so far, what is the right way to access the values in mergedProperties?
Many Thanks
Florian
The f:debug shows something similar to the var_dump function, so the properties of an object. In fluid you can only access the getter functions or if it is an array the values of the array. So if you write something like {fileReference.mergedProperties} the method getMergedProperties() is called if it is present.
Knowing that you can look inside the sysext/core/Classes/Resource/FileReference.php File and see what getters it has. We can quickly find the public function getProperties() that returns the merged properties you marked, so the right solution should be this:
{fileReference.properties.width}
Related
I want to set the "standard" TYPO3 field "fe_group" in the extbase controller. As far I see there no "standard" getters and setters? https://typo3.org/api/typo3cms/class_t_y_p_o3_1_1_c_m_s_1_1_extbase_1_1_domain_object_1_1_abstract_entity.html
I tried to implement them in the model, but it does not work - I do not get any error but it is never set.
What exactly I want to do:
I have an object of type \TYPO3\CMS\Extbase\Domain\Model\FrontendUserGroup and I have an object of my record type (I can set other fields without any problems).
Now I want to do something like:
$myobject->addFe_group($feusergroup);
Do I have to implement this by my own to my model? I tried to implement fe_group as ObjectStorage and also as string - does not work? :-(
Does anyone have a solution for this?
Thank you
Christian
First of all: In models please name functions and properties lowerCamelCase. So a field "fe_group" in TCA would become "feGroup" in the model and the function would be "addFeGroup".
FrontendUserGroup model has a function addSubgroup to add other groups as subobjects. Is this the right thing for your purpose or what you need those relation to another group for?
https://typo3.org/api/typo3cms/class_t_y_p_o3_1_1_c_m_s_1_1_extbase_1_1_domain_1_1_model_1_1_frontend_user_group.html
I have an object appointment with a property expertises of type \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\Vendor\Extname\Domain\Model\Expertise>.
Additionally one important property of Expertise is the bool checked.
What I want to do in my AppointmentController is:
In the first action: Empty the appointment's property expertises (not set it to NULL, I just want an empty ObjectStorage that I can add something to later)
In the second action: Fill appointment with expertises (from a different object) whose property checked equals true
To start out with the emptying I looked at the answer from here but it didn't work for me.
This is what I tried:
$appExp = $appointment->getExpertises();
foreach ($appExp as $exp) {
$appExp->detach($exp);
}
\TYPO3\CMS\Extbase\Utility\DebuggerUtility::var_dump($appointment);
But it shows that all expertises are still in appointment.
In the second action I do this:
foreach ($expertises as $expertise) {
if ($expertise->getChecked()) {
$appointment->addExpertise($expertise);
}
}
It works, but I wonder if there's an easier "filter" function that can automatically filter the checked value and return an ObjectStorage object. Because this way I could just use setExpertises() and the old ones would get overwritten which would make the first step unnecessary.
So does someone have an idea for the emptying and filtering of ObjectStorage objects?
I looked a bit into the ObjectStorage Class reference but there's no obvious function that empties it (removeAll ist just for objects contained in another storage from the current storage) and no filter function either.
There is an easy way to remove all objects from the object storage:
$appointment->getExpertises()->removeAll($appointment->getExpertises());
As for filtering: as you already noticed, you have to do it yourself. I would implement such functions like getActiveExpertises in the Model, because it fits there much better than in a controller.
The setters in ExtbaseObjects that refer to ObjectStorages have an optional parameter that defaults to null. Just call the setter without a parameter. You don't have to waste performance by instanciating an empty StorageObject.
$appointment->setExpertises();
i have an EObject and want to get all the Properties from it. I tryed to get all Structural Features:
myEObject.eClass().getEAllStructuralFeatures()
but i get too many Properties i do not want like the object ID.
With
myEObject.eClass().getEStructuralFeatures()
there are missing some that are displayed in the Properties View.
So how can i get the same List of Properties from an EObject like the Properties View does?
Thx for your help
Just use the first option and filter out the ones you don't want (like object id) from being displayed. It's probably the easiest way.
If it must absolutely be the same as the list that is displayed in the properties view, the safest bet is to find the code used to populate the properties view and reuse it.
I'm building a MEF-based plugin-centric WPF application and I'm facing an issue with GetExports, maybe it's just my ignorance but I find an odd behaviour. I have a number of exported parts, all derived from 2 different interfaces (let's name them A and B), but all marked with the same metadata attribute X. So I have code like:
[Export(typeof(A))]
[TheXAttributeHere...]
public class SomePart1 : A { ... }
for each part, and the same for classes implementing B:
[Export(typeof(B))]
[TheXAttributeHere...]
public class SomePart2 : B { ... }
Now, when I try getting all the parts implementing A and decorated by attribute X with some values, MEF returns not only the A-implementing parts, but ALSO the B-implementing parts. So, when I expect to deal with A-objects I get a B, whence a cast exception.
In the real world, interfaces are named IItemPartEditorViewModel and IItemPartEditorView, while their common attribute is named ItemPartEditorAttribute and exposes a PartType string property on which I do some filtering. My code to get parts is thus like e.g.:
var p = (from l in container.GetExports<IItemPartEditorViewModel, IItemPartEditorMetadata>()
where l.Metadata.PartType == sPartType
select l).FirstOrDefault();
When looking for IItemPartEditorViewModel whose PartType is equal to some value, I get the IItemPartEditorView instead of IItemPartEditorViewModel implementing object. If I comment out the attribute in the IItemPartEditorView object instead, I correctly get the IItemPartEditorViewModel implementing object.
Update the suggested "templated" method was used, but I mistyped it here as I forgot to change lessthan and greaterthan into entities. Anyway, reviewing the code I noticed that in the attribute I had "ViewModel" instead or "View" for the interface type, so this was the problem. Shame on me, sorry for bothering :)!
I think I'd need to see more of the code to know for sure what's going on. However, I'd suggest you call GetExports like this:
// Get exports of type A
container.GetExports<A>();
// Get exports of type B
container.GetExports<B>();
Then do your filtering on the list returned. This will probably fix the cast issues you are having. I'd also be interested in seeing the code for the custom metadata attribute. If it derives from ExportAttribute for example, that might be part of the problem.
I've just started using EF in VS2010. That thing is just amazin'.
I frankly can't understand something. For example I have EntityType with property, they generated from database structure.
Now, I have to simply override that property in my code. I don't need to save value of the property back into DB, but everytime when it gets read from DB it should be substituted with run-time calculated value.
Of course I can create derived class based on my EntityType but I've tried and found kinda difficulties, I'm not sure this is kinda right way to do. Anyway even when I try to change the whole EntityType to Abstract, damn Visual Studio doesn't want to validate that and says something like:
"Error 2078: The EntityType 'AssetsModel.Asset' is Abstract and can be mapped only using IsTypeOf."
"Error 2063: At least one property must be mapped in the set mapping for 'Assets'"
What the hell is this suppose to mean I dunno..
Any ideas?
The best approach would be to use Partial Classes and then create a new ReadOnly property to calculate the value in the getter.