kongondo Posted November 30, 2020 Share Posted November 30, 2020 Hi, Could someone please show me how to create a new file or image field using the API and enable tags as well? It used to work a while back but I am not sure what changed. It seems I can only enable tags using the GUI and only once the field has been added to a template. In addition, it seems one has to do it twice; First enable tag, then disable them then re-enable them! I am talking about normal tags (user enters tags by text input). <?php namespace ProcessWire; $f = new Field(); // ... more code here $f->useTags = 1;// does not work, even if I do this after adding this field to a template $f->save(); Relevant method in FieldtypeFile.module: updateDatabaseSchema() Edit: Just updating this. The above code will look like it works. The field will save the setting use tags. However, the field's table will not be altered, i.e. the column 'tags' will not be created. Editing a page that uses that field will throw a PDO error: unknown column field_your_field_name.tags in field list. Thanks. Link to comment Share on other sites More sharing options...
adrian Posted November 30, 2020 Share Posted November 30, 2020 I didn't try creating a new field, but I altered an existing one by visiting the field settings and using this in the Tracy console: $field->useTags = 1; $field->save(); and it worked as expected. Also, just in case you didn't notice (I am sure you did), the options are 0, 1, 8, 9 Link to comment Share on other sites More sharing options...
kongondo Posted November 30, 2020 Author Share Posted November 30, 2020 11 minutes ago, adrian said: and it worked as expected. Thanks to testing. I forgot to mention, it will look like it works but it doesn't. The setting is saved for the field, however, the database is not altered. A new column 'tags' is not created. In fact, if you edit a page using your field, you should get a PDO error about unknown column field_your_field_name.tags in field list ?. Link to comment Share on other sites More sharing options...
adrian Posted November 30, 2020 Share Posted November 30, 2020 New field (created via GUI) without tags: Then apply: $field->useTags = 1; $field->save(); but nothing happens yet. But then reload the field settings page in the admin and now it looks correct: so it seems like the updating of the DB schema doesn't happen on save(), but rather when the field is loaded. My guess would be that this behavior was broken when Ryan added the new custom image fields a while back. 1 Link to comment Share on other sites More sharing options...
kongondo Posted November 30, 2020 Author Share Posted November 30, 2020 1 minute ago, adrian said: when Ryan added the new custom image fields a while back. That has been my guess as well. 2 minutes ago, adrian said: But then reload the field settings page in the admin and now it looks correct: That was my observation as well, only difference being I was saving (like twice) before it would catch. Link to comment Share on other sites More sharing options...
kongondo Posted November 30, 2020 Author Share Posted November 30, 2020 Can call this a bug then? It broke Media Manager, btw. Link to comment Share on other sites More sharing options...
adrian Posted November 30, 2020 Share Posted November 30, 2020 4 minutes ago, kongondo said: Can call this a bug then? Yeah, I think so for sure. Link to comment Share on other sites More sharing options...
kongondo Posted December 3, 2020 Author Share Posted December 3, 2020 Filed an issue here: https://github.com/processwire/processwire-issues/issues/1287 1 Link to comment Share on other sites More sharing options...
adrian Posted December 3, 2020 Share Posted December 3, 2020 The multiple save issue that you brought up reminds me of the way ProfieldsTable works - you need to save the field settings twice in order for a field order change to stick. Link to comment Share on other sites More sharing options...
kongondo Posted December 3, 2020 Author Share Posted December 3, 2020 1 hour ago, adrian said: The multiple save issue that you brought up reminds me of the way ProfieldsTable works - you need to save the field settings twice in order for a field order change to stick. Interesting. Today even saving twice didn't work for me. I had to do it about 7 times! Link to comment Share on other sites More sharing options...
kongondo Posted December 5, 2020 Author Share Posted December 5, 2020 @adrian I think I have managed to resolve the issue in my case. I was using setImportData() to create the file/image fields and my import data contained a fileSchema declaration (set at 7). Removing that entry resolved the issue. I tested on a new install, creating the field using the GUI, using the API (non setImportData() usual method) as well as using setImportData(). I was only able to reproduce the issue as I mention above. I have closed the bug report but please let us know if you are still seeing the issue. Thanks. Link to comment Share on other sites More sharing options...
adrian Posted December 5, 2020 Share Posted December 5, 2020 @kongondo - not sure what happened here. I actually just had to reset my sandbox install (mysql issue when upgrading to PHP 8) and now everything seems to be working fine with the example I posted above. I get the feeling this issue might appear again in certain circumstances but not sure how to reproduce at the moment. Link to comment Share on other sites More sharing options...
Confluent Design Posted February 5, 2021 Share Posted February 5, 2021 (edited) Hi @kongondo, We're using Media Manager and are encountering this error. I have reviewed the comments here and the bug report, but it's not clear to me how as a user of Media Manager, I can solve or work around this issue. Edit: I found https://mediamanager.kongondo.com/troubleshooting/ Is this the appropriate workaround for this issue? Thanks, David Edited February 5, 2021 by Confluent Design Link to comment Share on other sites More sharing options...
kongondo Posted February 8, 2021 Author Share Posted February 8, 2021 On 2/5/2021 at 6:02 PM, Confluent Design said: Hi @kongondo, We're using Media Manager and are encountering this error. Hi @Confluent Design, This issue has already been fixed in Media Manager. Re-download Media Manager and copy over your current install. Please let me know if you still need help. Thanks. 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now