I've made several custom modules for i.e. adding attributes to categories. This is all the first time for me, so I set up the module the first time, enabled it and all is fine so far.
But when I go back to make changes in the code, I don't see them happening (and I'm talking about changing the text in a label, so it should be visible). I figured it has to do something with the way the module is implemented, so I tried;
- Disabling/Enabling the module
- Clearing cache / var/ folder
- Running
setup:static-content:deploy
- Running
setup:upgrade
- Running
setup:db-schema:upgrade
andsetup:db-data:upgrade
- Changing the module version in module.xml from 1.0.0 to 1.0.1
- Running
indexer:reindex
But still I don't see my changes in the module. What must I do to 'apply' the changes in a module?
For the creation of an attribute, I use a Setup/InstallData.php
file. Could it be the data is setup once, and doesn't get "refreshed" with an edit? What would be the best way to go around this (maybe changing the name, deleting in the DB)?
edit: I've now also changed the field-id and redid all steps above, still to no avail :/
update: this is the tutorial I used to get where I am; http://www.ibnab.com/en/blog/magento-2/magento-2-add-custom-eav-attribute-to-category-or-customer
And to test it, at first I created a text-field as attribute. That works, now I want to change it to a media-field (like a second category image field). This is the (part of) code in question ( Setup/InstallData.php
):
$categorySetup->removeAttribute(\Magento\Catalog\Model\Category::ENTITY, 'cat_bgimg1');
$categorySetup->addAttribute(
\Magento\Catalog\Model\Category::ENTITY, 'cat_bgimg1', [
'type' => 'file',
'label' => 'Category backgroundimage',
'input' => 'file',
'source' => '',
'visible_on_front' => true,
'required' => false,
'sort_order' => 100,
'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_STORE,
'group' => 'General Information',
]
Update
To try to force the changes I disabled the module, I updated module.xml
to 1.0.1 <module name="MyModule" setup_version="1.0.1">
and re-enabled the module, ran setup:upgrade
etc. In the database table setup_module
the new version was added, but the changes in code weren't applied. Maybe this is due me only having an InstallData script, and no updatescript.
Update 3 lord_of_strings gave me the right info on how this works and why it works like this. I ended up just clearing everything out and adding it again.