How to translate native SiteConfig with silverstripe-fluent - config

I'm using silverstripe 4 with silverstripe-fluent module. I can't translate native SiteConfig (site name and tagline/slogan) How do that ?
Thank for your help!
Aurélien

I had the same problem. Translating only specific variables.
Solved it simular:
YML (config.yml)
SilverStripe\SiteConfig\SiteConfig:
extensions:
- Pixelparker\Extensions\SiteConfigExtension
- TractorCow\Fluent\Extension\FluentExtension
SiteConfigExtension.php
private static $translate = [
'CookieMessage'
];
thats it.

Solved !
Add TractorCow\Fluent\Extension\FluentExtension in Silverstripe\SiteConfig\SiteConfig :
---
Name: myproject
---
SilverStripe\Core\Manifest\ModuleManifest:
project: app
Silverstripe\SiteConfig\SiteConfig:
extensions:
- TractorCow\Fluent\Extension\FluentExtension
- CustomSiteConfig
and extends FluentExtension instead of DataExtension in your config extension class :
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\HTMLEditor\HTMLEditorField;
use TractorCow\Fluent\Extension\FluentExtension;
class CustomSiteConfig extends FluentExtension
{
private static $db = [
'FooterContent' => 'HTMLText'
];
public function updateCMSFields(FieldList $fields)
{
$fields->addFieldToTab("Root.Main",
new HTMLEditorField("FooterContent", "Footer Content")
);
parent::updateCMSFields($fields);
}
}

If you just want to translate SiteConfig's default Title and Tagline DB field, then you can apply both the Fluent extension and define the DB fields to be translated in a .yml configuration file, like this:
SilverStripe\SiteConfig\SiteConfig:
extensions:
- TractorCow\Fluent\Extension\FluentExtension
translate:
- Title
- Tagline

Related

Lumen 8 - Using Faker in tests makes InvalidArgumentException: Unknown format "name"

I'm using Lumen default Tests only added this line to the test :
$users = \App\Models\User::factory()->count(5)->create();
But i get this error when running the test :
InvalidArgumentException: Unknown format "name"
I did't touch the UserFactory Class i include it below , whats wrong with my code?
public function definition()
{
return [
'name' => $this->faker->name,
'email' => $this->faker->unique()->safeEmail,
];
}
Should anybody else end up here looking for a similar issue in Laravel, make sure you include
parent::setUp();
in your setup method (if you have one). For example,
class ManageDocumentTest extends TestCase
{
public $user;
public function setUp():void
{
parent::setUp();
$this->user = User::factory()->create();
...
Uncommented these lines in app.php and its working now :
$app->withFacades();
$app->withEloquent();
You have to extend use Tests\TestCase instead of PHPUnit\Framework\TestCase.
At least, it helped me.
If you are using Tests\TestCase, calling parent::setUp(); and it still doesn't work, make sure not to call $faker before the actual test - ie. in a #dataProvider it won't work

Apply products list template in a custom module prestashop 1.7

I create a custom module in prestashop 1.7, and I would like to apply the layout of products list on my module and display products what I want. What I have to do ?
My initContent function is
class TestModuleDisplayModuleFrontController extends ModuleFrontController{
public function initContent()
{
parent::initContent();
$this->setTemplate('products.tpl');
}
}
Thanks you
Hi Varag and welcome to Stackoverflow.
Your answer is here waiting for you : https://devdocs.prestashop.com/1.7/modules/concepts/controllers/front-controllers/
For instance your function must look like that :
public function initContent()
{
// In the template, we need the vars paymentId & paymentStatus to be defined
$this->context->smarty->assign(
array(
'paymentId' => Tools::getValue('id'), // Retrieved from GET vars
));
// Will use the file modules/cheque/views/templates/front/validation.tpl
$this->setTemplate('module:cheque/views/templates/front/validation.tpl');
}
I think that you have to use array instead of object:
$listing['products'] = json_decode(json_encode($your_products), true); // convert object to array
$this->context->smarty->assign("listing", $listing);
$this->setTemplate('module:mymodule/views/templates/front/mytemplate.tpl');

Symfony 3.4 : "Could not load type ... : class does not exist"

Sorry, I'm a beginner at Symfony and I've tried to find an answer but nothing worked. I'm using Symfony3.4 which was updated from Symfony 2.8 a few months ago.
Now, I'm trying to do a rather simple thing : using a formType in a Controller, but no matter what, Symfony keeps showing the following error : Could not load type "Cha\GeneralBundle\Form\StripePaymentType": class does not exist.
Here's my StripePaymentType -really, really basic:
namespace Cha\GeneralBundle\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
class StripePaymentType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('name', TextType::class);
}
public function getBlockPrefix()
{
return 'cha_stripe_payment_form';
}
}
Here's my Controller action, once again, a basic thing (I didn't even write any code in there, because of this strange error) :
public function upgradeOfferPaymentAction(Offers $offers)
{
$form = $this->createForm(StripePaymentType::class);
return $this->render(
'#ChaGeneral/Offers/offer_payment.html.twig', array(
'form' => $form->createView()
));
}
I tried to use my form as a service but it did not work either :
cha.stripe.payment.form:
class: Cha\GeneralBundle\Form\StripePaymentType
tags:
- { name: cha_stripe_payment_form }
I'm probably missing something but I can't figure what...
Thank in advance for your help!
You must add this line at the top of the form class:
use Symfony\Component\Form\Extension\Core\Type\TextType;
Revert the SF version is not a solution, is just dodge the problem.
Well, finally I found what caused this problem : somebody did a composer update and we updated from Symfony 3.4.13 to Symfony 3.4.14. A simple revert did the trick, now everything is working again.
Thanks a lot for your help!

yii how to link to module images

my Yii modules file structure looks like this
-yii
-protected
-modules
-admin
-controller
-model
-view
-layout
-main.php
-assets
-css
-style.css
-js
-images
-logo.jpg
what i'm trying to do is access the logo.jpg from my protected/views/site/index.php. How do i do that?
Your should publish your assets first, then use this url. Add this code in your module:
class YourModule extends CWebModule
{
private $_assetsUrl;
public function getAssetsUrl()
{
if ($this->_assetsUrl === null)
$this->_assetsUrl = Yii::app()->getAssetManager()->publish(__DIR__ . '/assets', false, -1, true);
return $this->_assetsUrl;
}
Then use this url:
$assets = $this->module->getAssetsUrl();
echo $assets . '/images/logo.jpg'

IDEA GDSL How to add a method defination to all files(Classes) in a folder?

In my Grails Application, there a folder grails-app/mongoDomain. In this folder there are several classes that too in various packages.
I want to add a GDSL Defination for a method say "save()" to all classes inside the folder grails-app/mongoDomain.
I was successfully able to add this method to a single class, but any method to add in all classes in grails-app/mongoDomain??
.
.
I tried Doing this, but it did't worked..
def mongoDomainContext = context(pathRegexp: /.*grails-app\/mongoDomain.*/)
contributor(mongoDomainContext) {
method(name: 'save', type: 'void', params: [closure: { }])
}
But the above code did't worked, What is the right method for doing it??
.
.
Regards
Kushal
Unfortunately, there's no such GDSL primitive yet. In Griffon, they have the following GDSL fragment using undocumented features:
['Controller', 'Model', 'View', 'Service'].each { type ->
String artifactPath = type.toLowerCase() + 's'
contributor(ctype: PsiJavaPatterns.psiClass().withName(PlatformPatterns.string().matches(/.*${type}/))) {
def path = psiClass.containingFile.originalFile.virtualFile.path
if (path =~ ".*/*griffon-app/${artifactPath}/.*") {
delegatesTo(findClass("griffon.core.Griffon${type}"))
if (type == 'View') {
addNodeContributions(delegate)
}
}
}
}
They match on both class name and its path here, you need only the second part, inside the conributor call.
Here's how I did it and it works. Great thanks to Peter Gromov for providing the hint.
def mongoContext = context(
ctype: PsiJavaPatterns.psiClass().withName(PlatformPatterns.string().matches(/.*/))
)
contributor(mongoContext) {
def path = ""
try {
path = psiClass.containingFile.originalFile.virtualFile.path
} catch (Exception e) {/*This is to prevent any non Class null matches*/}
if (path =~ ".*/*grails-app/mongoDomain/.*")//Matches Directory
{
//Code Here to add methods/Properties etc
}
}
It worked like a charm. Thanks to all.