Labels.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Eav\Block\Adminhtml\Attribute\Edit\Options;
  7. /**
  8. * Attribute add/edit form options tab
  9. *
  10. * @api
  11. * @author Magento Core Team <core@magentocommerce.com>
  12. * @since 100.0.2
  13. */
  14. class Labels extends \Magento\Backend\Block\Template
  15. {
  16. /**
  17. * @var \Magento\Framework\Registry
  18. */
  19. protected $_registry;
  20. /**
  21. * @var string
  22. */
  23. protected $_template = 'Magento_Catalog::catalog/product/attribute/labels.phtml';
  24. /**
  25. * @param \Magento\Backend\Block\Template\Context $context
  26. * @param \Magento\Framework\Registry $registry
  27. * @param array $data
  28. * @codeCoverageIgnore
  29. */
  30. public function __construct(
  31. \Magento\Backend\Block\Template\Context $context,
  32. \Magento\Framework\Registry $registry,
  33. array $data = []
  34. ) {
  35. parent::__construct($context, $data);
  36. $this->_registry = $registry;
  37. }
  38. /**
  39. * Retrieve stores collection with default store
  40. *
  41. * @return \Magento\Store\Model\ResourceModel\Store\Collection
  42. */
  43. public function getStores()
  44. {
  45. if (!$this->hasStores()) {
  46. $this->setData('stores', $this->_storeManager->getStores());
  47. }
  48. return $this->_getData('stores');
  49. }
  50. /**
  51. * Retrieve frontend labels of attribute for each store
  52. *
  53. * @return array
  54. */
  55. public function getLabelValues()
  56. {
  57. $values = (array)$this->getAttributeObject()->getFrontend()->getLabel();
  58. $storeLabels = $this->getAttributeObject()->getStoreLabels();
  59. foreach ($this->getStores() as $store) {
  60. if ($store->getId() != 0) {
  61. $values[$store->getId()] = isset($storeLabels[$store->getId()]) ? $storeLabels[$store->getId()] : '';
  62. }
  63. }
  64. return $values;
  65. }
  66. /**
  67. * Retrieve attribute object from registry
  68. *
  69. * @return \Magento\Eav\Model\Entity\Attribute\AbstractAttribute
  70. * @codeCoverageIgnore
  71. */
  72. private function getAttributeObject()
  73. {
  74. return $this->_registry->registry('entity_attribute');
  75. }
  76. }