Is it possible to create a group dependency in JMS - symfony

Lets say I have following structure:
Article:
name
content
galleries: array of Gallery
Gallery:
name
description
media : array of Media
thumbnail: Media
Media:
name
file
Now when I am serializing The article or something that contains a gallery I need to specify groups for all children like this:
'groups' => [
'All',
'gallery' => [
'Details',
'thumbnail' => ['Basic'],
],
],
Now every time I add something to the gallery I need to go thorough all controllers and add the deep dependencies eg. After adding a largeThumbnail field:
'groups' => [
'All',
'gallery' => [
'Details',
'thumbnail' => ['Basic'],
'largeThumbnail' => ['Basic'],
],
],
If I dont do it, or miss a controller, it will include "largeThumbnail" with group "Details" instead of "Basic" and cause a lot of databasse requests (since without Groups defined it will just follow the tree and add everything it finds) killing the performance.
Is there a way to tell JMS what groups an entities children should have when a specific group is used for parent?
In other words can I tell that if I used "Details" For Gallery than it should use "Basic" for Gallery->media, so I can simplify the above to just saying:
'groups' => [
'All',
'gallery' => ['Details'],
],
And it would fill in 'thumbnail' => ['Basic'], for me?

Related

WordPress Custom Email Trigger

I'm using Crocoblocks/JetReviews to add reviews to my site (on a custom post type).
I can see there is a setting to require admin approval for it to be published, but I want to trigger an email to one of the admins when a review is submitted, and I don't see any settings for that so I'll have to do it myself.
I think I can handle the function to send the email, but can't sort out what to hook into or trigger it against?
Using something like this:
if ( function_exists( 'notification' ) ) :
notification( [
'title' => 'Admin Notification for Review Approval', // For internal reference.
'trigger' => 'trigger_slug', // Trigger slug (can be a Triggerable object).
'carriers' => [ // An array with format: carrier_slug => data array
'email' => [
'activated' => true, // Must be true.
'enabled' => true, // Must be true.
'subject' => 'A New Review Needs Approval',
'body' => 'There is a new review awaiting your approval.',
'recipients' => [
[
'type' => 'administrator',
'recipient' => 'admin#adminemail.com',
],
],
],
],
'enabled' => true, // Must be true.
] );
endif;
But right now that's not connected to any action...and that's where I'm lost.
Any thoughts of where to look? I couldn't figure it out from their docs so hoping someone here might have an idea of where to start at least.
Thanks!
Chad

adding Woocommerce attribute to a product via API

Ok, so, I have a fair bit of experience with the Woocommerce API and PHP and use it for lots of product population from XML files. However, I'm having a problem adding attributes. Well, thats not strictly true, the attributes DO add, but then throw up an error after they do.
I'm using the Automattic PHP code and, as I say, it does most things fine.
$data = [
'attributes' => [
[
'id' => 9,
'position' => 0,
'visible' => true,
'variation' => false,
'options' => [
'bathroom'
]
]
]
];
$woocommerce->put('products/123', $data);
but that gives me the error
'Error: Invalid parameter(s): attributes [rest_invalid_param]' in
/vendor/automattic/woocommerce/src/WooCommerce/HttpClient/HttpClient.php:348 Stack trace: #0
Although when I look at the product, the attribute has been added correctly.

Symfony : Sonata admin custom List Fields URL

After looking in the documentation :
https://sonata-project.org/bundles/admin/master/doc/reference/field_types.html
I need your help because i want to go a little further in customization and it's not indicated how to do in the documentation.
With this :
->add('hash', "url", array(
'label' => 'HashCode',
'header_style' => 'width: 20%; text-align: center',
'row_align' => 'center',
'route' => array(
'name' => 'cr_whiz_home',
'identifier_parameter_name' => 'id[]'
)
))
I can generate this URL for example:
http://localhost/Symfony/web/app_dev.php/home?id%5B%5D=27
But what I search is to change 27 at the end, because Sonata Admin take automatically id of the entity. I want to take another, the HashCode, i think there is a parameter to change it, but I didn't find it.
Can you help me ? Thank's !

A2LiX Translation Form labels options

I'm using KnpLabs/DoctrineBehaviors/Translatable and A2LiX Translation Form to translate my entities in a Symfony application. It works very well. However, when the form is rendered there is a "translations" title that I would like to delete and a "EN [Default]" text on a tab that I would like to change.
In the examples of the doc, there's a "medias" example so I imagine that we can change this text. Moreover, the tabs don't have this [Default] text. So I imagine that's possible to change them.
And this is mine:
Does anybody know how to do it? If we take a look on the form type options we don't see anything concerning the "Translations" label. For the "Default", I can't see where I should search for it.
Default template file is located at vendor/a2lix/translation-form-bundle/A2lix/TranslationFormBundle/Resources/views/default.html.twig. If you want you can specify your own template and set it in config.yml file, like this:
a2lix_translation_form:
....
templating: "#SLCore/includes/translation.html.twig"
More information can be found here.
For the "translations" title, I was able to override it adding a label to the form type just like a normal field. However, it is not possible to use a blank value. I had to use ' ' in order to override the text.
->add('translations', 'a2lix_translations', array(
'label' => ' ', --> this overrides the translations title
'fields' => array(
'name' => array(
'field_type' => 'text',
'label' => 'blabla'
),
'description' => array(
'field_type' => 'textarea',
'label' => 'bleble',
)
)
))
For the "Default" label, I still have no solution.

How to disable HTML escaping of labels in KnpMenuBundle

I want to render an HTML label like:
$menu->addChild('Dashboard', array(
'route' => 'dashboard',
'label' => '<i class="fa-icon-bar-chart"></i><span class="hidden-tablet"> Dashboard</span></a>',
'extra' => array('safe_label' => true)
)
);
And I've pass the proper option while rendering:
{{ knp_menu_render('WshCmsHtmlBundle:Builder:mainMenu', {'allow_safe_labels': true} ) }}
But my label is still being escaped. What am I doing wrong?
Ok, the answer is!
You set up extra items on menu item not by 'extra' key but by 'extras' key.
So when you setup the item like this:
$menu->addChild('Dashboard', array(
'route' => 'dashboard',
'label' => '<i class="fa-icon-bar-chart"></i><span class="hidden-tablet"> Dashboard</span></a>',
'extras' => array('safe_label' => true)
)
);
it works fine!
There's two steps to achieve this.
1. MenuBuilder
You have to set safe_label to true in extras. Note that you can now write HTML in your label.
$menu->addChild('Home<i><b></b></i>', array(
'route' => 'homepage',
'extras' => array(
'safe_label' => true
),
));
2. Twig
You have to filter the output of knp_menu_render() so that it prints raw HTML (see documentation).
{{ knp_menu_render('main', {'allow_safe_labels': true}) | raw }}
Warning
Please be aware that this may be dangerous. From the documentation:
Use it with caution as it can create some XSS holes in your application if the label is coming from the user.
I used FyodorX's method to add a strong tag. It works like a charm but I must say that the raw filter is not necessary

Resources