Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
CreateUrlAttributes.php
Go to the documentation of this file.
1 <?php
8 
10 use Magento\Eav\Setup\EavSetupFactory;
15 
21 {
25  private $moduleDataSetup;
26 
30  private $eavSetupFactory;
31 
37  public function __construct(
38  ModuleDataSetupInterface $moduleDataSetup,
39  EavSetupFactory $eavSetupFactory
40  ) {
41  $this->moduleDataSetup = $moduleDataSetup;
42  $this->eavSetupFactory = $eavSetupFactory;
43  }
44 
48  public function apply()
49  {
51  $eavSetup = $this->eavSetupFactory->create(['setup' => $this->moduleDataSetup]);
52  $eavSetup->addAttribute(
53  \Magento\Catalog\Model\Category::ENTITY,
54  'url_key',
55  [
56  'type' => 'varchar',
57  'label' => 'URL Key',
58  'input' => 'text',
59  'required' => false,
60  'sort_order' => 3,
61  'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_STORE,
62  'group' => 'General Information',
63  ]
64  );
65 
66  $eavSetup->addAttribute(
67  \Magento\Catalog\Model\Category::ENTITY,
68  'url_path',
69  [
70  'type' => 'varchar',
71  'required' => false,
72  'sort_order' => 17,
73  'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_STORE,
74  'visible' => false,
75  'group' => 'General Information',
76  ]
77  );
78  $eavSetup->addAttribute(
79  \Magento\Catalog\Model\Product::ENTITY,
80  'url_key',
81  [
82  'type' => 'varchar',
83  'label' => 'URL Key',
84  'input' => 'text',
85  'required' => false,
86  'sort_order' => 10,
87  'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_STORE,
88  'used_in_product_listing' => true,
89  'group' => 'Search Engine Optimization',
90  'is_used_in_grid' => true,
91  'is_visible_in_grid' => false,
92  'is_filterable_in_grid' => true,
93  ]
94  );
95  $eavSetup->addAttribute(
96  \Magento\Catalog\Model\Product::ENTITY,
97  'url_path',
98  [
99  'type' => 'varchar',
100  'required' => false,
101  'sort_order' => 11,
102  'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_STORE,
103  'visible' => false,
104  ]
105  );
106  }
107 
111  public static function getDependencies()
112  {
113  return [];
114  }
115 
119  public static function getVersion()
120  {
121  return '2.0.0';
122  }
123 
127  public function getAliases()
128  {
129  return [];
130  }
131 }
__construct(ModuleDataSetupInterface $moduleDataSetup, EavSetupFactory $eavSetupFactory)