I'm using Drupal 7 with Bootstrap. I copied the sub-theme and renamed all the files accordingly and everything works fine, however I'm having problems with my sub-theme's template.php
not doing what it should.
I am trying to add specific CSS classes to my form field while editing the form or adding new content. I tried following http://atendesigngroup.com/blog/adding-css-classes-fields-drupal, but I can't change the field's classses.
This is the code I have in template.php.
/**
* Overrides theme_field()
* Remove the hard coded classes so we can add them in preprocess functions.
*/
function MojCrm_field($variables) {
$output = '';
// Render the label, if it's not hidden.
if (!$variables['label_hidden']) {
$output .= '<div ' . $variables['title_attributes'] . '>' . $variables['label'] . ': </div>';
}
// Render the items.
$output .= '<div ' . $variables['content_attributes'] . '>';
foreach ($variables['items'] as $delta => $item) {
$output .= '<div ' . $variables['item_attributes'][$delta] . '>' . drupal_render($item) . '</div>';
}
$output .= '</div>';
// Render the top-level DIV.
$output = '<div class="' . $variables['classes'] . '"' . $variables['attributes'] . '>' . $output . '</div>';
return $output;
}
/**
* Implements hook_preprocess_field()
*/
function MojCrm_preprocess_field(&$vars) {
/* Set shortcut variables. Hooray for less typing! */
$name = $vars['element']['#field_name'];
$bundle = $vars['element']['#bundle'];
$mode = $vars['element']['#view_mode'];
$classes = &$vars['classes_array'];
$title_classes = &$vars['title_attributes_array']['class'];
$content_classes = &$vars['content_attributes_array']['class'];
$item_classes = array();
/* Global field classes */
$classes[] = 'field-wrapper';
$title_classes[] = 'field-label';
$content_classes[] = 'field-items';
$item_classes[] = 'field-item';
/* Add specific classes to targeted fields */
switch ($name) {
case 'field_baza_direktor':
$title_classes[] = 'inline';
$content_classes[] = 'col-sm-6';
break;
}
}
$variables['classes']
an array?