I'd like to change a message's class name - such as IPM.Note.MyName.
However I don't want to change it's form region.
In order to change the class name I need to register it somehow - How can I do that, since I don't have any form region?
Thanks,
Nili
You can change the class (MessageClass) without defining a custom form region - so long as the class Name starts with IPM.Note it will be treated just like a regular message item.
If you want custom form regions - you would have to add them by following the IFormRegionFactory interface, but this isn't necessary.
Related
Im trying to see if there is a way to using FluentValidation without explicitly creating a validation model for every object type in my application.
Is this technically and currently possible?
Updated
To rephrase this, is it possible for FluentValidation to validate Rules WITHOUT a IValidator context? Instead, i would like to pass in the item instance to be validated and use validation Rules which are constructed on-the-fly.
Resolved
I was able to resolve by doing a kind of a hack solution. Here are
basic details of what i did:
1) I created a class (GenericModel) which has a collection of objects
representing properties in a model. 2) I created a validator class
that inherits from AbstractValidator. 3) Based on
GenericModel's collection of "property objects" + additional metadata
about each property's validation rules and error messages, i was able
to add FluentValues Rules, all at run-time. 4). At the EditForm i
handled the OnSubmit event. In that event handler i execute validation
via FluentValidation's ValidateAsync() method. 5). Finally, i iterate
thru the validation results and update each field with appropriate
CSS, error messages, highlighting...etc.
I was able to resolve by doing a kind of a hack solution. Here are basic details of what i did:
I created a class (GenericModel) which has a collection of objects representing properties in a model.
I created a validator class that inherits from AbstractValidator.
Based on GenericModel's collection of "property objects" + additional metadata about each property's validation rules and error messages, i was able to add FluentValues Rules, all at run-time.
At the EditForm i handled the OnSubmit event. In that event handler i execute validation via FluentValidation's ValidateAsync() method.
Finally, i iterate thru the validation results and update each field with appropriate CSS, error messages, highlighting...etc.
I would like to determine whether an entity property is required or not.
Does anyone know how to access all of the constraints for a given entity property?
I want to check if the NotBlank constraint is active for a certain propery.
information:
You can check the mapping information for a class (or object) with the help of the service:
validator.mapping.class_metadata_factory
The underlying class is:
Symfony\Component\Validator\Mapping\ClassMetadataFactory
The service provides a method getMetadataFor() that allows you to obtain the active mapping metadata for a class (or object).
This method returns an instance of...
Symfony\Component\Validator\Mapping\ClassMetadata
... that provides a getPropertyMetadata(string $property) method that returns the Metadata for a given property name.
example usage:
Inside a controller (or any other ContainerAware instance) you can do:
$factory = $this->container->get('validator.mapping.class_metadata_factory');
$classMetadata = $factory->getMetadataFor('Your\Bundle\Entity\Name');
$propertyMetadata = $classMetadata->getPropertyMetadata('propertyName');
View the list of Supported Validation Constraints Reference from Symfony web site
You can try ladybug bundle. It is very easy to use and shows in detail and nicely to see all properties and info inside an object.
I need to be able to send transactional emails that include a conditional sentence. I want to include a sentence in the order confirmation emails for any orders that contain certain products. There plenty of examples of how to use conditionals within a transaction emails based on the built in variables, but I want to base the conditional on my own variable that I'll create programmatically from within my own extension.
The mailer class Mage_Core_Model_Email_Template_Mailer does have a public setTemplateParams method, but as that method just calls the base classes setData method, even if I could access that method to set my own parameters it would overwrite the core template parameters that are necessary to show the contents of the basket.
How to achieve this?
You should create a new order attribute where you save your conditional sentence.
Then you can access your attribute easily in the transactional email template via {{htmlescape var=$order.getYourAttribute()}}
The attribute you are creating is related to which entity product or customers
For customer you can get it by
{{var order.getCustomer().getAttrName()}}
I want to create a subscriber that gets triggered when the user tries to access the resource (which is a custom content-type). So, the object is not being added, modified, nothing, is just being traversed. Something like a Zope View Event.
So, basically, suppose a custom content type has a custom workflow (two states: private and viewed). The initial state is private. This content type is only going to be created programatically, using _createObjectByType by anonymous users. Suppose an object called myobjet was added, programatically, to the root folder of my Plone site.
What I want is: when the user access
http://localhost:8080/Plone/myobject
...it automatically changes the state of the workflow of this object to viewed. The url http://localhost:8080/Plone/myobject is going to be a custom view, not the default base_edit.
Which event should I use? I tried IEndRequestEvent and IBeforeTraverseEvent from this list and none of them work: the handler is not being called for my custom object interface.
I've tried other events with my custom object interface (like IObjectEditedEvent), and, for this event, my handler is called when I edit an object that implements the interface. But using IEndRequestEvent and IBeforeTraverseEvent doesn't call the handler.
IEndRequestEvent and IBeforeTraverseEvent only work when I set the subscriber to all interfaces:
<subscriber
for="*
zope.app.publication.interfaces.IBeforeTraverseEvent"
handler=".subscriber.myhandler"
/>
And when I make myhandler print the object and the event in this situation, it shows:
<PloneSite at Plone>
<zope.app.publication.interfaces.BeforeTraverseEvent object at 0xd52618c>
If the solution is to write an event myself, is there an easy tutorial for this?
You might want to have a look at http://pypi.python.org/pypi/plone.validatehook.
Make sure you bind the event to the right interface. If you bind it to "Interface" (as described on the plone.validatehook pypi page) the event will get called for every single request. In order to restrict the event to contentish objects you can do the following:
from Products.CMFCore.interfaces import IContentish
#adapter(IContentish, IPostValidationEvent)
def RedirectMember(object, event):
...
(Edit: I removed my first answer because it didn't work)
Not sure what this subscriber is supposed to do, but if the object is not being modified, added or whatsoever than I must suspect it will just be viewed...so why not just use the __call__ method of the items view (or the __update__ method if you are using five.grok/dexterity)?
I'm using Stripes and I am validating the values of a drop down box to ensure the user selects an option.
On initial load all data is present, but once the validation kicks in the form loses the data that was set up in the action bean on load. This includes the original list I am validating against.
I'm simply using in the jsp, and annotating the field in the action bean as #Validate(required=true).
Am I missing something simple?
Cheers
Fixed it.
I should use #Before methods to pre-populate domain objects, as per the Stripes best practice.
manual