eavSetupFactory = $eavSetupFactory; $this->categorySetupFactory = $categorySetupFactory; } /** * {@inheritdoc} */ public function upgrade( ModuleDataSetupInterface $setup, ModuleContextInterface $context ) { $setup->startSetup(); $this->applyUpgradeFunctions($setup, $context); $setup->endSetup(); } private function applyUpgradeFunctions(ModuleDataSetupInterface $setup, ModuleContextInterface $context) { $methods = $this->getUpgradeFunctions($context->getVersion()); foreach ($methods as $method) { call_user_func_array([$this, $method], [$setup, $context]); } } private function getUpgradeFunctions($low_version = '0.1.0') { $methods = get_class_methods($this); foreach ($methods as $key => $method) { if (preg_match('/^upgrade_(.+)$/i', $method, $matches)) { if (version_compare($low_version, $matches[1], '<')) { continue; } } unset($methods[$key]); } $methods = array_filter($methods); $methods = array_unique($methods); sort($methods); return $methods; } public function upgrade_0_2_0(ModuleDataSetupInterface $setup, ModuleContextInterface $context) { $tableFields = [ Category::ENTITY => [ 'ox_mm_lvl2_align_vertical' => [ 'type' => 'text', 'label' => 'Mega Menu in Dropdown Behavior', 'input' => 'select', 'source' => MmLvl2AlignVertical::class, 'required' => false, 'sort_order' => 71, 'global' => ScopedAttributeInterface::SCOPE_STORE, 'group' => 'Mega menu', 'default' => '', 'note' => 'For 2st-level category megamenu only' ], ], ]; $eavSetup = $this->eavSetupFactory->create(['setup' => $setup]); $categorySetup = $this->categorySetupFactory->create(['setup' => $setup]); foreach ($tableFields as $entity => $fields) { foreach ($fields as $key => $value) { if (Category::ENTITY == $entity) { $categorySetup->addAttribute($entity, $key, $value); } else { $eavSetup->addAttribute($entity, $key, $value); } } } } }