Commit 699680d2 authored by catch's avatar catch

Issue #1792600 by Stalski, fubhy, swentel: Refactor field_ui() so common...

Issue #1792600 by Stalski, fubhy, swentel: Refactor field_ui() so common behavior for fields and display overview screens are extracted.
parent 6323f118
This diff is collapsed.
......@@ -300,7 +300,7 @@ Drupal.fieldUIDisplayOverview.field.prototype = {
* Returns the region corresponding to the current form values of the row.
*/
getRegion: function () {
return (this.$formatSelect.val() === 'hidden') ? 'hidden' : 'visible';
return (this.$formatSelect.val() === 'hidden') ? 'hidden' : 'content';
},
/**
......@@ -326,7 +326,9 @@ Drupal.fieldUIDisplayOverview.field.prototype = {
// to the new region.
var currentValue = this.$formatSelect.val();
var value;
if (region === 'visible') {
// @TODO Check if this couldn't just be like
// if (region !== 'hidden') {
if (region === 'content') {
if (currentValue === 'hidden') {
// Restore the formatter back to the default formatter. Pseudo-fields do
// not have default formatters, we just return to 'visible' for those.
......
......@@ -103,8 +103,8 @@ function field_ui_menu() {
$items["$path/fields"] = array(
'title' => 'Manage fields',
'page callback' => 'drupal_get_form',
'page arguments' => array('field_ui_field_overview_form', $entity_type, $bundle_arg),
'page callback' => 'field_ui_field_overview',
'page arguments' => array($entity_type, $bundle_arg),
'type' => MENU_LOCAL_TASK,
'weight' => 1,
'file' => 'field_ui.admin.inc',
......@@ -154,8 +154,8 @@ function field_ui_menu() {
// 'Manage display' tab.
$items["$path/display"] = array(
'title' => 'Manage display',
'page callback' => 'drupal_get_form',
'page arguments' => array('field_ui_display_overview_form', $entity_type, $bundle_arg, 'default'),
'page callback' => 'field_ui_display_overview',
'page arguments' => array($entity_type, $bundle_arg, 'default'),
'type' => MENU_LOCAL_TASK,
'weight' => 2,
'file' => 'field_ui.admin.inc',
......@@ -173,7 +173,8 @@ function field_ui_menu() {
foreach ($view_modes as $view_mode => $view_mode_info) {
$items["$path/display/$view_mode"] = array(
'title' => $view_mode_info['label'],
'page arguments' => array('field_ui_display_overview_form', $entity_type, $bundle_arg, $view_mode),
'page callback' => 'field_ui_display_overview',
'page arguments' => array($entity_type, $bundle_arg, $view_mode),
// The access callback needs to check both the current 'custom
// display' setting for the view mode, and the overall access
// rules for the bundle admin pages.
......
This diff is collapsed.
This diff is collapsed.
<?php
/**
* @file
* Definition of Drupal\field_ui\OverviewBase.
*/
namespace Drupal\field_ui;
/**
* Abstract base class for Field UI overview forms.
*/
abstract class OverviewBase {
/**
* The name of the entity type.
*
* @var string
*/
protected $entity_type = '';
/**
* The entity bundle.
*
* @var string
*/
protected $bundle = '';
/**
* The entity view mode.
*
* @var string
*/
protected $view_mode = '';
/**
* The admin path of the overview page.
*
* @var string
*/
protected $adminPath = NULL;
/**
* Constructs the overview object for a entity type, bundle and view mode.
*
* @param string $entity_type
* The entity type.
* @param string $bundle
* The bundle for the entity of entity_type.
* @param string $view_mode
* (optional) The view mode for the entity which takes a string or
* "default".
*/
public function __construct($entity_type, $bundle, $view_mode = NULL) {
$this->entity_type = $entity_type;
$this->bundle = $bundle;
$this->view_mode = (isset($view_mode) ? $view_mode : 'default');
$this->adminPath = _field_ui_bundle_admin_path($this->entity_type, $this->bundle);
}
/**
* Creates a field UI overview form.
*
* @param array $form
* An associative array containing the structure of the form.
* @param array $form_state
* A reference to a keyed array containing the current state of the form.
*
* @return array
* The array containing the complete form.
*/
public function form(array $form, array &$form_state) {
// Add the validate and submit behavior.
$form['#validate'] = array(array($this, 'validate'));
$form['#submit'] = array(array($this, 'submit'));
return $form;
}
/**
* Validate handler for the field UI overview form.
*
* @param array $form
* The root element or form.
* @param array $form_state
* The state of the form.
*/
public function validate(array $form, array &$form_state) {
}
/**
* Submit handler for the field UI overview form.
*
* @param array $form
* An associative array containing the structure of the form.
* @param array $form_state
* A reference to a keyed array containing the current state of the form.
*/
public function submit(array $form, array &$form_state) {
}
/**
* Get the regions needed to create the overview form.
*
* @return array
* Example usage:
* @code
* return array(
* 'content' => array(
* // label for the region.
* 'title' => t('Content'),
* // Indicates if the region is visible in the UI.
* 'invisible' => TRUE,
* // A mesage to indicate that there is nothing to be displayed in
* // the region.
* 'message' => t('No field is displayed.'),
* ),
* );
* @endcode
*/
abstract public function getRegions();
/**
* Returns an associative array of all regions.
*/
public function getRegionOptions() {
$options = array();
foreach ($this->getRegions() as $region => $data) {
$options[$region] = $data['title'];
}
return $options;
}
}
......@@ -118,11 +118,11 @@ function testLanguageFieldVisibility() {
// Changes Language field visibility to true and check if it is saved.
$edit = array(
'fields[language][type]' => 'visible',
'fields[language][type]' => 'content',
);
$this->drupalPost('admin/structure/types/manage/article/display', $edit, t('Save'));
$this->drupalGet('admin/structure/types/manage/article/display');
$this->assertOptionSelected('edit-fields-language-type', 'visible', 'Language field has been set to visible.');
$this->assertOptionSelected('edit-fields-language-type', 'content', 'Language field has been set to visible.');
// Loads node page and check if Language field is shown.
$this->drupalGet('node/' . $node->nid);
......
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