Commit 7cc3d92d authored by webchick's avatar webchick

#616240 follow-up by yched, dereine, marvil07: Make Field UI screens...

#616240 follow-up by yched, dereine, marvil07: Make Field UI screens extensible from contrib - part II.
parent 3b21e82a
......@@ -1560,6 +1560,8 @@ function theme_breadcrumb($variables) {
* associative array with the following keys:
* - "data": an array of cells
* - Any HTML attributes, such as "class", to apply to the table row.
* - "no_striping": a boolean indicating that the row should receive no
* 'even / odd' styling. Defaults to FALSE.
* Each cell can be either a string or an associative array with the
* following keys:
* - "data": The string to display in the table cell.
......@@ -1728,8 +1730,10 @@ function theme_table($variables) {
}
if (count($cells)) {
// Add odd/even class
$class = $flip[$class];
$attributes['class'][] = $class;
if (empty($row['no_striping'])) {
$class = $flip[$class];
$attributes['class'][] = $class;
}
// Build row
$output .= ' <tr' . drupal_attributes($attributes) . '>';
......@@ -1999,7 +2003,7 @@ function theme_indentation($variables) {
/**
* Returns HTML output for a single table cell for theme_table().
*
*
* @param $cell
* Array of cell information, or string to display in cell.
* @param bool $header
......
......@@ -1016,8 +1016,11 @@ Drupal.tableDrag.prototype.row.prototype.validIndentInterval = function (prevRow
minIndent = nextRow ? $('.indentation', nextRow).size() : 0;
// Maximum indentation:
if (!prevRow || $(this.element).is('.tabledrag-root')) {
// Do not indent the first row in the table or 'root' rows..
if (!prevRow || $(prevRow).is(':not(.draggable)') || $(this.element).is('.tabledrag-root')) {
// Do not indent:
// - the first row in the table,
// - rows dragged below a non-draggable row,
// - 'root' rows.
maxIndent = 0;
}
else {
......
......@@ -2065,6 +2065,33 @@ function hook_field_storage_pre_update($entity_type, $entity, &$skip_fields) {
}
}
/**
* Returns the maximum weight for the entity components handled by the module.
*
* Field API takes care of fields and 'extra_fields'. This hook is intended for
* third-party modules adding other entity components (e.g. field_group).
*
* @param $entity_type
* The type of entity; e.g. 'node' or 'user'.
* @param $bundle
* The bundle name.
* @param $context
* The context for which the maximum weight is requested. Either 'form', or
* the name of a view mode.
* @return
* The maximum weight of the entity's components, or NULL if no components
* were found.
*/
function hook_field_info_max_weight($entity_type, $bundle, $context) {
$weights = array();
foreach (my_module_entity_additions($entity_type, $bundle, $context) as $addition) {
$weights[] = $addition['weight'];
}
return $weights ? max($weights) : NULL;
}
/**
* Alters the display settings of a field before it gets displayed.
*
......
......@@ -761,16 +761,8 @@ function _field_write_instance($instance, $update = FALSE) {
);
// If no weight specified, make sure the field sinks at the bottom.
if (!isset($instance['widget']['weight'])) {
$weights = array();
foreach (field_info_instances($instance['entity_type'], $instance['bundle']) as $existing_instance) {
if ($instance['field_name'] != $existing_instance['field_name']) {
$weights[] = $existing_instance['widget']['weight'];
}
}
foreach (field_info_extra_fields($instance['entity_type'], $instance['bundle'], 'form') as $extra) {
$weights[] = $extra['weight'];
}
$instance['widget']['weight'] = $weights ? max($weights) + 1 : 0;
$max_weight = field_info_max_weight($instance['entity_type'], $instance['bundle'], 'form');
$instance['widget']['weight'] = !is_null($max_weight) ? $max_weight + 1 : 0;
}
// Check widget module.
$widget_type = field_info_widget_types($instance['widget']['type']);
......@@ -795,16 +787,8 @@ function _field_write_instance($instance, $update = FALSE) {
}
// If no weight specified, make sure the field sinks at the bottom.
if (!isset($display['weight'])) {
$weights = array();
foreach (field_info_instances($instance['entity_type'], $instance['bundle']) as $existing_instance) {
if ($instance['field_name'] != $existing_instance['field_name']) {
$weights[] = $existing_instance['display'][$view_mode]['weight'];
}
}
foreach (field_info_extra_fields($instance['entity_type'], $instance['bundle'], 'display') as $extra) {
$weights[] = $extra['display'][$view_mode]['weight'];
}
$display['weight'] = $weights ? max($weights) + 1 : 0;
$max_weight = field_info_max_weight($instance['entity_type'], $instance['bundle'], $view_mode);
$display['weight'] = !is_null($max_weight) ? $max_weight + 1 : 0;
}
$instance['display'][$view_mode] = $display;
}
......
......@@ -760,6 +760,47 @@ function field_info_extra_fields($entity_type, $bundle, $context) {
return array();
}
/**
* Returns the maximum weight of all the components in an entity.
*
* This includes fields, 'extra_fields', and other components added by
* third-party modules (e.g. field_group).
*
* @param $entity_type
* The type of entity; e.g. 'node' or 'user'.
* @param $bundle
* The bundle name.
* @param $context
* The context for which the maximum weight is requested. Either 'form', or
* the name of a view mode.
* @return
* The maximum weight of the entity's components, or NULL if no components
* were found.
*/
function field_info_max_weight($entity_type, $bundle, $context) {
$weights = array();
// Collect weights for fields.
foreach (field_info_instances($entity_type, $bundle) as $instance) {
if ($context == 'form') {
$weights[] = $instance['widget']['weight'];
}
else {
$weights[] = $instance['display'][$context]['weight'];
}
}
// Collect weights for extra fields.
foreach (field_info_extra_fields($entity_type, $bundle, $context) as $extra) {
$weights[] = $extra['weight'];
}
// Let other modules feedback about their own additions.
$weights = array_merge($weights, module_invoke_all('field_info_max_weight', $entity_type, $bundle, $context));
$max_weight = $weights ? max($weights) : NULL;
return $max_weight;
}
/**
* Returns a field type's default settings.
*
......
<?php
// $Id$
/**
* @file
* Default theme implementation to configure field display settings.
*
* Available variables:
* - $rows: The field display settings form broken down into rendered rows for
* printing as a table. The array is separated in two entries, 'visible' and
* 'hidden'.
* - $id: The HTML id for the table.
*
* @see field_ui_display_overview_form()
* @see template_preprocess_field_ui_display_overview_table()
*/
?>
<?php if ($rows): ?>
<div id="field-display-overview-wrapper">
<table id="field-display-overview" class="field-display-overview sticky-enabled">
<thead>
<tr>
<th><?php print t('Field'); ?></th>
<th><?php print t('Weight'); ?></th>
<th><?php print t('Label'); ?></th>
<th colspan="3"><?php print t('Format'); ?></th>
</tr>
</thead>
<tbody>
<tr class="region-message region-visible-message <?php print empty($rows['visible']) ? 'region-empty' : 'region-populated'; ?>">
<td colspan="5"><em><?php print t('No field is displayed'); ?></em></td>
</tr>
<?php
$count = 0;
foreach ($rows['visible'] as $row): ?>
<tr id="<?php print $row->id; ?>" class="<?php print $count % 2 == 0 ? 'odd' : 'even'; ?> <?php print $row->class ?>">
<td><span class="<?php print $row->label_class; ?>"><?php print $row->human_name; ?></span></td>
<td><?php print $row->weight . $row->hidden_name; ?></td>
<td><?php if (isset($row->label)) print $row->label; ?></td>
<?php if (isset($row->settings_edit_form)) : ?>
<td colspan="3">
<?php print $row->type; ?>
<?php print $row->settings_edit_form; ?>
</td>
<?php else :?>
<td>
<?php print $row->type; ?>
</td>
<td class="field-formatter-summary-cell">
<?php print $row->settings_summary; ?>
</td>
<td>
<?php print $row->settings_edit; ?>
</td>
<?php endif; ?>
</tr>
<?php $count++;
endforeach; ?>
<tr class="region-title region-title-hidden">
<td colspan="5"><?php print t('Hidden'); ?></td>
</tr>
<tr class="region-message region-hidden-message <?php print empty($rows['hidden']) ? 'region-empty' : 'region-populated'; ?>">
<td colspan="5"><em><?php print t('No field is hidden'); ?></em></td>
</tr>
<?php foreach ($rows['hidden'] as $row): ?>
<tr class="<?php print $count % 2 == 0 ? 'odd' : 'even'; ?> <?php print $row->class ?>">
<td><span class="<?php print $row->label_class; ?>"><?php print $row->human_name; ?></span></td>
<td><?php print $row->weight . $row->hidden_name; ?></td>
<td><?php if (isset($row->label)) print $row->label; ?></td>
<td><?php print $row->type; ?></td>
<td class="field-formatter-summary-cell">
<?php print $row->settings_summary; ?>
</td>
<td>
<?php print $row->settings_edit; ?>
</td>
</tr>
<?php $count++;
endforeach; ?>
</tbody>
</table>
</div>
<?php endif; ?>
/* $Id$ */
/* 'Manage fields' overview */
#field-overview tr.add-new .label-input {
table.field-ui-overview tr.add-new .label-input {
float: right;
}
This diff is collapsed.
/* $Id$ */
/* 'Manage fields' overview */
#field-overview tr.add-new .label-input {
/* 'Manage fields' and 'Manage display' overviews */
table.field-ui-overview tr.add-new .label-input {
float: left; /* LTR */
}
#field-overview tr.add-new .tabledrag-changed {
table.field-ui-overview tr.add-new .tabledrag-changed {
display: none;
}
#field-overview tr.add-new .description {
table.field-ui-overview tr.add-new .description {
margin-bottom: 0;
}
#field-overview tr.add-new .add-new-placeholder {
table.field-ui-overview tr.add-new .add-new-placeholder {
font-weight: bold;
padding-bottom: .5em;
}
table.field-ui-overview tr.region-add-new-title {
display: none;
}
/* 'Manage display' overview */
.field-display-overview tr.region-title td {
#field-display-overview tr.region-title td {
font-weight: bold;
}
.field-display-overview tr.region-populated {
#field-display-overview tr.region-message td {
font-style: italic;
}
#field-display-overview tr.region-populated {
display: none;
}
.field-display-overview .field-formatter-summary-cell {
#field-display-overview .field-formatter-summary-cell {
line-height: 1em;
}
.field-display-overview .field-formatter-summary {
#field-display-overview .field-formatter-summary {
float: left;
font-size: 0.9em;
}
.field-display-overview td.field-formatter-summary-cell span.warning {
#field-display-overview td.field-formatter-summary-cell span.warning {
display: block;
float: left;
margin-right: .5em;
}
.field-display-overview .field-formatter-settings-edit-wrapper {
#field-display-overview .field-formatter-settings-edit-wrapper {
float: right;
}
.field-display-overview .field-formatter-settings-edit {
#field-display-overview .field-formatter-settings-edit {
float: right;
}
.field-display-overview tr.field-formatter-settings-editing td {
#field-display-overview tr.field-formatter-settings-editing td {
vertical-align: top;
}
.field-display-overview tr.field-formatter-settings-editing .field-formatter-type {
#field-display-overview tr.field-formatter-settings-editing .field-formatter-type {
display: none;
}
.field-display-overview .field-formatter-settings-edit-form .formatter-name{
#field-display-overview .field-formatter-settings-edit-form .formatter-name{
font-weight: bold;
}
\ No newline at end of file
}
#field-ui-display-overview-form #edit-refresh {
display:none;
}
This diff is collapsed.
......@@ -275,11 +275,6 @@ function _field_ui_view_mode_menu_access($entity_type, $bundle, $view_mode, $acc
*/
function field_ui_theme() {
return array(
'field_ui_display_overview_table' => array(
'render element' => 'elements',
'file' => 'field_ui.admin.inc',
'template' => 'field_ui-display-overview-table',
),
'field_ui_table' => array(
'render element' => 'elements',
),
......@@ -291,8 +286,10 @@ function field_ui_theme() {
*/
function field_ui_element_info() {
return array(
'table' => array(
'field_ui_table' => array(
'#theme' => 'field_ui_table',
'#pre_render' => array('field_ui_table_pre_render'),
'#regions' => array('' => array()),
),
);
}
......
......@@ -85,8 +85,8 @@ class FieldUITestCase extends DrupalWebTestCase {
function createField() {
// Create a test field.
$edit = array(
'_add_new_field[label]' => $this->field_label,
'_add_new_field[field_name]' => $this->field_name_input,
'fields[_add_new_field][label]' => $this->field_label,
'fields[_add_new_field][field_name]' => $this->field_name_input,
);
$this->fieldUIAddNewField('admin/structure/types/manage/' . $this->hyphen_type, $edit);
......@@ -95,7 +95,7 @@ class FieldUITestCase extends DrupalWebTestCase {
// should also appear in the 'taxonomy term' entity.
$vocabulary = taxonomy_vocabulary_load(1);
$this->drupalGet('admin/structure/taxonomy/' . $vocabulary->machine_name . '/fields');
$this->assertTrue($this->xpath('//select[@name="_add_existing_field[field_name]"]//option[@value="' . $this->field_name . '"]'), t('Existing field was found in account settings.'));
$this->assertTrue($this->xpath('//select[@name="fields[_add_existing_field][field_name]"]//option[@value="' . $this->field_name . '"]'), t('Existing field was found in account settings.'));
}
/**
......@@ -136,8 +136,8 @@ class FieldUITestCase extends DrupalWebTestCase {
// Add a new field based on an existing field.
$edit = array(
'_add_existing_field[label]' => $this->field_label . '_2',
'_add_existing_field[field_name]' => $this->field_name,
'fields[_add_existing_field][label]' => $this->field_label . '_2',
'fields[_add_existing_field][field_name]' => $this->field_name,
);
$this->fieldUIAddExistingField("admin/structure/types/manage/page", $edit);
}
......@@ -224,8 +224,8 @@ class FieldUITestCase extends DrupalWebTestCase {
// Create a new field.
$bundle_path1 = 'admin/structure/types/manage/' . $this->hyphen_type;
$edit1 = array(
'_add_new_field[label]' => $this->field_label,
'_add_new_field[field_name]' => $this->field_name,
'fields[_add_new_field][label]' => $this->field_label,
'fields[_add_new_field][field_name]' => $this->field_name,
);
$this->fieldUIAddNewField($bundle_path1, $edit1);
......@@ -238,8 +238,8 @@ class FieldUITestCase extends DrupalWebTestCase {
// Add an instance to the second node type.
$bundle_path2 = 'admin/structure/types/manage/' . $hyphen_type2;
$edit2 = array(
'_add_existing_field[label]' => $this->field_label,
'_add_existing_field[field_name]' => $this->field_name,
'fields[_add_existing_field][label]' => $this->field_label,
'fields[_add_existing_field][field_name]' => $this->field_name,
);
$this->fieldUIAddExistingField($bundle_path2, $edit2);
......@@ -317,11 +317,11 @@ class FieldUITestCase extends DrupalWebTestCase {
function fieldUIAddNewField($bundle_path, $initial_edit, $field_edit = array(), $instance_edit = array()) {
// Use 'test_field' field type by default.
$initial_edit += array(
'_add_new_field[type]' => 'test_field',
'_add_new_field[widget_type]' => 'test_field_widget',
'fields[_add_new_field][type]' => 'test_field',
'fields[_add_new_field][widget_type]' => 'test_field_widget',
);
$label = $initial_edit['_add_new_field[label]'];
$field_name = $initial_edit['_add_new_field[field_name]'];
$label = $initial_edit['fields[_add_new_field][label]'];
$field_name = $initial_edit['fields[_add_new_field][field_name]'];
// First step : 'Add new field' on the 'Manage fields' page.
$this->drupalPost("$bundle_path/fields", $initial_edit, t('Save'));
......@@ -357,10 +357,10 @@ class FieldUITestCase extends DrupalWebTestCase {
function fieldUIAddExistingField($bundle_path, $initial_edit, $instance_edit = array()) {
// Use 'test_field_widget' by default.
$initial_edit += array(
'_add_existing_field[widget_type]' => 'test_field_widget',
'fields[_add_existing_field][widget_type]' => 'test_field_widget',
);
$label = $initial_edit['_add_existing_field[label]'];
$field_name = $initial_edit['_add_existing_field[field_name]'];
$label = $initial_edit['fields[_add_existing_field][label]'];
$field_name = $initial_edit['fields[_add_existing_field][field_name]'];
// First step : 'Add existing field' on the 'Manage fields' page.
$this->drupalPost("$bundle_path/fields", $initial_edit, t('Save'));
......
......@@ -316,10 +316,10 @@ class FileFieldWidgetTestCase extends FileFieldTestCase {
// Create a new field.
$edit = array(
'_add_new_field[label]' => $label = $this->randomName(),
'_add_new_field[field_name]' => $name = strtolower($this->randomName()),
'_add_new_field[type]' => 'file',
'_add_new_field[widget_type]' => 'file_generic',
'fields[_add_new_field][label]' => $label = $this->randomName(),
'fields[_add_new_field][field_name]' => $name = strtolower($this->randomName()),
'fields[_add_new_field][type]' => 'file',
'fields[_add_new_field][widget_type]' => 'file_generic',
);
$this->drupalPost('admin/structure/types/manage/article/comment/fields', $edit, t('Save'));
$edit = array('field[settings][uri_scheme]' => 'private');
......@@ -347,7 +347,7 @@ class FileFieldWidgetTestCase extends FileFieldTestCase {
// Log in as normal user.
$this->drupalLogin($user);
$comment = comment_load($cid);
$comment_file = (object) $comment->{'field_' . $name}[LANGUAGE_NONE][0];
$this->assertFileExists($comment_file, t('New file saved to disk on node creation.'));
......@@ -356,7 +356,7 @@ class FileFieldWidgetTestCase extends FileFieldTestCase {
$this->assertNotEqual($url, NULL, t('Confirmed that the URL is valid'));
$this->drupalGet(file_create_url($comment_file->uri));
$this->assertResponse(200, t('Confirmed that the generated URL is correct by downloading the shipped file.'));
// Test anonymous file download.
$this->drupalLogout();
$this->drupalGet(file_create_url($comment_file->uri));
......
......@@ -934,23 +934,23 @@ div.add-or-remove-shortcuts {
/* Field UI */
.field-display-overview input.field-formatter-settings-edit {
#field-display-overview input.field-formatter-settings-edit {
margin: 0;
padding: 1px 8px;
}
.field-display-overview tr.field-formatter-settings-changed {
#field-display-overview tr.field-formatter-settings-changed {
background: #FFFFBB;
}
.field-display-overview tr.drag {
#field-display-overview tr.drag {
background: #FFEE77;
}
.field-display-overview tr.field-formatter-settings-editing {
#field-display-overview tr.field-formatter-settings-editing {
background: #D5E9F2;
}
.field-display-overview .field-formatter-settings-edit-form .form-item {
#field-display-overview .field-formatter-settings-edit-form .form-item {
margin: 10px 0;
}
.field-display-overview .field-formatter-settings-edit-form .form-submit {
#field-display-overview .field-formatter-settings-edit-form .form-submit {
margin-bottom: 0;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment