Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding expandEntityBaseFields() method. #114

Merged
merged 3 commits into from
Mar 16, 2018

Conversation

grasmash
Copy link
Contributor

@grasmash grasmash commented Nov 7, 2016

This pull request allows expansion of base fields on entities. In Drupal 8, base fields use the same field types as user-defined fields. E.g., a custom entity may define an entity reference field as a base field. Without this PR, there is no mechanism for expanding such fields.

Example usage:

      /** @var Drupal8 $d8_core */
      $d8_core = $this->getDriver()->getCore();
      $entity = (object) $row;
      $base_fields = [
        'licensed_entity',
        'user_id',
      ];
      $d8_core->expandEntityBaseFields('license', $entity, $base_fields);
      $d8_core->entityCreate('license', $entity);

This would expand the licensed_entity and user_id base fields using the EntityReferenceHandler class.

This pull request also documents a couple of undocumented parameters and fixes a bug that prevented user entity values from being expanded on entity reference fields.

* @param array $base_fields
* Base fields to be expanded in addition to user defined fields.
*/
public function expandEntityBaseFields($entity_type, \stdClass $entity, $base_fields) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This new method is public. expandEntityFields() cannot be used for custom entities because it is protected.

@grasmash grasmash force-pushed the expand-base-fields branch from 31b53ea to 50f2c18 Compare June 23, 2017 14:32
@jhedstrom jhedstrom added this to the 2.0 milestone Mar 16, 2018
@jhedstrom jhedstrom merged commit fae35a4 into jhedstrom:master Mar 16, 2018
@jhedstrom
Copy link
Owner

Sorry for the delay. This is merged now. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants