Company creation in Drupal 8 at code level

robinrana
Participant I

I'm trying to create a new company at org via a custom module in Drupal 8. Is there any document or code or any API that I can use for creating a new company at org via Drupal 8 custom module.

Is the company an entity in Drupal 8?

Below are the modules I'm using:

1) apigee_edge

2) apigee_m10n

Org has connected at my side.

Solved Solved
0 8 513
2 ACCEPTED SOLUTIONS

Take a look at apigee_edge/modules/apigee_edge_teams/src/Entity/Form/TeamForm.php in save(). Or https://github.com/apigee/apigee-edge-drupal/blob/8.x-1.x/modules/apigee_edge_teams/tests/src/Functi... which also creates a team programatically.

View solution in original post

robinrana
Participant I

Finally, I got the solution for the same:

$team = $team_storage->create(['name' => 'Loreum', 'displayName' => 'zzzzzyrobin','status' => 'active']);
$team->setAttribute('foo', 'bar');
// or $team->setAttributes(new \Apigee\Edge\Structure\AttributesProperty(['foo' => 'bar', 'bar' => 'baz"]);
$team->save(); -------------------------------------------------- $team = $team_storage->create(['name' => 'Loreum', 'displayName' => 'zzzzzyrobin','status' => 'active', 'attributes' => new \Apigee\Edge\Structure\AttributesProperty(['foo' => 'bar', 'bar' => 'baz"])]);
$team->save();

9190-solution.png

View solution in original post

8 REPLIES 8

Take a look at apigee_edge/modules/apigee_edge_teams/src/Entity/Form/TeamForm.php in save(). Or https://github.com/apigee/apigee-edge-drupal/blob/8.x-1.x/modules/apigee_edge_teams/tests/src/Functi... which also creates a team programatically.

So the earlier concept of the company replace with team. right?

Yeah, team == company. Now you can rename it to something else too, like "Projects" or "Business Groups"

Thanks Karl

@Karl Scheirer, Is there is any kind of documentation available for that? I'm unable to create a team programmatically.

Thanks
Robin

Drupal 7 the company object was as given below, which I'm trying to achieve the same in Drupal 8.


ApigeeCompanyEntity Object
(
[name] => addy25092019
[attributes] => Array
(
[ADMIN_EMAIL] => aditya.@.net
[MINT_COMPANY_ID] =>
[MINT_REGISTRATION_ID] => 123456789
[MINT_TAX_EXEMPT_AUTH_NO] =>
[MINT_DEVELOPER_LEGAL_NAME] => addy25092019
[MINT_BILLING_TYPE] => POSTPAID
[MINT_DEVELOPER_PHONE] => 9898989898
[MINT_APPROX_TAX_RATE] => 0.10
[MINT_DEVELOPER_TYPE] => UNTRUSTED
)
[displayName] => addy25092019
[status] => active
[developers] => Array
(
[Monetization Administrator] => Array
(
[0] => aditya.
@**.net
)

<code>	)

[createdAt] => 1569404031006
[createdBy] => ************************
[lastModifiedAt] => 1569404031006
[lastModifiedBy] => *********************
[apps] => Array
	(
	)

[organization] => Lorem Ipsum
[debugData] => ...

)


In Drupal 8 I'm able to create company using the only three attributes i.e name, display name and status(Please check below code for same) but in case I'm trying to add more attribute i'm getting error(Pls check the code in Drupal 8 --- Other attribute)

$team_storage = \Drupal::entityTypeManager()->getStorage('team');

$team = $team_storage->create(['name' => 'Loreum', 'displayName' => 'zzzzzyrobin','status' => 'active']);

$team->save();


Drupal 8 --- Other attribute

$team_storage = \Drupal::entityTypeManager()->getStorage('team');

$team = $team_storage->create(['name' => 'loreumIpsum', 'attributes' => array('ADMIN_EMAIL' => 'rob.******.net','MINT_APPROX_TAX_RATE' => 0.10, 'MINT_BILLING_TYPE' => 'POSTPAID', 'MINT_COMPANY_ID' =>'','MINT_DEVELOPER_ADDRESS' => '{"address1":"24 Street","address2":"","city":"Loreum Ipsum","country":"EU","isPrimary":"true","state":"loreum","zip":"213565"}','MINT_DEVELOPER_LEGAL_NAME' => 'ROB0502COM1','MINT_DEVELOPER_PHONE' => 1234567890,'MINT_REGISTRATION_ID' => 123456789, 'MINT_TAX_EXEMPT_AUTH_NO'=>'','MINT_DEVELOPER_TYPE' => 'UNTRUSTED'), 'displayName' => 'zzzzzyrobin','status' => 'active']);

$team->save();

Error: Cannot unpack array with string keys in Apigee\Edge\Structure\BaseObject->__construct()

robinrana
Participant I

Finally, I got the solution for the same:

$team = $team_storage->create(['name' => 'Loreum', 'displayName' => 'zzzzzyrobin','status' => 'active']);
$team->setAttribute('foo', 'bar');
// or $team->setAttributes(new \Apigee\Edge\Structure\AttributesProperty(['foo' => 'bar', 'bar' => 'baz"]);
$team->save(); -------------------------------------------------- $team = $team_storage->create(['name' => 'Loreum', 'displayName' => 'zzzzzyrobin','status' => 'active', 'attributes' => new \Apigee\Edge\Structure\AttributesProperty(['foo' => 'bar', 'bar' => 'baz"])]);
$team->save();

9190-solution.png

Hi,

how to add members to the team programmatically?

how to add roles to the team members programatically?

could you please help here?