-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #862 from zuk3975/feature-value-migrated-fields
Add missing form fields in migrated FeatureValue form
- Loading branch information
Showing
7 changed files
with
311 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
<?php | ||
/** | ||
* Copyright since 2007 PrestaShop SA and Contributors | ||
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA | ||
* | ||
* NOTICE OF LICENSE | ||
* | ||
* This source file is subject to the Academic Free License 3.0 (AFL-3.0) | ||
* that is bundled with this package in the file LICENSE.md. | ||
* It is also available through the world-wide-web at this URL: | ||
* https://opensource.org/licenses/AFL-3.0 | ||
* If you did not receive a copy of the license and are unable to | ||
* obtain it through the world-wide-web, please send an email | ||
* to license@prestashop.com so we can send you a copy immediately. | ||
* | ||
* @author PrestaShop SA <contact@prestashop.com> | ||
* @copyright Since 2007 PrestaShop SA and Contributors | ||
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0) | ||
*/ | ||
|
||
namespace PrestaShop\Module\FacetedSearch\Form\FeatureValue; | ||
|
||
use Db; | ||
|
||
/** | ||
* Provides form data | ||
*/ | ||
class FormDataProvider | ||
{ | ||
/** | ||
* @var Db | ||
*/ | ||
private $database; | ||
|
||
public function __construct(Db $database) | ||
{ | ||
$this->database = $database; | ||
} | ||
|
||
/** | ||
* Fills form data | ||
* | ||
* @param array $params | ||
* | ||
* @return array | ||
*/ | ||
public function getData(array $params) | ||
{ | ||
$defaultUrl = []; | ||
$defaultMetaTitle = []; | ||
|
||
// if params contains id, gets data for edit form | ||
if (!empty($params['id'])) { | ||
$featureValueId = (int) $params['id']; | ||
|
||
$result = $this->database->executeS( | ||
'SELECT `url_name`, `meta_title`, `id_lang` ' . | ||
'FROM ' . _DB_PREFIX_ . 'layered_indexable_feature_value_lang_value ' . | ||
'WHERE `id_feature_value` = ' . $featureValueId | ||
); | ||
|
||
if (!empty($result) && is_array($result)) { | ||
foreach ($result as $data) { | ||
$defaultUrl[$data['id_lang']] = $data['url_name']; | ||
$defaultMetaTitle[$data['id_lang']] = $data['meta_title']; | ||
} | ||
} | ||
} | ||
|
||
return [ | ||
'url' => $defaultUrl, | ||
'meta_title' => $defaultMetaTitle, | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
<?php | ||
/** | ||
* Copyright since 2007 PrestaShop SA and Contributors | ||
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA | ||
* | ||
* NOTICE OF LICENSE | ||
* | ||
* This source file is subject to the Academic Free License 3.0 (AFL-3.0) | ||
* that is bundled with this package in the file LICENSE.md. | ||
* It is also available through the world-wide-web at this URL: | ||
* https://opensource.org/licenses/AFL-3.0 | ||
* If you did not receive a copy of the license and are unable to | ||
* obtain it through the world-wide-web, please send an email | ||
* to license@prestashop.com so we can send you a copy immediately. | ||
* | ||
* @author PrestaShop SA <contact@prestashop.com> | ||
* @copyright Since 2007 PrestaShop SA and Contributors | ||
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0) | ||
*/ | ||
|
||
namespace PrestaShop\Module\FacetedSearch\Form\FeatureValue; | ||
|
||
use Context; | ||
use PrestaShop\Module\FacetedSearch\Constraint\UrlSegment; | ||
use PrestaShopBundle\Form\Admin\Type\TranslatableType; | ||
use PrestaShopBundle\Translation\TranslatorComponent; | ||
use Symfony\Component\Form\FormBuilderInterface; | ||
|
||
/** | ||
* Adds module specific fields to BO form | ||
*/ | ||
class FormModifier | ||
{ | ||
/** | ||
* @var Context | ||
*/ | ||
private $context; | ||
|
||
public function __construct(Context $context) | ||
{ | ||
$this->context = $context; | ||
} | ||
|
||
public function modify( | ||
FormBuilderInterface $formBuilder, | ||
array $data | ||
) { | ||
/** | ||
* @var TranslatorComponent | ||
*/ | ||
$translator = $this->context->getTranslator(); | ||
$invalidCharsHint = $translator->trans( | ||
'Invalid characters: <>;=#{}_', | ||
[], | ||
'Modules.Facetedsearch.Admin' | ||
); | ||
|
||
$urlTip = $translator->trans( | ||
'When the Faceted Search module is enabled, you can get more detailed URLs by choosing ' . | ||
'the word that best represents this feature. By default, PrestaShop uses the ' . | ||
'feature\'s value, but you can change that setting using this field.', | ||
[], | ||
'Modules.Facetedsearch.Admin' | ||
); | ||
$metaTitleTip = $translator->trans( | ||
'When the Faceted Search module is enabled, you can get more detailed page titles by ' . | ||
'choosing the word that best represents this feature. By default, PrestaShop uses the ' . | ||
'feature\'s value, but you can change that setting using this field.', | ||
[], | ||
'Modules.Facetedsearch.Admin' | ||
); | ||
|
||
$formBuilder | ||
->add( | ||
'url_name', | ||
TranslatableType::class, | ||
[ | ||
'required' => false, | ||
'label' => $translator->trans('URL', [], 'Modules.Facetedsearch.Admin'), | ||
'help' => $urlTip . ' ' . $invalidCharsHint, | ||
'options' => [ | ||
'constraints' => [ | ||
new UrlSegment([ | ||
'message' => $translator->trans('%s is invalid.', [], 'Admin.Notifications.Error'), | ||
]), | ||
], | ||
], | ||
'data' => $data['url'], | ||
] | ||
) | ||
->add( | ||
'meta_title', | ||
TranslatableType::class, | ||
[ | ||
'required' => false, | ||
'label' => $translator->trans('Meta title', [], 'Modules.Facetedsearch.Admin'), | ||
'help' => $metaTitleTip, | ||
'data' => $data['meta_title'], | ||
] | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
/** | ||
* Copyright since 2007 PrestaShop SA and Contributors | ||
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA | ||
* | ||
* NOTICE OF LICENSE | ||
* | ||
* This source file is subject to the Academic Free License 3.0 (AFL-3.0) | ||
* that is bundled with this package in the file LICENSE.md. | ||
* It is also available through the world-wide-web at this URL: | ||
* https://opensource.org/licenses/AFL-3.0 | ||
* If you did not receive a copy of the license and are unable to | ||
* obtain it through the world-wide-web, please send an email | ||
* to license@prestashop.com so we can send you a copy immediately. | ||
* | ||
* @author PrestaShop SA <contact@prestashop.com> | ||
* @copyright Since 2007 PrestaShop SA and Contributors | ||
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0) | ||
*/ | ||
if (!defined('_PS_VERSION_')) { | ||
exit; | ||
} | ||
|
||
function upgrade_module_3_13_0(Ps_Facetedsearch $module) | ||
{ | ||
$newHooks = [ | ||
'actionFeatureValueFormBuilderModifier', | ||
'actionAfterCreateFeatureValueFormHandler', | ||
'actionAfterUpdateFeatureValueFormHandler', | ||
]; | ||
|
||
return $module->registerHook($newHooks); | ||
} |