diff --git a/css/ds.admin.css b/css/ds.admin.css
index e69de29..e80170e 100644
--- a/css/ds.admin.css
+++ b/css/ds.admin.css
@@ -0,0 +1,9 @@
+
+.extra-field-settings {
+ display: none;
+ width: 300px;
+ z-index: 1000;
+ border: 1px solid #000;
+ padding: 5px;
+ background-color: #efefef;
+}
\ No newline at end of file
diff --git a/ds.api.php b/ds.api.php
index f85c229..5de14c2 100644
--- a/ds.api.php
+++ b/ds.api.php
@@ -339,6 +339,20 @@ function hook_ds_layout_info() {
}
/**
+ * Modify the field settings before they get saved.
+ *
+ * @param $field_settings
+ * A collection of field settings which keys are fields.
+ * @param $form
+ * The current form which is submitted.
+ * @param $form_state
+ * The form state with all its values.
+ */
+function hook_ds_field_settings_alter(&$field_settings, $form, $form_state) {
+ $field_settings['title']['region'] = 'left';
+}
+
+/**
* Alter the region options in the field UI screen.
*
* This function is only called when a layout has been chosen.
diff --git a/ds.field_ui.inc b/ds.field_ui.inc
index f5786d1..60e4f7d 100644
--- a/ds.field_ui.inc
+++ b/ds.field_ui.inc
@@ -246,19 +246,8 @@ function ds_field_ui_layouts_save($form, &$form_state) {
foreach ($fields as $key => $field) {
- // Ignore the Field group module and the region to block plugin.
- if ($key == '_add_new_group' || $key == '_add_new_block_region') {
- continue;
- }
-
- // If the field is in hidden region, do not save. Check if the
- // field has a type key which means it's from Field API and
- // we need to reset that type to 'hidden' so it doesn't get
- // fired by Field API in the frontend.
- if ($field['region'] == 'hidden') {
- if (isset($field['type'])) {
- $form_state['values']['fields'][$key]['type'] = 'hidden';
- }
+ // Make sure we need to save anything for this field
+ if (_ds_field_valid($key, $field, $form_state)) {
continue;
}
@@ -304,7 +293,7 @@ function ds_field_ui_layouts_save($form, &$form_state) {
}
/**
- * Save the field settings from the 'Manage display' screen.
+ * Save the Display Suite field settings from the 'Manage display' screen.
*/
function ds_field_ui_fields_save($form, &$form_state) {
@@ -348,6 +337,9 @@ function ds_field_ui_fields_save($form, &$form_state) {
$field_settings[$field] = $settings;
}
+ // Let other modules modify the field settings before they get saved.
+ drupal_alter('ds_field_settings', $field_settings, $form, $form_state);
+
// Save the record.
if (!empty($field_settings)) {
$record = new stdClass;
@@ -599,10 +591,12 @@ function _ds_field_ui_fields($entity_type, $bundle, $view_mode, &$form, &$form_s
return;
}
- // Get the fields.
+ // Get the fields and put them on the form.
$fields = ds_get_fields($entity_type, FALSE);
$field_settings = ds_get_field_settings($entity_type, $bundle, $view_mode);
+ $form['#field_settings'] = $field_settings;
+
$table = &$form['fields'];
$form['#ds_fields'] = array();
@@ -765,28 +759,52 @@ function _ds_field_ui_fields($entity_type, $bundle, $view_mode, &$form, &$form_s
}
/**
+ * Helper function to check if we need to save anything for this field.
+ */
+function _ds_field_valid($key, $field, &$form_state) {
+ $continue = FALSE;
+
+ // Ignore the Field group module and the region to block plugin.
+ if ($key == '_add_new_group' || $key == '_add_new_block_region') {
+ $continue = TRUE;
+ }
+
+ // If the field is in hidden region, do not save. Check if the
+ // field has a type key which means it's from Field API and
+ // we need to reset that type to 'hidden' so it doesn't get
+ // fired by Field API in the frontend.
+ if ($field['region'] == 'hidden') {
+ if (isset($field['type'])) {
+ $form_state['values']['fields'][$key]['type'] = 'hidden';
+ }
+ $continue = TRUE;
+ }
+
+ return $continue;
+}
+
+/**
* Return styles.
*/
-function _ds_styles() {
- static $run = FALSE;
+function _ds_styles($name = 'ds_styles_regions') {
static $styles = array();
- if (!$run) {
- $region_styles = trim(variable_get('ds_styles_regions', ''));
- if (!empty($region_styles)) {
- $styles[''] = t('None');
- $region_styles = explode("\n", $region_styles);
- foreach ($region_styles as $key => $value) {
+ if (!isset($styles[$name])) {
+ $styles[$name] = array();
+ $custom_styles = trim(variable_get($name, ''));
+ if (!empty($custom_styles)) {
+ $styles[$name][''] = t('None');
+ $custom_styles = explode("\n", $custom_styles);
+ foreach ($custom_styles as $key => $value) {
$classes = explode("|", $value);
$key = trim($classes[0]);
- $name = isset($classes[1]) ? trim($classes[1]) : $key;
- $styles[$key] = $name;
+ $friendly_name = isset($classes[1]) ? trim($classes[1]) : $key;
+ $styles[$name][$key] = $friendly_name;
}
}
- $run = TRUE;
}
- return $styles;
+ return $styles[$name];
}
diff --git a/ds.module b/ds.module
index ef94802..432e58d 100644
--- a/ds.module
+++ b/ds.module
@@ -402,6 +402,11 @@ function ds_field_attach_view_alter(&$build, $context) {
foreach ($field_values as $key => $field) {
+ // Ignore if this field is not a DS field.
+ if (!isset($fields[$key])) {
+ continue;
+ }
+
$field = $fields[$key];
$field['formatter'] = $field_values[$key]['format'];
@@ -420,6 +425,7 @@ function ds_field_attach_view_alter(&$build, $context) {
'#field_name' => $key,
'#bundle' => $bundle,
'#entity_type' => $entity_type,
+ '#view_mode' => $view_mode,
'#access' => TRUE,
'#items' => array(
0 => array(
diff --git a/ds.registry.inc b/ds.registry.inc
index e1d3b2d..e473a90 100644
--- a/ds.registry.inc
+++ b/ds.registry.inc
@@ -21,10 +21,10 @@ function _ds_menu() {
'file path' => drupal_get_path('module', 'system'),
);
- // Custom styles.
+ // Styles.
$items['admin/structure/ds/styles'] = array(
'title' => 'Styles',
- 'description' => 'Define classes which you can use as classes for regions.',
+ 'description' => 'Define styles which you can use as classes on regions and fields (if available).',
'page callback' => 'drupal_get_form',
'page arguments' => array('ds_styles_form'),
'file' => 'ds.styles.inc',
diff --git a/js/ds.js b/js/ds.js
index 0db51ca..8f1af01 100644
--- a/js/ds.js
+++ b/js/ds.js
@@ -1,6 +1,38 @@
(function($) {
+Drupal.DisplaySuite = Drupal.DisplaySuite || {};
+Drupal.DisplaySuite.fieldopened = '';
+
+/**
+ * Field settings.
+ */
+Drupal.behaviors.settingsToggle = {
+ attach: function (context) {
+ // remove click from link
+ $('.fs-link').click(function(e) {
+ e.preventDefault();
+ });
+
+ // Add click event to field settings link.
+ $('.fs-link').click(function(){
+ var settings = $(this).siblings('.extra-field-settings');
+ if (Drupal.DisplaySuite.fieldopened != '' && Drupal.DisplaySuite.fieldopened != settings.attr('id')) {
+ $('#' + Drupal.DisplaySuite.fieldopened).hide();
+ }
+
+ if (settings.is(':visible')) {
+ settings.hide();
+ }
+ else {
+ settings.slideDown('normal');
+ }
+ // Store the opened setting.
+ Drupal.DisplaySuite.fieldopened = settings.attr('id');
+ });
+ }
+};
+
/**
* Row handlers for the 'Manage display' screen.
*/
diff --git a/modules/ds_extras/ds_extras.install b/modules/ds_extras/ds_extras.install
index 95b723d..b683e94 100644
--- a/modules/ds_extras/ds_extras.install
+++ b/modules/ds_extras/ds_extras.install
@@ -75,6 +75,8 @@ function ds_extras_uninstall() {
variable_del('ds_extras_region_blocks');
variable_del('ds_extras_switch_view_mode');
variable_del('ds_extras_vd');
+ variable_del('ds_extras_field_settings');
+ variable_del('ds_extras_field_styles');
db_drop_field('node_revision', 'ds_switch');
}
diff --git a/modules/ds_extras/ds_extras.module b/modules/ds_extras/ds_extras.module
index 581a3be..f78f44a 100644
--- a/modules/ds_extras/ds_extras.module
+++ b/modules/ds_extras/ds_extras.module
@@ -40,6 +40,15 @@ function ds_extras_module_implements_alter(&$implementations, $hook) {
// Because it's possible to turn on/off features for DS extras,
// we'll unset hooks here if necessary which otherwhise do nothing at all.
+ // Disable the field settings feature.
+ $fs_hooks = array(
+ 'form_ds_styles_form_alter',
+ 'ds_field_settings_alter'
+ );
+ if (!variable_get('ds_extras_field_settings', FALSE) && in_array($hook, $fs_hooks)) {
+ unset($implementations['ds_extras']);
+ }
+
// Disable the region to block feature.
$region_hooks = array(
'ds_layout_region_alter',
@@ -66,12 +75,16 @@ function ds_extras_module_implements_alter(&$implementations, $hook) {
'field_extra_fields',
'entity_info',
'ds_fields_info',
- 'theme_registry_alter',
'ctools_plugin_api',
);
if (!variable_get('ds_extras_vd', FALSE) && in_array($hook, $vd_hooks)) {
unset($implementations['ds_extras']);
}
+
+ // Theme registry alter is used by 2 features.
+ if ((!variable_get('ds_extras_vd', FALSE) && !variable_get('ds_extras_field_settings', FALSE)) && $hook == 'theme_registry_alter') {
+ unset($implementations['ds_extras']);
+ }
}
/**
@@ -79,9 +92,21 @@ function ds_extras_module_implements_alter(&$implementations, $hook) {
*/
function ds_extras_settings($form) {
+ $form['fs'] = array(
+ '#type' => 'fieldset',
+ '#title' => t('Field settings'),
+ );
+
+ $form['fs']['ds_extras_field_settings'] = array(
+ '#type' => 'checkbox',
+ '#title' => t('Enable'),
+ '#description' => t('Toggle this checkbox to enable the "Field settings" functionality. With this feature, you can change properties per field: classes, label and wrappers.'),
+ '#default_value' => variable_get('ds_extras_field_settings', FALSE),
+ );
+
$form['switch'] = array(
'#type' => 'fieldset',
- '#title' => t('Switch view modes'),
+ '#title' => t('Node switch view modes'),
);
$form['switch']['ds_extras_switch_view_mode'] = array(
@@ -131,10 +156,190 @@ function ds_extras_settings_submit($form, &$form_state) {
// Clear module_implements cache and rebuild menu.
cache_clear_all('entity_info:', 'cache', TRUE);
cache_clear_all('module_implements', 'cache_bootstrap');
+ cache_clear_all('theme_registry:', 'cache', TRUE);
menu_rebuild();
}
/**
+ * Implements hook_form_FORM_ID_alter().
+ */
+function ds_extras_form_ds_styles_form_alter(&$form, &$form_state) {
+ $form['ds_styles_fields'] = array(
+ '#type' => 'textarea',
+ '#title' => t('Styles for fields'),
+ '#default_value' => variable_get('ds_styles_fields', ''),
+ '#description' => t('Configure styles which you can add to fields on the "manage display" screens. Add multiple styles line per line.
If you want to have a friendly name, separate class and friendly name by |, but this is not required. eg:
class_name_1
class_name_2|Friendly name
class_name_3')
+ );
+}
+
+/**
+ * Implements hook_ds_field_settings_alter().
+ */
+function ds_extras_ds_field_settings_alter(&$field_settings, $form, $form_state) {
+
+ $fields = $form_state['values']['fields'];
+ foreach ($fields as $key => $field) {
+
+ // Make sure we need to save anything for this field.
+ if (_ds_field_valid($key, $field, $form_state)) {
+ continue;
+ }
+
+ // Get the values.
+ $values = $fields[$key]['format']['extra-fs'];
+
+ // Another label.
+ if (!empty($values['field_label']) && $fields[$key]['label'] != 'hidden') {
+ $field_settings[$key]['field_label'] = $values['field_label'];
+ }
+
+ // Remove all wrappers.
+ if ($values['remove_all_wrappers']) {
+ $field_settings[$key]['remove_all_wrappers'] = TRUE;
+ continue;
+ }
+
+ // Remove outer wrapper.
+ if ($values['remove_outer_wrapper']) {
+ $field_settings[$key]['remove_outer_wrapper'] = TRUE;
+ }
+ else {
+ // Remove default classes on outher div.
+ if ($values['classes_remove']) {
+ $field_settings[$key]['classes_remove'] = TRUE;
+ }
+
+ // Extra outer div classes, do not save empty field classes.
+ $classes = implode(' ', $values['outer_field_wrapper_classes']);
+ if (!empty($classes)) {
+ $field_settings[$key]['outer_field_wrapper_classes'] = $classes;
+ }
+ }
+
+ // Remove field-items wrapper
+ if (!empty($values['remove_field_items_wrapper'])) {
+ $field_settings[$key]['remove_field_items_wrapper'] = TRUE;
+ }
+
+ // Remove field wrapper
+ if (!empty($values['remove_field_wrapper'])) {
+ $field_settings[$key]['remove_field_wrapper'] = TRUE;
+ }
+ else {
+
+ // Extra field div classes, do not save empty field classes.
+ $classes = implode(' ', $values['field_wrapper_classes']);
+ if (!empty($classes)) {
+ $field_settings[$key]['field_wrapper_classes'] = $classes;
+ }
+
+ // Another wrapper.
+ if (!empty($values['field_wrapper'])) {
+ $field_settings[$key]['field_wrapper'] = $values['field_wrapper'];
+ }
+ }
+ }
+}
+
+/**
+ * Overriden function of theme_field().
+ */
+function theme_ds_field($variables) {
+
+ static $field_settings = array();
+ if (!isset($field_settings[$variables['element']['#entity_type']][$variables['element']['#bundle']][$variables['element']['#view_mode']])) {
+ $field_settings[$variables['element']['#entity_type']][$variables['element']['#bundle']][$variables['element']['#view_mode']] = ds_get_field_settings($variables['element']['#entity_type'], $variables['element']['#bundle'], $variables['element']['#view_mode']);
+ }
+
+ // Alter the theming of this field if it's found in the field settings.
+ $field_name = $variables['element']['#field_name'];
+ if (isset($field_settings[$variables['element']['#entity_type']][$variables['element']['#bundle']][$variables['element']['#view_mode']][$field_name])) {
+ $output = '';
+
+ // Get the configuration for this field.
+ $config = $field_settings[$variables['element']['#entity_type']][$variables['element']['#bundle']][$variables['element']['#view_mode']][$field_name];
+
+ // Render the label, if it's not hidden.
+ if (!$variables['label_hidden']) {
+ $label = $variables['label'];
+ // Alter the label if configured.
+ if (isset($config['field_label'])) {
+ $label = t(check_plain($config['field_label']));
+ }
+ $label = '
" . $body_field . "
+" . $body_field . "
+" . $body_field . "
+" . $body_field . "
+" . $body_field . "
+" . $body_field . "
+" . $body_field . "
+" . $body_field . "
"); + } } diff --git a/tests/ds_test.module b/tests/ds_test.module index 02fcc7c..1916227 100644 --- a/tests/ds_test.module +++ b/tests/ds_test.module @@ -11,6 +11,7 @@ function ds_test_install() { variable_set('ds_extras_region_to_block', TRUE); variable_set('ds_extras_switch_view_mode', TRUE); + variable_set('ds_extras_field_settings', TRUE); } /**