You are here

class LearningPathAdminSettingsForm in Opigno Learning path 8

Same name and namespace in other branches
  1. 3.x src/Form/LearningPathAdminSettingsForm.php \Drupal\opigno_learning_path\Form\LearningPathAdminSettingsForm

Class LearningPathAdminSettingsForm.

Hierarchy

Expanded class hierarchy of LearningPathAdminSettingsForm

1 string reference to 'LearningPathAdminSettingsForm'
opigno_learning_path.routing.yml in ./opigno_learning_path.routing.yml
opigno_learning_path.routing.yml

File

src/Form/LearningPathAdminSettingsForm.php, line 11

Namespace

Drupal\opigno_learning_path\Form
View source
class LearningPathAdminSettingsForm extends ConfigFormBase {

  /**
   * {@inheritdoc}
   */
  protected function getEditableConfigNames() {
    return [
      'opigno_learning_path.learning_path_settings',
    ];
  }

  /**
   * {@inheritdoc}
   */
  public function getFormId() {
    return 'learning_path_admin_settings_form';
  }

  /**
   * {@inheritdoc}
   */
  public function buildForm(array $form, FormStateInterface $form_state) {
    $tokens_description = [
      '#type' => 'container',
      [
        '#type' => 'html_tag',
        '#tag' => 'div',
        '#value' => t('Group tokens:'),
      ],
      [
        '#theme' => 'item_list',
        '#list_type' => 'ul',
        '#items' => [
          '[group] - ' . $this
            ->t('group name'),
          '[link] - ' . $this
            ->t('link to group'),
          '[user] - ' . $this
            ->t('user account name'),
          '[user-role] - ' . $this
            ->t('user role in group'),
          '[user-status] - ' . $this
            ->t('user current status'),
        ],
      ],
    ];
    $config = $this
      ->config('opigno_learning_path.learning_path_settings');
    $form['opigno_learning_path_mail'] = [
      '#type' => 'fieldset',
      '#title' => $this
        ->t('E-mail notifications settings'),
    ];
    $form['opigno_learning_path_mail']['opigno_learning_path_notify_admin'] = [
      '#type' => 'checkbox',
      '#title' => $this
        ->t('Notify administrators'),
      '#description' => $this
        ->t('If checked administrators will be notified on trainings updates.'),
      '#default_value' => $config
        ->get('opigno_learning_path_notify_admin'),
    ];
    $form['opigno_learning_path_mail']['opigno_learning_path_notify_admin_mails'] = [
      '#type' => 'textarea',
      '#title' => $this
        ->t('Administrators email list.'),
      '#default_value' => $config
        ->get('opigno_learning_path_notify_admin_mails'),
    ];
    $form['opigno_learning_path_mail']['opigno_learning_path_notify_admin_user_subscribed'] = [
      '#type' => 'textarea',
      '#title' => $this
        ->t('Message to admins when user subscribed/updated/removed'),
      '#default_value' => $config
        ->get('opigno_learning_path_notify_admin_user_subscribed'),
    ];
    $form['opigno_learning_path_mail']['opigno_learning_path_notify_admin_user_approval'] = [
      '#type' => 'textarea',
      '#title' => $this
        ->t('Message to admins when user awaiting approval'),
      '#default_value' => $config
        ->get('opigno_learning_path_notify_admin_user_approval'),
    ];
    $form['opigno_learning_path_mail']['opigno_learning_path_notify_admin_user_blocked'] = [
      '#type' => 'textarea',
      '#title' => $this
        ->t('Message to admins when user blocked'),
      '#default_value' => $config
        ->get('opigno_learning_path_notify_admin_user_blocked'),
    ];
    $form['opigno_learning_path_mail']['opigno_learning_path_notify_group_tokens_1'] = $tokens_description;
    if (\Drupal::moduleHandler()
      ->moduleExists('token')) {
      $form['opigno_learning_path_mail']['token_tree_1'] = [
        '#theme' => 'token_tree_link',
        '#show_restricted' => TRUE,
      ];
    }
    $form['opigno_learning_path_mail']['opigno_learning_path_notify_users'] = [
      '#type' => 'checkbox',
      '#title' => $this
        ->t('Notify users'),
      '#description' => $this
        ->t('If checked users will be notified on training updates.'),
      '#default_value' => $config
        ->get('opigno_learning_path_notify_users'),
    ];
    $form['opigno_learning_path_mail']['opigno_learning_path_notify_user_user_subscribed'] = [
      '#type' => 'textarea',
      '#title' => $this
        ->t('Message to user when he subscribed/updated/removed'),
      '#default_value' => $config
        ->get('opigno_learning_path_notify_user_user_subscribed'),
    ];
    $form['opigno_learning_path_mail']['opigno_learning_path_notify_user_user_approval'] = [
      '#type' => 'textarea',
      '#title' => $this
        ->t('Message to user when he awaiting approval'),
      '#default_value' => $config
        ->get('opigno_learning_path_notify_user_user_approval'),
    ];
    $form['opigno_learning_path_mail']['opigno_learning_path_notify_user_user_blocked'] = [
      '#type' => 'textarea',
      '#title' => $this
        ->t('Message to user when he blocked'),
      '#default_value' => $config
        ->get('opigno_learning_path_notify_user_user_blocked'),
    ];
    $form['opigno_learning_path_mail']['opigno_learning_path_notify_group_tokens_2'] = $tokens_description;
    if (\Drupal::moduleHandler()
      ->moduleExists('token')) {
      $form['opigno_learning_path_mail']['token_tree_2'] = [
        '#theme' => 'token_tree_link',
        '#show_restricted' => TRUE,
      ];
    }
    $form['opigno_learning_path_mail']['opigno_learning_path_notify_user_user_certificate_expired'] = [
      '#type' => 'textarea',
      '#title' => $this
        ->t('Message to user when a training certificate has expired'),
      '#default_value' => $config
        ->get('opigno_learning_path_notify_user_user_certificate_expired'),
    ];
    $form['opigno_learning_path_mail']['opigno_learning_path_notify_group_tokens_3'] = [
      '#type' => 'container',
      [
        '#type' => 'html_tag',
        '#tag' => 'div',
        '#value' => t('Group tokens:'),
      ],
      [
        '#theme' => 'item_list',
        '#list_type' => 'ul',
        '#items' => [
          '[group:title] - ' . $this
            ->t('group name'),
          '[group:url] - ' . $this
            ->t('link to group'),
          '[group:expiration_date] - ' . $this
            ->t('certificate expiration date'),
        ],
      ],
    ];
    if (\Drupal::moduleHandler()
      ->moduleExists('token')) {
      $form['opigno_learning_path_mail']['token_tree_3'] = [
        '#theme' => 'token_tree_link',
        '#token_types' => [
          'group',
        ],
        '#show_restricted' => TRUE,
      ];
    }
    $form['opigno_learning_path_mail']['opigno_learning_path_student_does_activity_notify'] = [
      '#type' => 'checkbox',
      '#title' => $this
        ->t('Notify manager'),
      '#description' => $this
        ->t('If checked a manager will be notified when student does an activity.'),
      '#default_value' => $config
        ->get('opigno_learning_path_student_does_activity_notify'),
    ];
    $form['opigno_learning_path_mail']['opigno_learning_path_student_does_activity'] = [
      '#type' => 'textarea',
      '#title' => $this
        ->t('Message to a manager when student does an activity.'),
      '#default_value' => $config
        ->get('opigno_learning_path_student_does_activity'),
    ];
    $form['opigno_learning_path_mail']['student_does_activity_tokens'] = [
      '#type' => 'container',
      [
        '#type' => 'html_tag',
        '#tag' => 'div',
        '#value' => t('Tokens:'),
      ],
      [
        '#theme' => 'item_list',
        '#list_type' => 'ul',
        '#items' => [
          '[module] - ' . $this
            ->t('module name'),
          '[link] - ' . $this
            ->t('link to evaluate'),
          '[manager] - ' . $this
            ->t('manager name'),
          '[user] - ' . $this
            ->t('user name'),
          '[sitename] - ' . $this
            ->t('site name'),
        ],
      ],
    ];
    $form['opigno_learning_path_mail']['opigno_learning_path_students_answer_is_reviewed_notify'] = [
      '#type' => 'checkbox',
      '#title' => $this
        ->t('Notify student'),
      '#description' => $this
        ->t('If checked a student will be notified when student does an activity.'),
      '#default_value' => $config
        ->get('opigno_learning_path_students_answer_is_reviewed_notify'),
    ];
    $form['opigno_learning_path_mail']['opigno_learning_path_students_answer_is_reviewed'] = [
      '#type' => 'textarea',
      '#title' => $this
        ->t('Message to a student when his answer has been reviewed.'),
      '#default_value' => $config
        ->get('opigno_learning_path_students_answer_is_reviewed'),
    ];
    $form['opigno_learning_path_mail']['students_answer_is_reviewed_tokens'] = [
      '#type' => 'container',
      [
        '#type' => 'html_tag',
        '#tag' => 'div',
        '#value' => t('Tokens:'),
      ],
      [
        '#theme' => 'item_list',
        '#list_type' => 'ul',
        '#items' => [
          '[module] - ' . $this
            ->t('module name'),
          '[manager] - ' . $this
            ->t('manager name'),
          '[user] - ' . $this
            ->t('user name'),
          '[sitename] - ' . $this
            ->t('site name'),
        ],
      ],
    ];
    return parent::buildForm($form, $form_state);
  }

  /**
   * {@inheritdoc}
   */
  public function validateForm(array &$form, FormStateInterface $form_state) {
    parent::validateForm($form, $form_state);
  }

  /**
   * {@inheritdoc}
   */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    parent::submitForm($form, $form_state);
    $this
      ->config('opigno_learning_path.learning_path_settings')
      ->set('opigno_learning_path_notify_admin', $form_state
      ->getValue('opigno_learning_path_notify_admin'))
      ->set('opigno_learning_path_notify_admin_mails', $form_state
      ->getValue('opigno_learning_path_notify_admin_mails'))
      ->set('opigno_learning_path_notify_users', $form_state
      ->getValue('opigno_learning_path_notify_users'))
      ->set('opigno_learning_path_notify_admin_user_subscribed', $form_state
      ->getValue('opigno_learning_path_notify_admin_user_subscribed'))
      ->set('opigno_learning_path_notify_admin_user_approval', $form_state
      ->getValue('opigno_learning_path_notify_admin_user_approval'))
      ->set('opigno_learning_path_notify_admin_user_blocked', $form_state
      ->getValue('opigno_learning_path_notify_admin_user_blocked'))
      ->set('opigno_learning_path_notify_user_user_subscribed', $form_state
      ->getValue('opigno_learning_path_notify_user_user_subscribed'))
      ->set('opigno_learning_path_notify_user_user_approval', $form_state
      ->getValue('opigno_learning_path_notify_user_user_approval'))
      ->set('opigno_learning_path_notify_user_user_blocked', $form_state
      ->getValue('opigno_learning_path_notify_user_user_blocked'))
      ->set('opigno_learning_path_notify_user_user_certificate_expired', $form_state
      ->getValue('opigno_learning_path_notify_user_user_certificate_expired'))
      ->set('opigno_learning_path_student_does_activity_notify', $form_state
      ->getValue('opigno_learning_path_student_does_activity_notify'))
      ->set('opigno_learning_path_student_does_activity', $form_state
      ->getValue('opigno_learning_path_student_does_activity'))
      ->set('opigno_learning_path_students_answer_is_reviewed_notify', $form_state
      ->getValue('opigno_learning_path_students_answer_is_reviewed_notify'))
      ->set('opigno_learning_path_students_answer_is_reviewed', $form_state
      ->getValue('opigno_learning_path_students_answer_is_reviewed'))
      ->save();
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ConfigFormBase::create public static function Instantiates a new instance of this class. Overrides FormBase::create 13
ConfigFormBase::__construct public function Constructs a \Drupal\system\ConfigFormBase object. 11
ConfigFormBaseTrait::config protected function Retrieves a configuration object.
DependencySerializationTrait::$_entityStorages protected property An array of entity type IDs keyed by the property name of their storages.
DependencySerializationTrait::$_serviceIds protected property An array of service IDs keyed by property name used for serialization.
DependencySerializationTrait::__sleep public function 1
DependencySerializationTrait::__wakeup public function 2
FormBase::$configFactory protected property The config factory. 1
FormBase::$requestStack protected property The request stack. 1
FormBase::$routeMatch protected property The route match.
FormBase::configFactory protected function Gets the config factory for this form. 1
FormBase::container private function Returns the service container.
FormBase::currentUser protected function Gets the current user.
FormBase::getRequest protected function Gets the request object.
FormBase::getRouteMatch protected function Gets the route match.
FormBase::logger protected function Gets the logger for a specific channel.
FormBase::redirect protected function Returns a redirect response object for the specified route. Overrides UrlGeneratorTrait::redirect
FormBase::resetConfigFactory public function Resets the configuration factory.
FormBase::setConfigFactory public function Sets the config factory for this form.
FormBase::setRequestStack public function Sets the request stack object to use.
LearningPathAdminSettingsForm::buildForm public function Form constructor. Overrides ConfigFormBase::buildForm
LearningPathAdminSettingsForm::getEditableConfigNames protected function Gets the configuration names that will be editable. Overrides ConfigFormBaseTrait::getEditableConfigNames
LearningPathAdminSettingsForm::getFormId public function Returns a unique string identifying the form. Overrides FormInterface::getFormId
LearningPathAdminSettingsForm::submitForm public function Form submission handler. Overrides ConfigFormBase::submitForm
LearningPathAdminSettingsForm::validateForm public function Form validation handler. Overrides FormBase::validateForm
LinkGeneratorTrait::$linkGenerator protected property The link generator. 1
LinkGeneratorTrait::getLinkGenerator Deprecated protected function Returns the link generator.
LinkGeneratorTrait::l Deprecated protected function Renders a link to a route given a route name and its parameters.
LinkGeneratorTrait::setLinkGenerator Deprecated public function Sets the link generator service.
LoggerChannelTrait::$loggerFactory protected property The logger channel factory service.
LoggerChannelTrait::getLogger protected function Gets the logger for a specific channel.
LoggerChannelTrait::setLoggerFactory public function Injects the logger channel factory.
MessengerTrait::$messenger protected property The messenger. 29
MessengerTrait::messenger public function Gets the messenger. 29
MessengerTrait::setMessenger public function Sets the messenger.
RedirectDestinationTrait::$redirectDestination protected property The redirect destination service. 1
RedirectDestinationTrait::getDestinationArray protected function Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url.
RedirectDestinationTrait::getRedirectDestination protected function Returns the redirect destination service.
RedirectDestinationTrait::setRedirectDestination public function Sets the redirect destination service.
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.
UrlGeneratorTrait::$urlGenerator protected property The url generator.
UrlGeneratorTrait::getUrlGenerator Deprecated protected function Returns the URL generator service.
UrlGeneratorTrait::setUrlGenerator Deprecated public function Sets the URL generator service.
UrlGeneratorTrait::url Deprecated protected function Generates a URL or path for a specific route based on the given parameters.