Currently, adding new fields is a kind of second-class operation, half living in alterProperties(), half in preprocessIndexItems(), and not really reflected in the UI in any kind, or aided by the framework (beyond providing these methods).
I propose (at least for discussion) making this first-class, in the sense that processors like "URL Field" or "Rendered Item" would define themselves as just adding an optional field to the index, nothing more. (Same for "Aggregated fields", but that's a much more complicated subject because it's a configurable number of fields, each with its own configuration.) There would then be a method just for getting that field's values for a certain item, which the index would call automatically. Views could more easily display such computed properties (which should properly be marked as such, of course), and the enabling (and possible configuration) of those processors could move to the "Fields" tab (especially in combination with #2574969: Add a Views-like UI for adding fields), hiding them from the "Processors" tab (unless they also work at other stages).
However, I think it should also be possible to add fields with the current, more "hidden" way, since I don't think users will understand why the "Content access" processor has to be added on the "Fields" tab.
And, as said, incorporating the "Aggregated fields" processor into this plan would of course be quite a challenge. Having this actually work like any other "Add field" operation would of course be a huge win, usability-wise, but it will have to remain to be seen whether we can manage that (#2044287: Introduce field aliases would help a lot, I guess).
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 : 5
Story Points: 8
| Comment | File | Size | Author |
|---|---|---|---|
| #24 | 2575003-24--processor_properties.patch | 159.4 KB | drunken monkey |
Comments
Comment #2
nick_vhComment #3
borisson_Should we postpone this issue on #2574969: Add a Views-like UI for adding fields? I think we should.
Comment #4
drunken monkeyYes, definitely.
Comment #5
drunken monkeyMight be I'll implement it together with #2574969: Add a Views-like UI for adding fields, so assigning to myself, too.
Comment #6
drunken monkeyDid not get implemented together with #2574969: Add a Views-like UI for adding fields, but since that's committed now this issue is not postponed anymore.
Comment #7
drunken monkeyTackling this now.
Attached is a first-step patch which reproduces the current functionality in a slightly different way, to make it easier to build on.
Next steps: define new kind of data definitions that show which processor they belong to, make it possible for them to have configuration, have a separate method on the processor for providing data for one of its properties, etc.
Comment #8
drunken monkeyStep two: Properties are explicitly linked to the processor that defines them and
addFieldValues($item)can/should be used to provide associated field values.Not completely sure about that method, though – this version keeps the code working more or less exactly the same as before, and especially allows processors like "Aggregated fields" to use synergies across multiple fields – on the other hand, though, it's much more awkward if you just want a single property's values for some other reason than indexing (since you have to construct a dummy object for that).
So, that might still change slightly. (Suggestions also welcome.)
Next step: make it possible for fields to have settings (based on their property).
Final step afterwards: integrate this into the UI as smoothly as possible. (Luckily, I'm a renowned UI expert.)
Comment #11
drunken monkeyNext try.
Comment #13
drunken monkeyOK, container rebuilds apparently cause more problems than they solve. (Couldn't reproduce the test fail locally, though, and it's also weird that the other environment passes – but random fails would be just as bad as normal ones, if not worse.)
So, second try, circumventing the Field UI entirely.
Comment #14
borisson_I quickly went trough the latest interdiff - I did see one thing. I like that there are less random fails now that we removed the container rebuilds.
We should remove this debug statement.
I have more time to look at this later today/tomorrow.
Comment #15
borisson_Overall, I think this patch looks great, this makes the processors that add fields much simpler.
Can this happen? I know it was in the previous processor as well but I still don't understand it.
Since we're refactoring this processor anyway, can we inject the database service instead? We could open a followup as well I guess.
Nice, this makes sense!
Comment #16
drunken monkeyYes, it can – e.g., with a buggy datasource, or with someone overriding the processor.
Not very realistic, true, but if the method can return
NULL(just code-wise, not logic-wise), I'd say it's good practice to check for it. And it doesn't really cost us anything.And avoids yellow squiggly lines in PhpStorm!
(Or, rather, it should. But no, PhpStorm is still positive that
$accountis aQueryInterfaceobject. Huh.)Comment #17
joachim commented> And, as said, incorporating the "Aggregated fields" processor into this plan would of course be quite a challenge
I was thinking that you could have a new plugin type for index fields, and OOTB have 'normal' and 'aggregated'.
Comment #18
drunken monkeyNext step, passes all tests locally (and fixes Joris' comments).
Now only the UI to be done, as far as I can see.
Comment #19
borisson_This patch has become really hard to review, does it make the patch smaller to use
git diff -M?I did find 2 things in the tests, but overall from what I can see, this is looking great. Thanks for the answers in #16, I understand that now.
What exactly still needs to happen here? Can we link to an issue or should this be done in this patch?
We should fix this in this issue as well?
Comment #20
borisson_I spent some time sitting in the car waiting, so I looked trough the patch again.
Should we remove this blank line? That makes it clearer that the comment belongs to the definition.
I like this, makes it clearer!
can we make this extend field_processors_configuration instead? Less lines of code!
Let's remove this blank line as well.
Do we really need to do this twice? I'd think that this is only needed in the preSave? Not sure though.
Comment #21
drunken monkeyNo, doesn't change anything, unfortunately. The problem is that the code from one class got split into two in several cases – no good way of expressing that in a diff.
Both cases you point out were just temporary notes for me, for what still needs to be done. I'd never use
#for a "real" comment. But thanks for reminding me!Most of your other finds are spot-on, though. As always: thanks a lot!
I disagree in this case, since the comment is a "heading" for all three definitions underneath.
That could lead to problems if someone was accessing a newly created index's configuration before it is saved. Unlikely, but not completely implausible.
I'd think just doing it in
postCreate()might be the better option, if we're gonna drop one – after creation, there should be no point at which those settings get removed again. We can do that, if you want.I just opted for extra safety here, but possibly went a bit too far.
The attached patch would be RTBC in my opinion, unless I've overlooked something.
Comment #24
drunken monkeyI have not the smallest trace of a clue why, but for some reason in this one instance the double quote character (") doesn't get escaped. What the heck is going on …
Just took the easy way out now, like the Beatles recommended.
Comment #25
borisson_woo.
Comment #27
drunken monkeyExcellent, thanks for reviewing!
Committed.
Comment #28
joachim commentedThis breaks existing search indexes -- or at least I assume it's this:
> Drupal\search_api\SearchApiException: Could not retrieve data definition for field 'Foo - aggregated' on index 'My index'. in Drupal\search_api\Item\Field->getDataDefinition() (line 369 of modules/search_api/src/Item/Field.php).
I know this is still in alpha, so it's my problem :) but tips on upgrading would be useful.
Comment #29
joachim commentedBig improvement to the UI for aggregated fields BTW :)
Comment #30
joachim commentedOk so got it working. Your existing search index configuration will need hacking by hand in the exported YML file then reimporting:
1. Find the settings for the aggregated_field processor, eg:
2. Remove the whole of the 'fields' property from this, but pasting it to another file.
3. For each aggregated field, find it in the main fields list:
4. Change the property_path to be 'aggregated_field'
5. Remove the indexed_locked property
6. Add a configuration property
7. Paste into the configuration property the type and fields properties from the stuff you removed from the processor in step 2.
End result should be like:
There are a few other changes to the config array, but saving the Processors form will take care of those.
Comment #31
audriusb commentedthanks @joachim!
Comment #33
mpp commentedCould someone update the documentation on https://www.drupal.org/node/2715959?
Comment #34
csedax90 commentedSorry, someone can update the documentation or explain here what the new procedure to add custom fields?