0

I tried following the instructions here: How to override some admin theme CSS rules? and have spent a lot of time and energy googling and iterating this, so I'm turning to the stack exchange community for help.

What I'm trying to do is make some text fields larger when a user tries to edit a page. I'm attempting to do this by writing a custom module that checks if the page's url contains the string edit, and if so, enabling the custom css. The version is drupal 7, and I am working with Pantheon. So far, my module looks like this:

<?php

function admincss_preprocess_html(&$variables) {

$url_string = $_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'];

if (strpos($url_string, 'edit') !== FALSE) {

  // reference your current admin theme
    $theme_path = drupal_get_path('theme', 'seven');

  // reference your own stylesheet
    drupal_add_css('sites/all/modules/admincss/css/admincss.css', array('weight' => CSS_THEME));
}

Why isn't my module being used by edit pages? And what, specifically, is the $variables variable referencing? Thank you in advance!

1 Answer 1

0

To add CSS to node edit pages you can use hook_form_alter. Then check the $form_id to localize changes to desired node form(s) and add your call to drupal_add_css().

Example:

function admincss_form_alter(&$form, &$form_state, $form_id) {
  if ($form_id == "xxx") {
    drupal_add_css(drupal_get_path('module', 'admincss') . '/css/admincss.css');
  }
}

hook_preprocess_html() Is used to preprocess variables for the html.tpl.php file.

2
  • Great, glad to hear you got it working. If this answer is correct please upvote and mark as accepted answer. Commented Jul 6, 2018 at 20:26
  • 1
    I have very low reputation, so my upvote isn't visible, but I did upvote and have marked it as accepted.
    – Satchel
    Commented Jul 9, 2018 at 15:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.