'radios',
'#title' => t('Default "Read more" link behaviour'),
'#default_value' => variable_get($key, $entity_type == 'node' ? 'always' : 'never'),
'#required' => TRUE,
'#options' => readmorecontrol_display_options($entity_type),
'#description' => t('This setting can be overridden by individual content types and fields. Note that most themes will link teaser titles to the node irrespective of these settings.'),
);
// Global and bundle based processing.
$key = 'readmorecontrol_format__' . $entity_type;
$form[$key] = array(
'#type' => 'fieldset',
'#title' => t('Global formatting settings'),
'#description' => t('Here you can specify the wording, appearance and position of the Read More Link globally.'),
'#tree' => TRUE,
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$settings = readmorecontrol_format_settings($entity_type, NULL, NULL, TRUE);
$form[$key] += readmorecontrol_formatting_settings_form($entity_type, $entity_info, $settings, $key);
unset($form[$key]['enabled']['#options']['global']);
return system_settings_form($form);
}
function readmorecontrol_formatting_settings_form($entity_type, $entity_info, $settings, $key) {
$subform['#attached']['css'] = array(
drupal_get_path('module', 'readmorecontrol') . '/readmorecontrol.css',
);
$subform['enabled'] = array(
'#type' => 'radios',
'#title' => t('Enable custom link processing'),
'#default_value' => $settings['enabled'],
'#options' => array(
'global' => t('Inherit default format settings'),
'none' => t('Do not modify'),
'custom' => t('Custom settings'),
),
);
$states = array(
'visible' => array(
':input[name$="' . $key . '[enabled]"]' => array('value' => 'custom'),
),
);
$subform['text'] = array(
'#type' => 'textfield',
'#title' => t('Link text'),
'#default_value' => $settings['text'],
'#states' => $states,
'#description' => t('Defaults to: "Read more<span class="element-invisible"> about @title</span>".
Replace "@title with" corresponding token, eg: "[node:title]"'),
'#attributes' => array('class' => array('readmorecontrol')),
);
$subform['href'] = array(
'#type' => 'textfield',
'#title' => t('URL'),
'#default_value' => $settings['href'],
'#states' => $states,
'#prefix' => '
Leave fields empty to use the system defaults. Tokens can be used in all text fields for the current %entity.
', array('%entity' => $entity_info['label'])), ); if (module_exists('token')) { $subform['help']['tokens'] = array( '#theme' => 'token_tree', '#token_types' => array($entity_type), '#recursion_limit' => 2, ); } return $subform; } /** * Implements hook_form_FORM_ID_alter(). */ function _readmorecontrol_form_field_ui_field_edit_form_alter(&$form, &$form_state, $form_id) { // Add readmore_behaviour flag to field_ui_field_edit_form to set fields // specific behaviour on the read more link (if applicable). $instance = $form['#instance']; $field = $form['#field']; $entity_type = $instance['entity_type']; if (readmorecontrol_supported_entity($entity_type)) { $form['instance']['readmore_behaviour'] = array( '#type' => 'radios', '#title' => t('Read More Behaviour'), '#default_value' => empty($instance['readmore_behaviour']) ? 'default' : $instance['readmore_behaviour'], '#options' => array( 'default' => t('Use the default behaviour'), 'process' => t('Check this field when determining the Read more link'), 'ignore' => t('Ignore this field when determining the Read more link'), ), '#weight' => -9, ); $usage_desc = array(); $info = entity_get_info($entity_type); $usage_desc[] = t('Display @view_mode: !usage', array( '@view_mode' => t('Default'), '!usage' => readmorecontrol_field_readmore_settings($field, $instance), )); $excluded = readmorecontrol_excluded_view_modes(); $excluded[] = 'full'; foreach($info['view modes'] as $view_mode => $view_mode_info) { if (!in_array($view_mode, $excluded)) { $usage_desc[] = t('Display @view_mode: !usage', array( '@view_mode' => $view_mode_info['label'], '!usage' => readmorecontrol_field_readmore_settings($field, $instance, $view_mode), )); } } $form['instance']['readmore_behaviour']['#description']= implode('These settings define the behaviours for all %label @content items. These can be overriden if you use custom display settings.
', $t_args); } else { $t_args['%display'] = $entity_info['view modes'][$view_mode]['label']; $disabled_modes = variable_get('readmorecontrol_disabled_view_modes', readmorecontrol_excluded_view_modes()); if ($view_mode == 'full' || in_array($view_mode, $disabled_modes)) { $fieldset['#description'] = t('Read more settings are not available on the %display display mode.
', $t_args); return; } else { $fieldset['#description'] = t('These settings define the behaviours for all %label @content items when viewed using the %display display settings.
', $t_args); } } $key = 'readmorecontrol_behaviour__' . $entity_type . '__' . $bundle . ($default ? '' : '__' . $view_mode); $fieldset[$key] = array( '#type' => 'radios', '#title' => t('Display Read More'), '#options' => readmorecontrol_display_options($entity_type, $bundle, $view_mode), '#default_value' => variable_get($key, 'default'), '#required' => TRUE, '#description' => t('Note that most themes will link to the main view irrespective of these settings.'), ); $key = 'readmorecontrol_format__' . $entity_type . '__' . $bundle . ($default ? '' : '__' . $view_mode); $fieldset[$key] = array( '#type' => 'fieldset', '#title' => t('Formatting settings'), '#description' => t('Here you can specify the wording, appearance and position of the Read More Link.'), '#collapsible' => TRUE, '#collapsed' => FALSE, '#tree' => TRUE, ); $settings = readmorecontrol_format_settings($entity_type, $bundle, $view_mode, TRUE); $fieldset[$key] += readmorecontrol_formatting_settings_form($entity_type, $entity_info, $settings, $key); if ($view_mode == 'search_result') { $fieldset[$key]['placement']['#options'] = array( 'search_snippet_inline' => t('Inline in the search results snippet'), 'search_snippet' => t('New line after the search results snippet'), 'search_info' => t('In the results info'), ); } $form['#submit'][] = 'readmorecontrol_form_field_ui_display_overview_form_alter_submit'; } function _readmorecontrol_form_field_ui_display_overview_form_alter_submit(&$form, &$form_state) { $entity_type = $form['#entity_type']; $bundle = $form['#bundle']; $view_mode = $form['#view_mode']; $default = $view_mode == 'default'; $key = 'readmorecontrol_behaviour__' . $entity_type . '__' . $bundle . ($default ? '' : '__' . $view_mode); if (isset($form_state['values'][$key])) { variable_set($key, $form_state['values'][$key]); } $key = 'readmorecontrol_format__' . $entity_type . '__' . $bundle . ($default ? '' : '__' . $view_mode); if (isset($form_state['values'][$key])) { variable_set($key, $form_state['values'][$key]); } } /** * Helper function to get the default display options. */ function readmorecontrol_display_options($entity_type, $bundle = NULL, $view_mode = NULL) { $entity_info = entity_get_info($entity_type); $options = array(); if (isset($bundle)) { $options['default'] = t('Inherit default behaviour'); } if ($entity_type == 'node') { $options += array( 'always' => t('Always show link