You are here

function readmorecontrol_field_readmore_settings in Read More Control 7

Helper function to explain how the current instance setting would be used.

1 call to readmorecontrol_field_readmore_settings()
_readmorecontrol_form_field_ui_field_edit_form_alter in ./readmorecontrol.admin.inc
Implements hook_form_FORM_ID_alter().

File

./readmorecontrol.admin.inc, line 230
Contains form alter callback bodies.

Code

function readmorecontrol_field_readmore_settings($field, $instance, $view_mode = 0) {
  $bundle = $instance['bundle'];
  $entity_type = $instance['entity_type'];
  $system_default = $entity_type == 'node' ? 'always' : 'never';
  $entity_default = variable_get('readmorecontrol_behaviour__' . $entity_type, $system_default);
  $bundle_default = variable_get("readmorecontrol_behaviour__{$entity_type}__{$bundle}", $entity_default);
  $t_args = array();
  if ($view_mode) {
    $view_default = variable_get("readmorecontrol_behaviour__{$entity_type}__{$bundle}__{$view_mode}", $bundle_default);
    if ($view_default != 'default') {
      $actual_behaviour = $view_default;
      $t_args['!settings_source'] = t('display');
    }
    elseif ($bundle_default != 'default') {
      $actual_behaviour = $bundle_default;
      $t_args['!settings_source'] = t('default display');
    }
    else {
      $actual_behaviour = $entity_default;
      $t_args['!settings_source'] = t('entity');
    }
  }
  else {
    if ($bundle_default != 'default') {
      $actual_behaviour = $bundle_default;
      $t_args['!settings_source'] = t('default display');
    }
    else {
      $actual_behaviour = $entity_default;
      $t_args['!settings_source'] = t('entity');
    }
  }
  $output = '';
  switch ($actual_behaviour) {
    case 'always':
      $t_args['%behaviour'] = t('always show');
      break;
    case 'when_required':
      $t_args['%behaviour'] = t('conditionally show based on any field');
      break;
    case 'when_required_text':
      $t_args['%behaviour'] = t('conditionally show based on any text fields');
      break;
    case 'when_required_body':
      $t_args['%behaviour'] = t('conditionally show based on the body field');
      break;
    case 'never':
      $t_args['%behaviour'] = t('never show link');
      break;
    case 'none':
      $t_args['%behaviour'] = t('disabled');
      break;
  }
  $output .= ' ' . t('set to "%behaviour" using <strong>!settings_source</strong> settings.', $t_args);
  return $output;
}