Skip to content
Snippets Groups Projects

ISTWCMS-6850 Add message to service to create categories if none exist

1 file
+ 25
0
Compare changes
  • Side-by-side
  • Inline
+ 25
0
@@ -5,6 +5,7 @@
* Provides configuration and settings for services.
*/
use Drupal\Core\Link;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url;
use Drupal\views\Plugin\views\query\QueryPluginBase;
@@ -121,6 +122,30 @@ function uw_ct_service_form_node_uw_ct_service_form_alter(array &$form, FormStat
// ISTWCMS-5551: adding help text to office hours exception days.
$form['field_uw_service_hours']['widget']['office_hours_exceptions']['#description'] = t('<p>Exceptions further in the future will display once the exception is under one week away.</p>');
// Get terms from uw_vocab_service_categories.
$terms = \Drupal::entityTypeManager()->getStorage('taxonomy_term')->loadTree('uw_vocab_service_categories');
// If there is not service categories taxonomy term set yet.
if (empty($terms)) {
// Set message.
\Drupal::messenger()->addMessage(t('You must create at least one service category before adding a service.'), 'error');
// Get the current user.
$current_user = \Drupal::currentUser();
// If the current user has no permission, set field description.
if (!$current_user->hasPermission('create terms in uw_vocab_service_categories')) {
$form['field_uw_service_category']['widget']['#description'] = t('Reach out to someone who has access to add a service category.');
}
// If the current user has permission, add a link to create a term.
else {
$form['field_uw_service_category']['widget']['#description'] =
Link::fromTextAndUrl(t('Add a service category.'), Url::fromUri('internal:/admin/structure/taxonomy/manage/uw_vocab_service_categories/add'))->toString();
}
}
}
/**
Loading