| Comment | File | Size | Author |
|---|---|---|---|
| #20 | link-field-type-1839080-20.patch | 8.51 KB | berdir |
| #20 | link-field-type-1839080-20-interdiff.txt | 3.12 KB | berdir |
| #18 | link-field-type-1839080-18.patch | 8.53 KB | jjchinquist |
| #17 | d8_map_fixes.patch | 3.46 KB | fago |
| #16 | d8_map_fixes.patch | 3.45 KB | fago |
Comments
Comment #1
dasjoComment #2
dasjocouldn't finish this patch today, but here's my intermediate results.
added an Unknown type for the serialized link attributes.
basically this is missing a LinkItemTest
Comment #3
berdirSounds to me like 'Serialized array of attributes for the link.' defines this quite clearly as a (serialized) array. So why Unknown?
Comment #4
berdirTagging to lure @fago's in here :)
Comment #5
fagoWell, it's unknown what is in there, right? I think having a 'unknown' type is useful for any situation where you prefer to not keep describing your data structure, e.g. think of deeply nested CMI-structures.
However, we could still be more specific, e.g. introduce an attributes type and class which properly implements the ComplexDataInterface at run-time. Still, the property-definitions returned without data would have to be empty.
Comment #6
smiletrl commented@fago, I'm trying to build an Attribute typed data, which lives in link module lib directory. As you suggested, a class implementing ComplexDataInterface could be a good idea. Here's what I've figured out, an outline of what the class could look like. Future contrib modules could extend this Attribute class.
My concern is with the child interfaces in the nested cass structure. For instance,
Should another new class implement ListInterface to represent
$attribute->get('class')? E.g.,Because right now, I'm creating a class to represent
$attribute, but the following property, item seem to don't have such a proper class.I guess I can't say each property lives only with interface. The property should live with actual class?
If the answer is yes, then this issue seems need more work. I'm not sure I'm on the right way. Any ideas? Thanks:)
Comment #7
smiletrl commentedAlso, I'm thinking the document inside following is confusing.
At least for entity property, it's not the case. It returns ListInterface, like
Comment #8
fagoNo it is the case. The list also implements the TypedDataInterface.
Yep, we'd another another class to represent the list classes. For that we'd need a generic list class, such that we can properly represent a list of strings. Thus, I think we should better take care of #1913328: Provide general list and map classes before this as we can use the generic map class also as base for the attributes class (or just that).
Comment #9
amateescu commentedMarking as postponed on #1913328: Provide general list and map classes.
Comment #10
berdirThat went in, working on this.
Comment #11
berdirOk, here is a mostly working patch. Contains working tests, experienced some strange issues there however. will review my own patch in the next comment to point them out.
Comment #12
berdirSo, the problem is that $field->attributes returns the getValue() representation of the attributes, which is an array that you can't change. So you can only read it from that but not write anything into it.
Second, set('something', $bla) doesn't work on not-yet-existing properies, because it does a get() internally. Also, it currently doesn't seem to work at all, see the second snippet, which does not give me an array but also does not change the value.
Comment #13
fago+ //$entity->field_test->get('attributes')->set('class', $new_class);
Yes, this works only if there is already a 'class' key in the map. I must say having a map without any metadata is a bit weird and I was not really sure how to implement the class best. So right now it works only from a pre-defined array as good as it can and tries to produce the metadata from there. As you noted, that does not work for creating new items. I agree that it should work that way, so I suppose it should just eat what it gets and live with that.
That said, let's fix the Map class such that set() just creates a new value.
Comment #14
jjchinquisttested manually, the patch for #11 functions correctly
Comment #15
berdirUpdated patch that fixes set().
Setting $this->values has two effects, one that I understand and another one that I don't.
a) It makes sure that getPropertyDefinitions() returns it, then get() works.
b) It fixes updates. First I only did that conditionally but then I noticed that the set() on existing values that already have a defined property class in $this->properties. Not sure why this is necessary?
Comment #16
fagook, here is a patch for fixing the Map class and adding test-coverage for that. It's not complete yet as the change has still one fail in the map class.
Comment #17
fagoUpdated #16 with a correction for the one test-fail.
Comment #18
jjchinquistlets see if this does it.
Comment #19
das-peter commentedGenerally this looks good to me, however a re-roll is necessary because
FieldItemUnitTestBasehas becomeFieldUnitTestBase. And I found some nit-picky stuff too.This should be
FieldUnitTestBasenow.Create a link field... maybe?Same here
link fieldI guess.How about
Create entity.? The verification happens below and has its own comment already.Sounds a bit odd, shouldn't it be something like
Verify the field value is changed.?Should be
Contains \Drupal\link\Type\LinkItem., as far as I know.'link_field'?Comment #20
berdirThanks for the review, re-rolled and fixed those comments I think.
Comment #21
das-peter commentedI can't find anything else that needs to be done here -> RTBC
Comment #22
fagoYep, I agree this is ready.
Comment #23
catchCommitted/pushed to 8.x, thanks!
I think we're down to one of these now.
Comment #24
jjchinquistCongrats! Keep up the great work and thanks.