public static function Sharrre::checkConfiguration in Share Message 8
Check if the plugin can work.
The library needs to be either external or we need the local library module with the library present.
Parameters
$show_message: A flag that determines if the warning should be shown or not.
Return value
mixed
2 calls to Sharrre::checkConfiguration()
- Sharrre::buildConfigurationForm in src/
Plugin/ sharemessage/ Sharrre.php - Form constructor.
- SharrreSettingsForm::buildForm in src/
Form/ SharrreSettingsForm.php - Form constructor.
File
- src/
Plugin/ sharemessage/ Sharrre.php, line 33
Class
- Sharrre
- Sharrre plugin.
Namespace
Drupal\sharemessage\Plugin\sharemessageCode
public static function checkConfiguration($show_message = FALSE) {
if (\Drupal::config('sharemessage.sharrre')
->get('library_url')) {
// We have an external library URL configured. Fine.
return NULL;
}
// Check for both, local library and remote URL.
if (!\Drupal::moduleHandler()
->moduleExists('libraries') && !\Drupal::config('sharemessage.sharrre')
->get('library_url') && $show_message) {
$form['message'] = [
'#type' => 'container',
'#markup' => t('Either set the library locally (in /libraries/sharrre) and enable the libraries module or enter the remote URL on <a href=":sharrre_settings">Sharrre settings page</a>.', [
':sharrre_settings' => Url::fromRoute('sharemessage.sharrre.settings')
->toString(),
]),
'#attributes' => [
'class' => [
'messages messages--error',
],
],
];
return $form;
}
if (\Drupal::moduleHandler()
->moduleExists('libraries')) {
// Check if local library is set correctly.
$directory = libraries_get_path('sharrre');
$file = 'jquery.sharrre.min.js';
if (!file_exists($directory . '/' . $file) && $show_message) {
$form['message'] = [
'#type' => 'container',
'#markup' => t('The library file is not present in the expected directory (/libraries/sharrre).'),
'#attributes' => [
'class' => [
'messages messages--error',
],
],
];
return $form;
}
}
}