Cms: Allow users to change fieldtypes (with warning if need be)

Created on 19 Dec 2017  Â·  8Comments  Â·  Source: craftcms/cms

I, and a few others it seems like to create field types and set up fields/sections quickly when setting up a new Craft site. This would mean potentially changing field types after their creation.

I understand this can no longer be done with Craft 3. And I can understand why, but I think having the option to override this would be handy, maybe even if the field is empty, just simply allow it?

Most helpful comment

Maybe allow it if devMode is on, and keep the behavior of showing them disabled when devMode is off? Assume the developer knows what they are doing?

All 8 comments

Maybe allow it if devMode is on, and keep the behavior of showing them disabled when devMode is off? Assume the developer knows what they are doing?

Good shout @khalwat ! Like that idea.

I am probably going to sound conservative here, but sometimes that can be a virtue -- and to innovation (because then you are brought to invent better ways for what you thought you wanted).

Craft is very evidently gaining a large number of users with the coming release. Fewer of them will be skilled in the fine points. In fact this kind of request illustrates the problem: 'we just want to do it'.

I guess it seems very little effort at all to remove and replace a field definition, if you want to change its fundamental type. This is always entirely safe.

That's a benefit to those who think to do this, and it's a benefit to the Craft team, so that support is not burned up chasing unanticipated results.

The same would be true for developers of any plugins that manage fields, no?

I think this is a pretty good example of why it would be nice to be able to change the Field type — I have a site that I’m converting from Craft 2 -> Craft 3. The FocusPoint field type doesn’t exist anymore, I’m fine with that. But it won’t let me switch it to an Asset field

google chromescreensnapz906

I’m assuming that if I delete and re-add the Field, the content will be lost?

Using Craft CMS 3 RC3, I just hacked FieldsController.php (line 137) and Matrix.php (line 252) to add:

$enabled = true;

So that I can convert the field types to Assets — worked fine. In case anyone else runs into this...

@khalwat I'd been thinking I wanted to soften approach on this, just having a hard time....

That's a sort of good example, true, except it underlines the point that you really need to examine and be sure of what you're doing vs. the underlying data for the field. Even with somewhat like for like, it's not obvious that your FocusPoint->Asset conversion should work, or fully work, is it?

Even on text fields, Plain->Rich/Redactor/CKEdit may function, but the reverse won't well, while Redactor<-->CKEdit is definitely not fully compatible, especially as far as embeds are concerned, having tried it out on the prototype a bit ago.

Then you have fields with their own data storage, like Matrix, SuperTable, Neo, and no doubt many custom fields, which will entirely lose data if you try to substitute them.

In some ideal world, there'd be a cross-compatibility matrix, though it would mostly object, and would be pretty unworkable from a support point of view unless field purveyors tested and specified themselves where their efforts could be just substituted.

Looking at Chris's request, maybe allowing switch before there is data should be allowed as a convenience to initial sketches, but it doesn't seem it will help much for most real cases, where the data is there so that you surely care.

I suspect the real thing that would make field substitutions workable is the holy grail still being pursued, the data migration toolset, so you could push legacy data out, replace a field, and pull the data back in, converted to type, still with or without loss of function.

To make this workable with always freshly appearing types, there's likely going to need to be an easily-attached/plug-in data manipulation filter stage.

Just blue-skying a moment, I wonder what you think of, @Chrisedmo , when you say it would help if you could do this on empty fields? It makes me feel you're doing some kind of pre-development sketching, maybe because of the nice-looking gui on Craft's field manager.

Maybe there's an opportunity, to create a design tool which could allow dummying up project data schemas, which could be a nice add-on re-using some best current parts, and possibly doing work for you underneath, like creating the fields and adding them to sections, as they are finally worked out?

Such an FR or co-project might answer some of the other requests for easy early stages, perhaps?

Well @narration-sd in this case, I know that it's okay to do the conversion, because FocalPoint is a subclass of Assets.

Which I guess is really the point... if I really do know what I'm doing, let me do it. I understand the reason for including safeguards, but there should be some way to bypass them when you're sure (or pretty sure!) you know what you're doing, other than hacking core.

Yes, that's what I meant by 'somewhat like for like'. And I think you'd have to admit you're somewhat of a special case, Andrew, who really would appreciate the ins and outs of such a subclass/equivalent situation.

I do appreciate that none of us want to hack core (if amused how you've done it where such can be hands-off...), nor especially encourage the broad community to do so, not at all.

The suggestion to allow substitutes on devMode possibly shows a better opportunity, though.

devMode as-is probably shouldn't be the key to the lock, because persons are encouraged to use it often either to see accurate enough error indication when scripting for instance, or to engage deeper logging for similar or to be sent in for support.

Since we don't have time-outable configuration, maybe a second flag, e.g. expertMode, could do the trick, if it flashes up an unforgettable warning motif -- half-centimeter high, bright red hashes this time?? --- so that you wouldn't be tempted to leave it engaged. This flag could be used for other requires-knowledge temporary core function bypasses, in future as well.

I still like the idea of future tools as mentioned clearing up such foggy spots as field changes, and maybe if useful putting the Craft nice content modeling ux into broader use....

Was this page helpful?
0 / 5 - 0 ratings