You are here

maestro_form_approval_example.install in Maestro 3.x

Install file for the Maestro form approval example flow.

File

modules/examples/maestro_form_approval_example/maestro_form_approval_example.install
View source
<?php

/**
 * @file
 * Install file for the Maestro form approval example flow.
 */
use Drupal\user\Entity\Role;
use Drupal\maestro\Engine\MaestroEngine;
use Drupal\user\Entity\User;

/**
 * Implements hook_install().
 */
function maestro_form_approval_example_install() {
  $user = User::create();
  $user
    ->setPassword('password');
  $user
    ->enforceIsNew();
  $user
    ->setEmail('test@test.test');
  $user
    ->setUsername('maestro_manager');
  $user
    ->activate();
  $res = $user
    ->save();
  $user
    ->addRole('maestro_example');
  $user
    ->save();
  $user = User::create();
  $user
    ->setPassword('password');
  $user
    ->enforceIsNew();
  $user
    ->setEmail('test2@test.test');
  $user
    ->setUsername('maestro_employee');
  $user
    ->activate();
  $res = $user
    ->save();
  $user
    ->addRole('maestro_example');
  $user
    ->save();
}

/**
 * Implements hook_uninstall().
 */
function maestro_form_approval_example_uninstall() {

  // Remove the two users we created.
  $user = user_load_by_name('maestro_manager');
  if ($user) {
    \Drupal::entityTypeManager()
      ->getStorage('user')
      ->load($user
      ->id())
      ->delete();
  }
  $user = user_load_by_name('maestro_employee');
  if ($user) {
    \Drupal::entityTypeManager()
      ->getStorage('user')
      ->load($user
      ->id())
      ->delete();
  }

  // Remove the template.
  $template = MaestroEngine::getTemplate('form_approval_flow');
  if ($template) {
    $template
      ->delete();
  }

  // Remove our role.
  $role = Role::load('maestro_example');
  if ($role) {
    $role
      ->delete();
  }
}