I have 2 views, each one with a type of node (Products and Users). I want to add a unique class in each node create/edit pages, but i can’t find any difference between the two, the only way i found is with the title of the page but that is not a good solution, because if the title changes it will stop working.
I’m using the preprocess_html hook
I tried with the route of the two pages but it’s the same.
$route = Drupal::routeMatch()->getRouteName();
/* Output:
/* Products edit page -> $route = entity.node.edit_form
/* Users edit page -> $route = entity.node.edit_form
/*
/* In the node creation pages it's the same too
*/
Is there any way to find a difference in code from two node creation/edit pages?
This is the code i used to add classes to the same pages but now i need to add more specific classes like users_creation_page and products_creation_pages
$route = Drupal::routeMatch()->getRouteName();
//Adding unique class to creation, edit and delete pages
if (str_contains($route, 'add') || str_contains($route, 'create')) {
$variables['attributes']['class'][] = 'action-nodes-page';
}
elseif (str_contains($route, 'edit')) {
$variables['attributes']['class'][] = 'action-nodes-page';
}
elseif (str_contains($route, 'delete')) {
$variables['attributes']['class'][] = 'node-delete-page';
}