I wanted to use javascript to delete an option from the list of options in case the user is not an administrator and I searched and found this code inside a post and I used it inside the project's themes->mythemename->mythemename.theme file, but that didn't work and I have several problems I want to know how to solve, as I searched a lot I did not find a solution
function mythemename_preprocess_page(&$variables, $hook) {
if (!in_array("administrator", \Drupal::currentUser()->roles) {
if (isset($variables['node']->type) && !empty($variables['node']->type) && (strpos($variables['node']->type, 'proxy_request') !== false)) {
drupal_add_js(drupal_get_path('theme', 'mythemename') . '/js/datcbaseauth.js');
}
}
}
The first problem is that I can't get the data of the current user, as I am always reported that it is the second parameter of the in_array function is null.
The second problem is that I am telling that the second parameter of the strpos function is an object and not just a string even though the example in the post was treating it as just a string.
The third and final problem is that I am saying that function drupal_add_js and function drupal_get_path are undefined.
I searched for a long time, but I did not find a solution to these 3 problems, even the topics they may mentioned in it are not complete, for example, do not report how to use the drupal_add_js function inside the .theme file what is the prerequisite or even within Drupal's documentation itself, there is no data on the variable &$variables will tell about its content, the nature of each part, etc except that it is an associative array