Problem/Motivation

When going to "/subscription-management-service/sync-user/[user-id]" the following error will appear:

InvalidArgumentException: Field field_subman_external_id is unknown.

Having a look in the README, apparently the user field has to be created manually. This should be done automatically on installation

* Ensure the field user.field_subman_external_id exists as type text (plain).
* Ensure the field user.field_subman_sync exists as type text (plain, long).

Steps to reproduce

Proposed resolution

Automatically create both fields on the user on installation.

Remaining tasks

User interface changes

API changes

Data model changes

Issue fork subman-3366167

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

Grevil created an issue. See original summary.

anybody’s picture

@Grevil: Thanks, I totally agree with the auto-creation, especially because also the machine name of the field is hard-coded. Otherwise, it should be done the other way around as a setting, where you can select the appropriate field, but I think hard-coding the name is okay for this special case in the module.

Installation of the field should be simple by creating the field and putting the config export into the install directory (after UUID etc. cleanup).

The steps should be removed from the README then.

anybody’s picture

Assigned: Unassigned » grevil

Go for it, should be simple using drush cex
Sadly drush decided against a uuid removal option: https://github.com/drush-ops/drush/issues/3468

grevil’s picture

Status: Active » Needs review

Done, please review!

anybody’s picture

Assigned: grevil » Unassigned

Okay, the code is ready for test now, I made the fields locked and dependent on the subman module.

The field_subman_sync isn't really clear to me. I guess it's a kind of user data storage, but we should have a closer look, what it does. If it's clear for example, that it will always store JSON content, it might be better to introduce a dependency on https://www.drupal.org/project/json_field and use a JSON field, instead of a string. Once #3343634: Add "json" as core data type to Schema and Database API is solved, we might use JSON as core data type.

Also it might be discussable if a field is the right choice here, or if it should better use User Data:
https://www.webomelette.com/storing-user-data-such-preferences-drupal-8-...

grevil’s picture

Status: Needs review » Needs work

Indeed @Anybody, the field is used to store json data.

This is done through "storeSyncData()" inside "/src/SubmanSync.php":

  /**
   * Save sync data into field on subscriber.
   *
   * @param \Drupal\Core\Entity\ContentEntityBase $subscriber
   *   The subscriber.
   * @param array $sync
   *   The sync data.
   */
  public function storeSyncData(ContentEntityBase $subscriber, array $sync = []) {
    if ($subscriber->hasField(self::FIELDNAME_SYNC)) {
      $sync[self::DATA_KEY_TIMESTAMP] = $this->utils->getRequestTime();
      $sync = json_encode($sync, JSON_PRETTY_PRINT);
      $subscriber->set(self::FIELDNAME_SYNC, $sync);
    }
  }

Let's implement it and add the dependency as said in #6.

grevil’s picture

Status: Needs work » Needs review

Alright, done! The type of the fields isn't checked anywhere, and accessing "/subscription-management-service/sync-user/1" does not throw any errors! Please review!

anybody’s picture

@Grevil: Are both fields present as expected in the UI?

anybody’s picture

Status: Needs review » Reviewed & tested by the community

Well done, RTBC!

  • Anybody committed 16004087 on 1.0.x authored by Grevil
    Issue #3366167 by Grevil, Anybody: Field "field_subman_external_id" is...
anybody’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

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