https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21TypedData...

$configuration['name'] and $configuration['parent'] are not optional because they are used unconditionally in TypedDataManager::createInstance(). So omitting these options causes 'Undefined index' notices.

$typed_data = $class::createInstance($data_definition, $configuration['name'], $configuration['parent']);
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Chi created an issue. See original summary.

Chi’s picture

Status: Active » Needs review
FileSize
1002 bytes
Chi’s picture

Issue tags: +Documentation
Chi’s picture

FileSize
1.17 KB

Fixed wrapping.

chx’s picture

Priority: Minor » Normal
Status: Needs review » Reviewed & tested by the community

Oh nice!

jordanpagewhite’s picture

It looks like the only call to TypedDataManager::createInstance() is TypedDataManager::create, which sets passes NULL to configuration['name'] and configuration['parent'] by default. So, it seems like passing 'name' and 'parent' is still technically optional, but I do think that this is confusing. At the very least, maybe we can add 'Set to NULL by default' at the end of each of those two lines. We could even add a @see Drupal\Core\TypedData\TypedDataManager::create . What do you think?

chx’s picture

Status: Reviewed & tested by the community » Needs work

So yeah, this is confusing , we should add "can be NULL but must be set" or something to that effect.

hussainweb’s picture

Status: Needs work » Needs review
FileSize
1.38 KB
1.4 KB

How about this? I changed the sentence order to make the text flow.

chx’s picture

Status: Needs review » Reviewed & tested by the community

I like it.

jordanpagewhite’s picture

I'm still not sure that this is the most accurate description of the current state of the code. What would happen if someone didn't pass ['name'] or ['parent']? Unless I am misunderstanding, it seems like (since createInstance is only called by create) that everything would be fine since $name = NULL and $parent = NULL in the create method declaration. If I am misunderstanding, I would really like to know though. I am trying to better understand core so I can be a valuable contributor.

I'm also wondering if it was an architectural decision to only call createInstance in the create method.

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

@jordanpagewhite if createInstance is called from somewhere else then 'name' and 'parent' must exist - this patch is just documenting that.

We could argue that we're redefining a public API here but I think it is better that documentation is correct rather then worrying about the semantics of semver in this instance. Committed 88233eb and pushed to 8.0.x and 8.1.x. Thanks!

  • alexpott committed 17bc367 on 8.1.x
    Issue #2592213 by Chi, hussainweb: The documentation for...

  • alexpott committed 88233eb on
    Issue #2592213 by Chi, hussainweb: The documentation for...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.