There are already several issues for improving the "Fields" tab (which has really horrible UX, of course), but I think there is now a consensus, more or less, to imitate Views' solution for this – only list the indexed fields and provide an "Add fields" button to add more. In a first step, this wouldn't even have to use a modal dialog, it could just be a normal form on a separate page, too. Changing it to a modal would just be polishing.
(I also don't know whether separate forms for our few settings for each field would make sense – probably not until we add more introspection to "Add fields" processors, and then this might still be incorporated into a single form much better.)
One thing that would be needed here, though, which probably isn't trivial, is a good way to add related fields. Probably some AJAX magic to load the related fields, up to arbitrary depths, on demand, also making the "additional fields" configuration for indexes unnecessary.
Estimated Value and Story Points
This issue was identified as a Beta Blocker for Drupal 8. We sat down and figured out the value proposition and amount of work (story points) for this issue.
Value and Story points are in the scale of fibonacci. Our minimum is 1, our maximum is 21. The higher, the more value or work a certain issue has.
Value : 13
Story Points: 21
Comment | File | Size | Author |
---|---|---|---|
#8 | 2574969-8--fields_aliases_and_ui.patch | 309.39 KB | drunken monkey |
Comments
Comment #2
drunken monkeyGonna work on this now, in conjunction with #2044287: Introduce field aliases. This is definitely gonna be a major change, so I guess better sooner than later.
Comment #3
Nick_vhComment #4
drunken monkeyOK, I've finally got a working version! Please see the attached small patch. (What's 300 kB in our age of terabyte HDDs?)
To summarize the more substantial changes:
$index->options['fields']
can now containlabel
,datasource_id
,property_path
,type
,boost
, indexed_locked,type_locked
andhidden
, and must contain the first four (exceptdatasource_id
for datasource-independent (processor-added) properties).PropertyInterface
is gone – since properties don't have a 1:[0-1] relationship to fields anymore marking them as "locked" or "hidden" makes even less sense now than it did before. Processors just add normal data definitions now and have a newpreIndexSave()
method now for forcing fields on an index.$index->getFields()
and do most of the same stuff as before. However, if you useUtility:[create|split]CombinedId()
with fields you are probably doing something wrong. (On the other hand, some of the code actually still does it, since it's a pretty handy way of getting a single string containing all the information about where to get a property from. I call it "combined property path" now – quite a mouthful, though.)OK, that all is done, and even all of the tests are passing locally.
However, there's still a lot of TODOs here, unfortunately – but I think we should move most of those into follow-up issues to have the basic new API ASAP and don't develop against the old one unnecessarily long.
Remaining TODOs are:
Only problem: it's not working. Like, not at all. And I don't have any idea why. However, since it's not at all critical I'd just leave it there for now and fix it in a follow-up (it's only in the UI, so it's not even really a beta blocker).
getOriginalId()
method to easily spot a change.Why am I bringing this up? Because even now, with this patch, the field's ID can be changed, so no-one can actually rely on a field with that field ID being present anyways. Especially, it makes the "Content access" processor potentially dangerous, since it now has no reliable way anymore to force the query to not return any results.
Long story short: we should add something like a
$query->dontReturnAnyResultsFromThis()
method. (There's something like it already in the Views query plugin, but it would make sense outside of Views, too.)OK, that's about it.
Once everyone (including the test bot) is happy and we have decided which of these should be done in follow-up issues (and fixed the others, of course), I'll commit here and create said follow-ups. (And, in doing the former, ruin everyone's current setup. Hohoho.)
Comment #7
borisson_I really like the
Index::addField
andIndex::removeField
methods, they make for an markable improvement in the rest of the code for readability. Very well done.I also like that you added static caching in some places, ++.
In this patch, a couple of new exceptions are thrown, I would however prefer to have more specific exceptions - this can be a followup though.
I read trough the patch twice but I will probably have missed a couple of things, this patch is massive and some of the diffs are really hard to follow.
This should probably go into #2268867: Review README.txt files.
You remove the
$keywords_field
here and replace it with a hardcoded string trough the test.While here, you just change the value of
$keywords_field
. Can we do one or the other?The diff for index is horrible, I'll probably miss half the changes in the red-green noise here :)
what does this do? Can we add a comment?
I think it'd make sense to move these methods next to each other, the
UpdateFieldsIndex
method in between confused me at first. Very, VERY minor though. ;)Should we note that this method is used recursively when the $fields variable contains an array?
Can we reword this comment? We're touching it anyway and I dislike the "Obviously" in there because at first it wasn't very obvious for me.
Is this better?
if this is so unlikely to happen, why do we even catch it? In what scenario can this happen and shouldn't we just let the exception trough if it does? It's not like this will happen when running, only when setting up an index, right?
The fields are not indexed before being added so I think the comment should clearly reflect that.
Provides a form for adding fields to a search index.
Dateformatter is the only service that can also be
null
.This is wrong, it's not an IndexFieldsForm. I'm starting to get in the habit of just writing
Constructs a new instance of the class.
to prevent just those kinds of mistakes, this is usually forgotten during refactors as well.This setter is never used, let's get rid of it.
DateFormatter is the only service that has this pattern, the other service getters just return $this->service. Is there a reason for that?
This setter is never used, let's get rid of it.
Can we use the
entity_type.manager
instead?This setter is never used, let's get rid of it.
I think we can replace the username here with a call to
$account->getDisplayName
. That way we shouldn't need the renderer.This setter is never used, let's get rid of it.
This looks weird and could use a reformatting.
Awesome comment.
Does this serve the same purpose as the
$indexId
? Should we add the same comment about __sleep / __wakeup?Can we remove the "(currently)" or add a link to an issue?
We can probably remove the parenthesis here.
This should probably be fixed in this patch.
/s/Link/link
Comment #8
drunken monkeyThanks for your review and comments, really awesome!
OK, let's do that.
updateFieldsIndex
was in between there previously because it's only ever used ingetCache()
, but I guess it still makes more sense to have those other methods grouped.We already do.
You're right, sorry, that does sound a bit conceited. I should be more careful about such wording.
I think this can only happen if it couldn't acquire a lock for the index, which I don't think is likely to happen ever, and especially not when you're deleting it. And we catch the exception because leaving that data in the temp store, in the worst case scenario, doesn't really do any harm either, so I don't think it's worth failing over.
Also, since the interface doesn't declare any thrown exceptions, we are technically not even allowed to let an exception escape from this method.
You're right, the current system doesn't make much sense. However, I think this was once in the coding standards, that's why I still always add the line like that.
But I just checked and it seems this is gone again from the standard. Also, #2140961: Allow constructor methods to omit docblocks wants to completely drop the line, so it might not be an issue at all in the future.
For now, I just corrected the line, though, to stay consistent within the module.
Ah, yes, thanks for catching that and all the other DI irregularities. I'm just used to the other DI pattern, using the setters in
create()
, so I slipped up a few times with this different system we use (for some reason – does anyone actually know?) for forms.I don't think so, since that just returns the stored name (or "Anonymous"), while I'm pretty certain the user name needs to be themed if it will be displayed to the user.
But actually, I don't really have an idea myself, that's just one more field in Drupal where there's simply too many ways to do something to know which is the right one. I just copied all of that code from the Views UI, so I'm gonna assume it's more or less correct.
No, the datasource ID actually has a getter and setter, that's a normal property.
No, it shouldn't, it's completely unrelated and was broken before. The difference is just that we previously explicitly asserted that it's still broken, which is of course nonsensical.
The attached patch fixes those and all your other comments, and should also fix the test fails.
Comment #9
drunken monkeyCreated #2640982: Fix "unsaved changes" code in the new Fields UI as one of the follow-ups (since I was able to solve it mostly, but then got stuck on kind of a circular dependency).
Comment #10
borisson_The new patch looks great and all my comments are resolved. Not sure what we should do about the comments you mentioned in #4.
Comment #12
drunken monkeyExcellent, great to hear! Test bot is happy, too – so let's do this!
Committed.
Thanks again for your great reviewing work here!
I'll create the follow-ups now.