Get current action in extbase - extbase

TYPO3 v8
I have created a custom Validator class in my extbase project.
I call the validator on the model:
* #validate ME\MyProject\Domain\Validator\MyCustomValidator
I need to check/test what the current Action is inside the validator class.
How do I find this out?
Thanks again T3 community

Related

How add verifications before update dados of an item using framework symfony?

I need to check information when updating an item, to know if saving is allowed or not. This must be done in the backend after the user have clicked on 'UPDATE' button. I'm using Symfony and the existing methods in CRUDController. Is there any method I can add in Controller or Entity so I can add code that does this check before saving?
You have multiple ways to set validation with Symfony.
If I understand well your question, you maybe need to look at the callbacks
https://symfony.com/doc/current/reference/constraints/Callback.html
The purpose is to create custom validation with dedicated functions (like only saving an item if it meets some requirement.)

Registering additional validators on PloneFormGen

I'm trying to register a new validator to the available list of validators you can select in a PloneFormGen field.
The task seems simple at the beginning: I registered a new Archetypes validator and I found a way to add it to the dropdown list (through a monkey-patch to add new item to stringValidators tuple) and a call to initStringValidators method of the PFG tool.
Still, selecting my new validator will not lead to anything: the __call__ method is never called.
What I'm missing?

Custom ErrorMessage for model validation attributes

I am new to MVC, so please bear with me.
We have a large WebForms website, where content is managed by a
custom CMS. I have added DataAnnotation attributes to my model
properties. The attributes have an ErrorMessage property, but this
must be a compile-time constant.
I would like to get error message texts at runtime from out custom
CMS. We already do this in our WebForms pages, so the infrustructure
is in place i.e. manager classes with aproprate methods for retrieving
the correct texts by key.
My question is where do I hook in at runtime in order to populate the
texts from the CMS to be displayed when validation error occur
client-side or server-side?
One way I guess would be to create your own DataAnnotationsModelMetadataProvider. Derive from this class and override the CreateMetadata method. Don't forget to register your custom MetaDataProvider with the ModelMetadataProviders when your WebApp initializes.

Symfony 1.4 - Accessing values from the parent of an embedded form in an instance of sfValidatorCallback

$values seems to be sandboxed to that of the form you are calling the sfValidatorCallback from.
I need to be able to query a posted value from the parent form against something in the embedded form I'm calling the post validator from. Can anyone think of a way to do this?
Can you check the possibility of overwriting the form submit/validation method in the form class to pass these value when the parent::method() is being called?

Where to place common business logic for all pages in symfony2

I am now working on my first symfony2 project. I have created a service, and I need to call it for every controllers to generate a html which is necessary throughout the all pages in my website.
So I created a BaseController class which extends Symfony\Bundle\FrameworkBundle\Controller\Controller class and tried to place the code in this BaseController class. Now whenever I call from the constructor:
$my_service = $this->get('my_service');
or
$my_service = $this->container->get('my_service');
I got error:
Call to a member function get() on a non-object.
The container object has not been initialized. What is the solution to this problem? How DRY method is followed in symfony2, if I want to place left panel or header in all pages which contains dynamic data?
Thanks in advance.
You shouldn't use the constructor in your controller class, especially when you inherit from Symfony Controller: that way you get the container after the object instantiation (the DIC will call the setContainer method inherited from Symfony's Controller).
In general, for your first experiments, use the services in the action methods; if there is some cross-cutting logic that you need to execute in every request you could consider registering some event listeners (see the "Internals" docs in the Symfony website).
When you get more confidence with the framework you can start thinking about not inheriting Symfony's Controller, registering your controller classes in the DIC and injecting the services that you need manually (eventually implementing some logic in the constructor).
I know this is not the answer you desire, but if you need some html on all pages, I think using a service the way you do is the wrong way.
I guess you know about twig and the possibility to use a layout to place common code. But you can also embed a controller:
{% render "AcmeArticleBundle:Article:recentArticles" %}
Within the recentArticlesAction, you can place your specific code and return a template. By this, you can get custom html into each of your templates! See the symfony docs for more: http://symfony.com/doc/current/book/templating.html#embedding-controllers
Business logic is all the custom code you write for your app that's not specific to the framework (e.g. routing and controllers). Domain classes, Doctrine entities and regular PHP classes that are used as services are good examples of business logic. Ref

Resources