Closed (fixed)
Project:
Drupal core
Version:
8.0.x-dev
Component:
base system
Priority:
Major
Category:
Task
Assigned:
Unassigned
Reporter:
Created:
10 Feb 2013 at 10:57 UTC
Updated:
29 Jul 2014 at 21:53 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
gábor hojtsyTagging for a bunch of other things.
Comment #2
smiletrl commentedThis looks good^^, here're some little concerns.
I guess a protected
createItem();is ok, since this function is going to interact with$list[$index]only, and that's a protected variable. So, a publiccreateItem();looks useless to me^And for
public function offsetGet($offset), is there use case to return non-existing items? Maybe it will confuse the user, sinceoffsetExists($offset)returns FALSE, whileoffsetGet($offset)could return something in this case. Perhaps, add Exists examination, in offsetGet()?For
'map' could be a little confusion, as this could relate to Google map, or sort of things. How about a simple 'ComplexData':)
Looks like we need extract
$entityto a generic complexdata too, and we will need tests for the two generic data type?Comment #3
fagoWell, without that you cannot create list item and then know it's delta what kind off sucks.
The regular use case for this is trying to access the first field item via $node->field->value what runs through $node->field[0]->value. Also, I think it makes the API easier to use as you do not have to check for unset objects before moving on - as it is the case for retrieved properties as well. Indeed our __isset() implementation there just checks for non-NULL values, what we should do here as well to be consistent.
Comment #4
fagoSo you'd suggest type "complex" and class name ComplexData ?
I'm not sure - "map" seems to be a common term for that, e.g. http://en.wikipedia.org/wiki/Map_%28disambiguation%29. Whereas complex vs simple types is usually more a categorization of data types only.
Comment #5
fagook, worked a bit more on this and added "any" and "map" data types as well. All untested and needs tests cases.
Comment #6
chx commentedhash?
Comment #7
berdirHash is a way to implement a map, not a separate thing? (HashMap implements Map in Java)
Comment #9
gábor hojtsyShould the goal of this patch include removing the Mapping and Sequence types in Config schema and making them work with these generic implementations? Those were introduced there due to the missing implementations in Typed Data, and the initiator for this issue was to migrate them to Typed Data :)
Comment #10
gábor hojtsyTests fail with exception 'Drupal\Core\Config\StorageException' with message 'Failed to write configuration file: sites/default/files/simpletest/379234/config_active/system.module.yml' in /var/lib/drupaltestbot/sites/default/files/checkout/core/lib/Drupal/Core/Config/FileStorage.php:102 does not seem to be related.
Comment #11
gábor hojtsy#5: d8_typed_data_structures.patch queued for re-testing.
Comment #13
dave reidI'm curious about a few things with this:
Comment #14
fagoYes, but this issue is needed for some other stuff as well, e.g. #1839080: Implement the new entity field API for the link field type or for the conditions API to support lists of strings. So I think we should only bake this clean-up into this patch if it's do-able rather quick, but postpone to a follow-up if not.
Well, using it when casting to strings was not the purpose of the method, but having an easy, explicit way to get a string representation of the data. I can see using __toString() has some advantages anyway though. This needs a change in the interface and some classes, so it deserves its own issue.
Good suggestion, thanks!
Well, this is just a simple way to get a string representation - it does not fit for generating customizable string tokens. I'd be happy to discuss how we could leverage typed data for token generation best though. Maybe, getString() could be extended to support multiple token formats - but I'm not sure formatting should be part of the core typed data API, I'd rather have a separate system relying on typed data for that? Maybe, we could just rely on the token API for the formatting part per data type, while the chaining part could be handled by the typed data API? Let's discuss this more over at #1869582: Leverage the Typed Data API for token replacements
Comment #15
fagook, I took a stab on that and completed the data types + added tests covering them (independently from existing entity field stuff).
I've not look into using this for config-schema stuff yet, else this should be complete. Please review!
Comment #16
fagoOps, I realized I forgot to take care of handling the special case of non-list values for entity field values again. Updated patch.
Comment #17
berdirI think you can define this in $this->defaults and then the default processDefinition() implementation is capable of merging that.
Comment #18
fagoIndeed. Typed definitions get cached so no need for micro-optimizing here - fixed that.
I also tried to see whether we can use the new classes for the config schema, but I've quickly seen that's not a simple undertacking but requires considerable more effort. Thus opened #1928868: Typed config incorrectly implements Typed Data interfaces for that.
Comment #19
fagoOh, above patch also had the start of #1928868: Typed config incorrectly implements Typed Data interfaces baked in - re-uploading the patch without that. The interdiff is correct.
Comment #20
fagoNoted the dedicated tests for the 'any' type were missing, added them.
Comment #21
berdirWe're just moving it around but while we do that, we should replace use for global classes with an inline \.
The implements IteratorAggregate can probably be removed now from Field, as it extends from ItemList. Unless you want to keep it for explicitly stating it?
There might als be some now unused use statements in Field.php
Unrelated: TypedData should really really be a DUBT or even plain unit test, the main reason it currently can't be seems to be that it relies on a create helper method that was added to WebTestBase ?!
If it where, then these long test methods could be rewritten into multiple methods so that it's easier to follow/review.
Comment #22
fagoThanks for the review. Attached patch takes care of the use statements and fixes the code to use \Exception style.
Totally, yep. I guess that instead of that helper we should have a TypedDataUnitTestBase or so. But let's clean that up in another issue.
Comment #23
fagoberdir pointed out on IRC that all use statements of global classes should not be used, not only exceptions. Thus re-rolled the patch accordingly.
Comment #24
fagoBut then, the same applies to maps - thus updated the patch to take care of that also.
Comment #25
dave reidAs stated before I believe this needs to use drupal_strlen() in order to support UTF-8 properly.
Comment #26
fagoAs discussed on IRC, changed it to use drupal_strlen() as we've Drupal-specific code below Core and thus should follow best-practices.
Updated patch attached.
Comment #27
berdirI think this is good to go.
The naming makes also sense IMHO, these are standard programming terms, Here's what Wikipedia says about "Map":
Setting this to major to raise awareness, this is a blocker for converting the link field type which is the last one that is not yet ready and therefore is this also blocking a critical meta issue.
Comment #28
dries commentedI was going to commit this patch but got an error:
The patch may require a reroll. Asking for a retest.
Comment #29
dries commented#26: d8_typed_data_structures.patch queued for re-testing.
Comment #30
webchickWorked here, for whatever reason, so!
Committed and pushed to 8.x. Thanks!
Comment #31
wim leersThis broke Edit.module's "edit/metadata" route.
That route now fatals with a "Unable to get a value with a non-numeric delta in a list", which is in
ItemList::offsetGet(). That route results in a call toEditController::metadata(), which does something super simple: iterate over the fields parameter it receives in the request, retrieve the corresponding metadata (this all still works just fine), and then callDrupal\edit\MetadataGenerator::generate(). There is this tidbit:The second line of the two now fails.
Note that this does have test coverage, at
Drupal\edit\Tests\MetadataGeneratorTest. However, that works with mock objects, and it seems those mock objects should have been updated by some other changeset, but haven't been? Or… what should I do?Comment #32
berdirI don't think that's related to this issue. The API didn't change.
What entity type and field type are you using?
Node is now NG so on nodes, you now get a Field class back, which means that you no longer access it with the langcode, it automatically uses the default. Instead, you have a Field class and can do something like $node->field->value or $node->field[0]->value or, in case of the EntityBCDecorator (which still returns the old structure back on $node->field) $node->get('field')->value.
You're probably the only one or almost only one that uses ->get() so it continues to work for everyone else thanks to the BCDecorator.
Ping me in IRC and I can help to sort this out.
Comment #33
berdirClosing this one again: #1942000: Node NG broke Edit module
Comment #34
wim leersYes, thanks, and sorry for not doing so myself.
Comment #35
gábor hojtsyOpened #1949916: Make use of general, any, list & map classes for configuration schema as a followup!