Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
TemplateSelector.php
Go to the documentation of this file.
1 <?php
7 
14 {
20  protected $_coreRegistry = null;
21 
27  protected $_setColFactory;
28 
34  protected $_resourceHelper;
35 
43  public function __construct(
44  \Magento\Framework\View\Element\Template\Context $context,
45  \Magento\Eav\Model\ResourceModel\Entity\Attribute\Set\CollectionFactory $setColFactory,
46  \Magento\Framework\Registry $registry,
47  \Magento\Catalog\Model\ResourceModel\Helper $resourceHelper,
48  array $data = []
49  ) {
50  $this->_setColFactory = $setColFactory;
51  $this->_coreRegistry = $registry;
52  $this->_resourceHelper = $resourceHelper;
53  parent::__construct($context, $data);
54  }
55 
62  public function getSuggestedTemplates($labelPart)
63  {
64  $product = $this->_coreRegistry->registry('product');
65  $entityType = $product->getResource()->getEntityType();
66  $labelPart = $this->_resourceHelper->addLikeEscape($labelPart, ['position' => 'any']);
68  $collection = $this->_setColFactory->create();
69  $collection->setEntityTypeFilter(
70  $entityType->getId()
71  )->addFieldToFilter(
72  'attribute_set_name',
73  ['like' => $labelPart]
74  )->addFieldToSelect(
75  'attribute_set_id',
76  'id'
77  )->addFieldToSelect(
78  'attribute_set_name',
79  'label'
80  )->setOrder(
81  'attribute_set_name',
83  );
84  return $collection->getData();
85  }
86 }
__construct(\Magento\Framework\View\Element\Template\Context $context, \Magento\Eav\Model\ResourceModel\Entity\Attribute\Set\CollectionFactory $setColFactory, \Magento\Framework\Registry $registry, \Magento\Catalog\Model\ResourceModel\Helper $resourceHelper, array $data=[])