You are here

function opigno_tincan_activity_form_opigno_activity_opigno_tincan_add_form_validate in Opigno module 8

Same name and namespace in other branches
  1. 3.x ActivityTypes/opigno_tincan_activity/opigno_tincan_activity.module \opigno_tincan_activity_form_opigno_activity_opigno_tincan_add_form_validate()

Function called when a form for type opigno_tincan_activity is raised.

1 string reference to 'opigno_tincan_activity_form_opigno_activity_opigno_tincan_add_form_validate'
opigno_tincan_activity_form_opigno_activity_opigno_tincan_add_form_alter in ActivityTypes/opigno_tincan_activity/opigno_tincan_activity.module
Implements hook_form_FORM_ID_alter().

File

ActivityTypes/opigno_tincan_activity/opigno_tincan_activity.module, line 36
The main module file which contains the main drupal hooks.

Code

function opigno_tincan_activity_form_opigno_activity_opigno_tincan_add_form_validate(&$form, FormStateInterface $form_state) {
  $messenger = \Drupal::messenger();

  // Check if Tincan PHP library is installed.
  $has_library = opigno_tincan_api_tincanphp_is_installed();
  if (!$has_library) {
    $form_state
      ->setError($form, t('Impossible to create a new TinCan Package activity.'));
    $messenger
      ->addWarning(Markup::create("Please install the TinCanPHP library using Composer, with the command: <em>composer require rusticisoftware/tincan:@stable</em>"));
  }
  else {

    // Check if the LRS settings are set.
    $config = \Drupal::config('opigno_tincan_api.settings');
    $endpoint = $config
      ->get('opigno_tincan_api_endpoint');
    $username = $config
      ->get('opigno_tincan_api_username');
    $password = $config
      ->get('opigno_tincan_api_password');
    if (empty($endpoint) || empty($username) || empty($password)) {
      $form_state
        ->setError($form, t('Impossible to create a new TinCan Package activity. Please, configure the LRS connection in the @setting_page.', [
        '@setting_page' => Link::createFromRoute('settings page', 'opigno_tincan_api.settings_form')
          ->toString(),
      ]));
    }
  }
}