Our Symfony application is currently one application, that will soon require ability to have multiple sites point to the same Symfony core and have slightly different functionality based on which site it is currently on.
As an example we might have a banner showing on one site but not another. Another example is a payment option that will be enabled/disabled on the different sites. Or another one is different fields on a form on the different sites.
Has anybody had experience structuring Symfony application in this way?
If you want to "theme" your application you can use the LiipThemeBundle, it really works well. For the features activation/deactivation you also have the FeatureToggleBundle bundle (quiet recent).
You could also implement a basic helper like this:
/**
* Check if a feature is activated.
*
* #param string $feature Name of the feature
*
* #throws AccessDeniedHttpException
*/
protected function checkFeature($feature)
{
$features = $this->container->getParameter('app.features')
if (!$features[$feature]) {
throw new AccessDeniedHttpException();
}
}
...
$this->checkFeature('contact_form');
With this kind of configuration:
app.features:
contact_form: false
You have to know that using kernel event listener you can do most of the work.
You can in a 'CoreBundle' for example refer the user to a different template depending on the domain name where he is, using the kernel.request event.
So in your situation it would be easy for a site to showing a banner in a site but not another.
You can look this article that explains it :
Twig templating using event listener
Yess thats the advantage of symfony
symfony use the kernel connected with routing and controller and then response is being created.
If you want to use multiple applications in symfony you can do this very easily and that is an advantage of symfony.For this you just need to add some routing and everything will be done automatically.
You can use symfony form class to add forms and append them to other pages with required field without creating whole form again.
If you want to add or remove some features on/off you can just do this by app class or by creating different controllers.
Related
I am building a plugin for Shopware 6 and cannot seem to find any documentation as to how to extend an existing controller action. I found this How to add an Action to Account Controller in Shopware but it seems to refer to Shopware 5 and I am not sure I can use it that way in Shopware 6.
The controller action I want to extend is \Shopware\Storefront\Controller\AddressController::saveAddress - in my case I want to add custom address validation that would use a service in my plugin where a request to 3rd party API would be made, if the address is correct then allow the address, if not then return an error. Perhaps it is better to instead extend \Shopware\Core\Checkout\Customer\SalesChannel\AddressService::save but I have no clue for now (I am new to Shopware in general). Extending the service would mean I do not have to override the whole action logic so that it contains my check in the middle. Or perhaps there is an event I can use for address saving (same thing, can't find a good source/list of events for Shopware6).
There seem to be guides here:
https://docs.shopware.com/en/shopware-platform-dev-en/developer-guide/controller
and here:
https://docs.shopware.com/en/shopware-platform-dev-en/how-to/custom-storefront-controller
but these only describe how to make a new controller and it is not very useful to me since I do not want to add any new routes but use the existing one /account/address/create.
I would be very grateful for a code example of how to register the override in the plugin (config, xml) and how would the extending class look like. If it is not too much to ask the ideal answer would contain an example of:
How to extend an action for existing controller.
How to extend an existing service.
Where to find which event is firing in a controller/service, subscribe to it and make it override default behaviour (like throw Shopware\Core\Framework\Validation\Exception\ConstraintViolationException).
It does not make sense to extend/override action, as action should be as thin as it is possible, and all business logic should be in service.
To extend existing service you can decorate it or subscribe to some events to extend functionality. See https://docs.shopware.com/en/shopware-platform-dev-en/how-to/decorating-a-service
In your case, you can subscribe on framework.validation.address.create or/and framework.validation.address.update events to extend list of constraints. In general all validation events have prefix framework.validation. second part is defined in \Shopware\Core\Framework\Validation\DataValidationFactoryInterface implementation in your case it is \Shopware\Core\Checkout\Customer\Validation\AddressValidationFactory
We have 2 application one is main application and second is moodle 3.6, we want to trigger a callback from Moodle to our main application when a user starts a course or complete a course, How to implement this functionality.
Thanks in advance.
You may code it along this lines:
Create a plugin for Moodle, if you are just handling this "event emission" thing, you may just make a "local plugin" (https://docs.moodle.org/dev/Local_plugins). I recommend you to use a plugin skeleton generator to generate the boilerplate code for the plugin: https://moodle.org/plugins/tool_pluginskel
In your plugin, register the event observers for the relevant core events (documentation here: https://docs.moodle.org/dev/Event_2#Event_observers ). For example: course_completed would be an straightforward one according to your needs. You have a list of events here: https://docs.moodle.org/dev/Event_2#Existing_events .
From the listener method linked to the observer you can make the relevant external calls to your main app.
How to add a custom form to sulu CMS (example: complex contact form) and save values to database? Is there any good example? Documentation does not mention about custom development.
Regards,
As long as your forms are static (meaning the content manager is not able to choose which fields are appearing), you can simply do what is described in the Symfony documentation.
There are two (probably even more) different possibilities to include Symfony forms:
The first one is to create your own route and controller, working with Symfony forms as you would do in any other Symfony application.
The second one is to use the template system of Sulu as described in our documentation. Then you can add a few fields for content management around the form the content manager can use. In the template defined in the <view> tag of the XML you can again use Symfony form stuff. If you need any special information from the system you can even change the <controller> tag of the XML, to pass more than only the data from the content management.
There are also some ideas concerning a more sophisticated form manager floating around, but that's far from being published.
I'm thinking of creating admin page with forms to modify, delete and add content to simple pages of website. What would you recommend me to approach this in Symfony2?
Should I create new Bundle or just new Action in same controller where all the other pages are.
I heard of this SonataAdmin, but I am not sure I need something this complicated. My admin page will only contain few forms to modify some data that is stored on website. I don't need CMS functionality to create pages or posts.
All I want is simple, safe admin page and to know how nowadays this problem is solved.
Just create something like a AdminBundle and create your forms there.
Secure your routes so that you need to login to acces that routes.
SonataAdmin is to much for this kind of work.
Example of a secured function where you need to be logged in as admin :
/**
* #Route("/", name="homepage", name="homepage")
* #Route("/{_locale}", name="homepage", name="homepage")
* #Security("has_role('ROLE_ADMIN')")
* #Template("ProdacomMainBundle:Main:index.html.twig")
*/
public function indexAction() {
return array();
}
It looks like you really don't need SonataAdminBundle. It's huge and sometime difficult to understand. So, for such functionality you can create some secured area in your routing and use to access management pages. Or you can implement simple authentication with hardcoded (inside config files) credentials (look detailed description here: http://symfony.com/doc/current/book/security.html) and show for authenticated user additional elements on the pages (forms, buttons, etc.). It really depends on your wishes. I think you have to overthink all you have and just decide which way is more convenient for you.
I have a symfony module for my GenericImport class. Rather than the default method symfony uses for the list page, I want to use GenericImportTable::getQueue(). I thought the following would work but it didn't:
config:
actions: ~
fields:
list:
peer_method: getQueue
How can I use a custom query for the list page? (I'm using Doctrine.)
(To be clear, I don't wish to manually create a whole new custom action. I'm going the route I'm going because I want to take advantage of everything that comes with the admin generator like batch actions, the filter, etc.)
Try table_method.
...and read more here: http://www.symfony-project.org/jobeet/1_4/Doctrine/en/12#chapter_12_sub_table_method