farmOS/modules/core/fieldkit/farm_fieldkit.install

47 lines
1.0 KiB
PHP

<?php
/**
* @file
* Install, update and uninstall function for the farm_fieldkit module.
*/
use Drupal\consumers\Entity\Consumer;
/**
* Implements hook_install().
*/
function farm_fieldkit_install() {
// Create a consumer for the farmOS Field Kit client.
$fk_consumer = Consumer::create([
'label' => 'Field Kit',
'client_id' => 'fieldkit',
'redirect' => 'https://farmOS.app',
'allowed_origins' => 'https://farmos.app',
'owner_id' => '',
'secret' => '',
'confidential' => FALSE,
'third_party' => FALSE,
'grant_user_access' => TRUE,
'limit_user_access' => TRUE,
'limit_requested_access' => FALSE,
]);
$fk_consumer->save();
}
/**
* Implements hook_uninstall().
*/
function farm_fieldkit_uninstall() {
// Load the fieldkit consumer.
$consumers = \Drupal::entityTypeManager()->getStorage('consumer')
->loadByProperties(['client_id' => 'fieldkit']);
// If found, delete the consumer.
if (!empty($consumers)) {
$client_consumer = reset($consumers);
$client_consumer->delete();
}
}