Drupal Don't Be Like That - Part 1

  • Posted on: 1 October 2015
  • By: Shawn DeWolfe

Drupal likes to give you lots of options. Sometimes, it doesn't like to dole out control. For example, what if you make a View and expose a filter? There may be a long list of options that will just confuse the user. This Stack Exchange post asks about just that. The easy way to deal with this, is to use form alter to nip out the options. But what if you left the programmatic piece out of this? This can be addressed on the theming level.


In the code below, the CSS turns off the display of select form options in the dropdowns.
/* form controls - general */
 
option[value="word"] { display: none; }
option[value="allwords"] { display: none; }
option[value="starts"] { display: none; }
option[value="not_starts"] { display: none; }
option[value="ends"] { display: none; }
option[value="not_ends"] { display: none; }
option[value="shorterthan"] { display: none; }
option[value="longerthan"] { display: none; }
option[value="regular_expression"] { display: none; }
option[value="empty"] { display: none; }
option[value="not empty"] { display: none; }
This will not mask out the options entirely nor bar users from trying to use these options, this will only remove them from view.

Maybe you want to hide these from the general public, but make those options available to logged in users:
/* form controls - logged in */

.logged-in option[value="regular_expression"] { display: inline; }
.logged-in option[value="empty"] { display: inline; }
.logged-in option[value="not empty"] { display: inline; }
These would have to follow the first set of generally applicable styles to make more specific styles that apply to logged in people.
*Part 1? I think there are enough Drupalisms that this will be first part in a long list of Drupal quirk remedies.

Last updated date

Thursday, October 1, 2015 - 12:20