Quote:
Originally Posted by Soptareanu Alex
Yes, this is was the solution that i found and use but still remains a problem because when i finish my module i want to install in an production env and there i don't have the access to go and hard-code the yaml file. I need a solution if can be posible to do this task when i deploy the module.
|
There are several ways how to overcome the problem.
1) Decorate \XLite\Model\AddressField class and define its getSchemaClass() method as follows:
Code:
public function getSchemaClass()
{
if ($this->getServiceName() == 'city') {
return '\XLite\Module\DevID\ModuleID\View\FormField\Select\MyCustomClass';
} else {
return parent::getSchemaClass();
}
}
2) In your module's Main.php file create runBuildCacheHandler() method that will change 'schemaClass' property of the Address Field.
Here is an example script that shows how you can change 'schemaClass' property for 'city' address field:
Code:
<?php
include "top.inc.php";
$cityField = \XLite\Core\Database::getRepo('XLite\Model\AddressField')->createQueryBuilder('af')
->andWhere('af.serviceName = :city')
->setParameter('city', 'city')
->getSingleResult();
$cityField->setSchemaClass('\XLite\View\FormField\Input\Text');
\XLite\Core\Database::getEM()->flush();
So, in your module you should define 'schemaClass' as your own value, if the module is enabled:
Code:
\XLite\Core\Database::getRepo('XLite\Model\Module')->isModuleEnabled('DevID\ModuleID')
or if your module is inactive, then you define 'schemaClass' as usual '\XLite\View\FormField\Input\Text'.
Please, let me know if it makes sense to you.
Tony