Commit 3cecaaea authored by Bogdan Dziewierz's avatar Bogdan Dziewierz
Browse files

Added workflow states

parent f3719115
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -6,3 +6,4 @@ core_version_requirement: ^10 || ^11
dependencies:
  - address
  - inline_entity_form
  - state_machine
+5 −0
Original line number Diff line number Diff line
kyc:
  label: KYC
  entity_type:
    - kyc_business
    - kyc_person

kyc.workflows.yml

0 → 100644
+32 −0
Original line number Diff line number Diff line
kyc_default:
  id: kyc_default
  group: kyc
  label: 'Default'
  states:
    draft:
      label: Draft
    awaiting_verification:
      label: Awaiting verification
    in_progress:
      label: Verification in progress
    verified:
      label: Verified
    failed_verification:
      label: Failed verification
  transitions:
    submit:
      label: 'Submit'
      from: [draft]
      to: awaiting_verification
    start_verification:
      label: 'Start verification'
      from: [awaiting_verification]
      to: in_progress
    verify:
      label: 'Verify'
      from: [in_progress]
      to: verified
    fail:
      label: 'Fail verification'
      from: [in_progress]
      to: draft
+68 −1
Original line number Diff line number Diff line
@@ -183,6 +183,11 @@ class Business extends ContentEntityBase implements BusinessInterface {
      ->setLabel(t('Type'))
      ->setDescription(t('The business type.'))
      ->setSetting('target_type', 'kyc_business_type')
      ->setDisplayConfigurable('view', TRUE)
      ->setDisplayOptions('view', [
        'type' => 'string',
        'weight' => 0,
      ])
      ->setReadOnly(TRUE);

    $fields['uid']
@@ -191,6 +196,23 @@ class Business extends ContentEntityBase implements BusinessInterface {
      ->setDisplayConfigurable('view', TRUE)
      ->setDisplayConfigurable('form', TRUE);

    $fields['state'] = BaseFieldDefinition::create('state')
      ->setLabel(t('State'))
      ->setDescription(t('Verification state.'))
      ->setRequired(TRUE)
      ->setSetting('max_length', 255)
      ->setDisplayOptions('form', [
        'type' => 'list_default',
        'weight' => 0,
      ])
      ->setDisplayOptions('view', [
        'label' => 'hidden',
        'type' => 'list_default',
        'weight' => 0,
      ])
      ->setDisplayConfigurable('view', TRUE)
      ->setSetting('workflow_callback', ['\Drupal\kyc\Entity\Business', 'getWorkflowId']);

    $fields['name'] = BaseFieldDefinition::create('string')
      ->setLabel(t('Name'))
      ->setDescription(t('Business\' registered name.'))
@@ -203,6 +225,10 @@ class Business extends ContentEntityBase implements BusinessInterface {
        'type' => 'string_textfield',
        'weight' => 0,
      ])
      ->setDisplayOptions('view', [
        'type' => 'string',
        'weight' => 0,
      ])
      ->setDisplayConfigurable('view', TRUE)
      ->setDisplayConfigurable('form', TRUE);

@@ -214,6 +240,10 @@ class Business extends ContentEntityBase implements BusinessInterface {
        'type' => 'email_default',
        'weight' => 1,
      ])
      ->setDisplayOptions('view', [
        'type' => 'email_mailto',
        'weight' => 1,
      ])
      ->setSetting('display_description', TRUE)
      ->setDisplayConfigurable('view', TRUE)
      ->setDisplayConfigurable('form', TRUE);
@@ -226,6 +256,10 @@ class Business extends ContentEntityBase implements BusinessInterface {
        'type' => 'telephone_default',
        'weight' => 2,
      ])
      ->setDisplayOptions('view', [
        'type' => 'telephone_link',
        'weight' => 2,
      ])
      ->setSetting('display_description', TRUE)
      ->setDisplayConfigurable('view', TRUE)
      ->setDisplayConfigurable('form', TRUE);
@@ -246,6 +280,10 @@ class Business extends ContentEntityBase implements BusinessInterface {
        'type' => 'address_default',
        'weight' => 3,
      ])
      ->setDisplayOptions('view', [
        'type' => 'address_default',
        'weight' => 3,
      ])
      ->setDisplayConfigurable('view', TRUE)
      ->setDisplayConfigurable('form', TRUE);

@@ -262,6 +300,10 @@ class Business extends ContentEntityBase implements BusinessInterface {
        'type' => 'string_textfield',
        'weight' => 4,
      ])
      ->setDisplayOptions('view', [
        'type' => 'string',
        'weight' => 4,
      ])
      ->setDisplayConfigurable('view', TRUE)
      ->setDisplayConfigurable('form', TRUE);

@@ -277,6 +319,10 @@ class Business extends ContentEntityBase implements BusinessInterface {
        'type' => 'datetime_default',
        'weight' => 5,
      ])
      ->setDisplayOptions('view', [
        'type' => 'datetime_default',
        'weight' => 5,
      ])
      ->setDisplayConfigurable('view', TRUE)
      ->setDisplayConfigurable('form', TRUE);

@@ -288,6 +334,10 @@ class Business extends ContentEntityBase implements BusinessInterface {
        'type' => 'options_select',
        'weight' => 6,
      ])
      ->setDisplayOptions('view', [
        'type' => 'string',
        'weight' => 6,
      ])
      ->setDisplayConfigurable('view', TRUE)
      ->setDisplayConfigurable('form', TRUE);

@@ -299,6 +349,10 @@ class Business extends ContentEntityBase implements BusinessInterface {
        'type' => 'options_select',
        'weight' => 7,
      ])
      ->setDisplayOptions('view', [
        'type' => 'string',
        'weight' => 6,
      ])
      ->setDisplayConfigurable('view', TRUE)
      ->setDisplayConfigurable('form', TRUE);

@@ -310,7 +364,6 @@ class Business extends ContentEntityBase implements BusinessInterface {
      ->setSetting('handler', 'default')
      ->setCardinality(BaseFieldDefinition::CARDINALITY_UNLIMITED)
      ->setDisplayOptions('view', [
        'label' => 'hidden',
        'type' => 'entity_reference_entity_view',
        'settings' => [
          'view_mode' => 'default',
@@ -378,4 +431,18 @@ class Business extends ContentEntityBase implements BusinessInterface {
    return \Drupal::service('address.country_repository')->getList();
  }

  /**
   * Gets the workflow ID for the state field.
   *
   * @param \Drupal\kyc\Entity\BusinessInterface $business
   *   The person.
   *
   * @return string
   *   The workflow ID.
   */
  public static function getWorkflowId(BusinessInterface $business) {
    $business_type = PersonType::load($business->bundle());
    return $business_type?->getWorkflowId() ?? 'kyc_default';
  }

}
+24 −2
Original line number Diff line number Diff line
@@ -58,10 +58,17 @@ use Drupal\Core\Config\Entity\ConfigEntityBundleBase;
 *   }
 * )
 */
class BusinessType extends ConfigEntityBundleBase {
class BusinessType extends ConfigEntityBundleBase implements BusinessTypeInterface {

  /**
   * A brief description of this kyc type.
   * The business type workflow ID.
   *
   * @var string
   */
  protected $workflow;

  /**
   * A brief description of this business type.
   *
   * @var string
   */
@@ -82,4 +89,19 @@ class BusinessType extends ConfigEntityBundleBase {
    return $this;
  }

  /**
   * {@inheritdoc}
   */
  public function getWorkflowId() {
    return $this->workflow;
  }

  /**
   * {@inheritdoc}
   */
  public function setWorkflowId($workflow_id) {
    $this->workflow = $workflow_id;
    return $this;
  }

}
Loading