Background

Identifier Assignment Plugins are designed to generate Identifiers for supported entities. Not all plugins need to support al entities.

Entry Point Models

Each Entry Point model for Identifier Assignment plugins will be made available when a new Identifier Assignment is instantiated. The corresponding controller should extend StandardPluginController, and implement an edit-only fields.inc.

assign()

The Entry Point Model must implement an assign() function with the following signature:

public function assign(
  \App\Model\Entity\IdentifierAssignment $ia,
  object $entity
): string

where

  • ia: The IdentifierAssignment configuration associated with the request
  • entity: The entity for which the Identifier is to be assigned, and including the Primary Name for People

The return value is the newly generated Identifier.

The plugin may throw an InvalidArgumentException if it does not support the requested entity type, or a RuntimeException if it is unable to assign an Identifier.

The plugin is not responsible for verifying the availability of the generated Identifier (the calling code will handle that), but it may wish to do so in order to generate an alternate option if the initial choice is in use. Availability may be examined via IdentifierAssignmentsTable::checkAvailability(). The plugin should not persist the Identifier to the database.

assign() will be called within a transaction. Plugin queries that are dependent on preserving database state during the assignment operation should use SELECT ... FOR UPDATE to obtain a read lock, which can be requested by appending ->epilog('FOR UPDATE') to a Cake find().

Example

// $plugin/src/config/plugin.json
 
{
  "types": {
    "assigner": [
      "RandomAssigners"
    ]
  }
}
 
// $plugin/src/Model/Table/RandomAssignersTable.php
  
namespace RandomAssigner\Model\Table;
   
class RandomAssignersTable extends Table {
  public function assign(
    \App\Model\Entity\IdentifierAssignment $ia,
    object $entity
  ): string {
    return $this->myRandomAssignmentFunction($entity);
  }
}

See Also

  • No labels