FrontTabPlugin.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\CatalogSearch\Block\Plugin;
  7. use Magento\Catalog\Block\Adminhtml\Product\Attribute\Edit\Tab\Front as ProductAttributeFrontTabBlock;
  8. use Magento\CatalogSearch\Model\Source\Weight;
  9. use Magento\Framework\Data\Form;
  10. use Magento\Framework\Data\Form\Element\Fieldset;
  11. /**
  12. * Add Search Weight field to the product attribute add/edit tab
  13. */
  14. class FrontTabPlugin
  15. {
  16. /**
  17. * @var Weight
  18. */
  19. private $weightSource;
  20. /**
  21. * @param Weight $weightSource
  22. */
  23. public function __construct(Weight $weightSource)
  24. {
  25. $this->weightSource = $weightSource;
  26. }
  27. /**
  28. * Add Search Weight field
  29. *
  30. * @param ProductAttributeFrontTabBlock $subject
  31. * @param Form $form
  32. * @return void
  33. */
  34. public function beforeSetForm(ProductAttributeFrontTabBlock $subject, Form $form)
  35. {
  36. /** @var Fieldset $fieldset */
  37. $fieldset = $form->getElement('front_fieldset');
  38. $fieldset->addField(
  39. 'search_weight',
  40. 'select',
  41. [
  42. 'name' => 'search_weight',
  43. 'label' => __('Search Weight'),
  44. 'values' => $this->weightSource->getOptions()
  45. ],
  46. 'is_searchable'
  47. );
  48. $subject->getChildBlock('form_after')
  49. ->addFieldMap('search_weight', 'search_weight')
  50. ->addFieldDependence('search_weight', 'searchable', '1');
  51. }
  52. }