V9: Group add() and delete() deprecated, what to use instead?

User Group add() and delete() are deprecated. The docs say to “use the AddGroupCommand and the command bus”. Is there any example or documentation how to use them to add and delete groups? This is outdated:

https://documentation.concretecms.org/developers/users-groups/groups/overview

Something like that:

use Concrete\Core\Support\Facade\Facade;
use Concrete\Core\User\Group\Command\AddGroupCommand;
use Concrete\Core\User\Group\Command\DeleteGroupCommand;

$app = Facade::getFacadeApplication();

// Add
$command = new AddGroupCommand();
$command->setName('Group name');
$command->setDescription('Group description');
$group = $app->executeCommand($command);

// Delete
$command = new DeleteGroupCommand($group->getGroupID());
$app->executeCommand($command);

@Parasek , thank you!

But I think we’ll soon be writing petitions too :slight_smile:

Why deprecate a 1-line piece of code if it already does that? Why remove $group->add() and $group->delete()? Now I have to write 10 lines of code instead of 2!

1 Like