Can I use hook_css_alter inside of hook_form_alter Can I use hook_css_alter inside of hook_form_alter. I need to unset a css file only on certain forms and only to non-admins. This is what I have but it doesn't work.

use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\Session\UserSession;

function mymodule_form_alter(array &amp;$form, FormStateInterface $form_state,  $form_id) {
  $user = \Drupal::currentUser()-&gt;getRoles();
    if(in_array("administrator", $user)) {

    function mymodule_css_alter(&amp;$css) {
      unset($css['core/themes/stable/css/system/components/tabledrag.module.css']);
    }
  }
}
You can't use a hook function inside of a hook function. If you are in the css alter hook you have to get the information you need from where you are in code. For example you could check for the route name of the form because the current route match is available in a service. So this could work (not tested):

function mymodule_css_alter(&amp;$css) {
  $user = \Drupal::currentUser()-&gt;getRoles();
  $route = \Drupal::service('current_route_match')-&gt;getRouteName();
  if (in_array('administrator', $user) &amp;&amp; $route == 'entity.node.edit_form') {
    ...