You are here

function spamicide_add_button_to_form in Spamicide 8

Helper function to check permissions and requirements to form.

Parameters

bool $spamicide: Spamicide.

string $form_id: Form id.

Return value

bool True or false.

1 call to spamicide_add_button_to_form()
spamicide_form_alter in ./spamicide.module
Implements hook_form_alter().

File

./spamicide.module, line 133
Spamicide.module.

Code

function spamicide_add_button_to_form($spamicide, $form_id) {
  $current_path = \Drupal::service('path.current');
  $spamicide_settings = \Drupal::configFactory()
    ->get('spamicide.settings');
  $currentUser = \Drupal::currentUser();
  $exclude_forms = [
    'spamicide_add_form',
    'spamicide_edit_form',
    'spamicide_delete_form',
    'search_block_form',
    'search_form',
  ];
  if ($spamicide_settings
    ->get('spamicide_admin_mode') && $currentUser
    ->hasPermission('administer spamicide') && !$spamicide && !in_array($form_id, $exclude_forms) && strpos($current_path
    ->getPath(), '/admin/structure') === FALSE) {
    return TRUE;
  }
  return FALSE;
}