Loading kyc.info.yml +1 −0 Original line number Diff line number Diff line Loading @@ -6,3 +6,4 @@ core_version_requirement: ^10 || ^11 dependencies: - address - inline_entity_form - state_machine kyc.workflow_groups.yml 0 → 100644 +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 src/Entity/Business.php +68 −1 Original line number Diff line number Diff line Loading @@ -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'] Loading @@ -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.')) Loading @@ -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); Loading @@ -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); Loading @@ -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); Loading @@ -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); Loading @@ -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); Loading @@ -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); Loading @@ -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); Loading @@ -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); Loading @@ -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', Loading Loading @@ -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'; } } src/Entity/BusinessType.php +24 −2 Original line number Diff line number Diff line Loading @@ -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 */ Loading @@ -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
kyc.info.yml +1 −0 Original line number Diff line number Diff line Loading @@ -6,3 +6,4 @@ core_version_requirement: ^10 || ^11 dependencies: - address - inline_entity_form - state_machine
kyc.workflow_groups.yml 0 → 100644 +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
src/Entity/Business.php +68 −1 Original line number Diff line number Diff line Loading @@ -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'] Loading @@ -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.')) Loading @@ -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); Loading @@ -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); Loading @@ -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); Loading @@ -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); Loading @@ -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); Loading @@ -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); Loading @@ -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); Loading @@ -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); Loading @@ -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', Loading Loading @@ -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'; } }
src/Entity/BusinessType.php +24 −2 Original line number Diff line number Diff line Loading @@ -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 */ Loading @@ -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; } }