diff --git a/core/modules/field_ui/field_ui.admin.inc b/core/modules/field_ui/field_ui.admin.inc index 58aee91..2804657 100644 --- a/core/modules/field_ui/field_ui.admin.inc +++ b/core/modules/field_ui/field_ui.admin.inc @@ -58,99 +58,6 @@ function field_ui_fields_list() { } /** - * Determines the rendering order of an array representing a tree. - * - * Callback for array_reduce() within field_ui_table_pre_render(). - */ -function _field_ui_reduce_order($array, $a) { - $array = !isset($array) ? array() : $array; - if ($a['name']) { - $array[] = $a['name']; - } - if (!empty($a['children'])) { - uasort($a['children'], 'drupal_sort_weight'); - $array = array_merge($array, array_reduce($a['children'], '_field_ui_reduce_order')); - } - return $array; -} - -/** - * Render API callback: Performs pre-render tasks on field_ui_table elements. - * - * This function is assigned as a #pre_render callback in - * field_ui_element_info(). - * - * @see drupal_render(). - */ -function field_ui_table_pre_render($elements) { - $js_settings = array(); - - // For each region, build the tree structure from the weight and parenting - // data contained in the flat form structure, to determine row order and - // indentation. - $regions = $elements['#regions']; - $tree = array('' => array('name' => '', 'children' => array())); - $trees = array_fill_keys(array_keys($regions), $tree); - - $parents = array(); - $list = drupal_map_assoc(element_children($elements)); - - // Iterate on rows until we can build a known tree path for all of them. - while ($list) { - foreach ($list as $name) { - $row = &$elements[$name]; - $parent = $row['parent_wrapper']['parent']['#value']; - // Proceed if parent is known. - if (empty($parent) || isset($parents[$parent])) { - // Grab parent, and remove the row from the next iteration. - $parents[$name] = $parent ? array_merge($parents[$parent], array($parent)) : array(); - unset($list[$name]); - - // Determine the region for the row. - $region_name = call_user_func($row['#region_callback'], $row); - - // Add the element in the tree. - $target = &$trees[$region_name]['']; - foreach ($parents[$name] as $key) { - $target = &$target['children'][$key]; - } - $target['children'][$name] = array('name' => $name, 'weight' => $row['weight']['#value']); - - // Add tabledrag indentation to the first row cell. - if ($depth = count($parents[$name])) { - $children = element_children($row); - $cell = current($children); - $row[$cell]['#prefix'] = theme('indentation', array('size' => $depth)) . (isset($row[$cell]['#prefix']) ? $row[$cell]['#prefix'] : ''); - } - - // Add row id and associate JS settings. - $id = drupal_html_class($name); - $row['#attributes']['id'] = $id; - if (isset($row['#js_settings'])) { - $row['#js_settings'] += array( - 'rowHandler' => $row['#row_type'], - 'name' => $name, - 'region' => $region_name, - ); - $js_settings[$id] = $row['#js_settings']; - } - } - } - } - // Determine rendering order from the tree structure. - foreach ($regions as $region_name => $region) { - $elements['#regions'][$region_name]['rows_order'] = array_reduce($trees[$region_name], '_field_ui_reduce_order'); - } - - $elements['#attached']['js'][] = array( - 'type' => 'setting', - 'data' => array('fieldUIRowsData' => $js_settings), - ); - - return $elements; -} - -/** * Returns HTML for Field UI overview tables. * * @param $variables @@ -231,21 +138,3 @@ function theme_field_ui_table($variables) { return theme('table', $table); } - -/** - * Render API callback: Checks if a field machine name is taken. - * - * @param $value - * The machine name, not prefixed with 'field_'. - * - * @return - * Whether or not the field machine name is taken. - */ -function _field_ui_field_name_exists($value) { - // Prefix with 'field_'. - $field_name = 'field_' . $value; - - // We need to check inactive fields as well, so we can't use - // field_info_fields(). - return (bool) field_read_fields(array('field_name' => $field_name), array('include_inactive' => TRUE)); -} diff --git a/core/modules/field_ui/field_ui.module b/core/modules/field_ui/field_ui.module index cce8734..f9aefe3 100644 --- a/core/modules/field_ui/field_ui.module +++ b/core/modules/field_ui/field_ui.module @@ -237,7 +237,6 @@ function field_ui_element_info() { return array( 'field_ui_table' => array( '#theme' => 'field_ui_table', - '#pre_render' => array('field_ui_table_pre_render'), '#regions' => array('' => array()), ), ); @@ -262,40 +261,6 @@ function field_ui_entity_bundle_rename($entity_type, $bundle_old, $bundle_new) { } /** - * Identifies inactive fields within a bundle. - */ -function field_ui_inactive_instances($entity_type, $bundle_name = NULL) { - $params = array('entity_type' => $entity_type); - - if (empty($bundle_name)) { - $active = field_info_instances($entity_type); - $inactive = array(); - } - else { - // Restrict to the specified bundle. For consistency with the case where - // $bundle_name is NULL, the $active and $inactive arrays are keyed by - // bundle name first. - $params['bundle'] = $bundle_name; - $active = array($bundle_name => field_info_instances($entity_type, $bundle_name)); - $inactive = array($bundle_name => array()); - } - - // Iterate on existing definitions, and spot those that do not appear in the - // $active list collected earlier. - $all_instances = field_read_instances($params, array('include_inactive' => TRUE)); - foreach ($all_instances as $instance) { - if (!isset($active[$instance['bundle']][$instance['field_name']])) { - $inactive[$instance['bundle']][$instance['field_name']] = $instance; - } - } - - if (!empty($bundle_name)) { - return $inactive[$bundle_name]; - } - return $inactive; -} - -/** * Implements hook_form_FORM_ID_alter(). * * Adds a button 'Save and manage fields' to the 'Create content type' form. diff --git a/core/modules/field_ui/lib/Drupal/field_ui/DisplayOverview.php b/core/modules/field_ui/lib/Drupal/field_ui/DisplayOverview.php index 4ae46ef..cc699a6 100644 --- a/core/modules/field_ui/lib/Drupal/field_ui/DisplayOverview.php +++ b/core/modules/field_ui/lib/Drupal/field_ui/DisplayOverview.php @@ -104,6 +104,7 @@ public function buildForm(array $form, array &$form_state, $entity_type = NULL, $table = array( '#type' => 'field_ui_table', + '#pre_render' => array(array($this, 'tablePreRender')), '#tree' => TRUE, '#header' => array( t('Field'), @@ -612,7 +613,13 @@ public function multistepAjax($form, &$form_state) { } /** - * {@inheritdoc} + * Returns the region to which a row in the display overview belongs. + * + * @param array $row + * The row element. + * + * @return string|null + * The region name this row belongs to. */ public function getRowRegion($row) { switch ($row['#row_type']) { diff --git a/core/modules/field_ui/lib/Drupal/field_ui/FieldOverview.php b/core/modules/field_ui/lib/Drupal/field_ui/FieldOverview.php index 74d4d3d..ead0fb6 100644 --- a/core/modules/field_ui/lib/Drupal/field_ui/FieldOverview.php +++ b/core/modules/field_ui/lib/Drupal/field_ui/FieldOverview.php @@ -101,6 +101,7 @@ public function buildForm(array $form, array &$form_state, $entity_type = NULL, $table = array( '#type' => 'field_ui_table', + '#pre_render' => array(array($this, 'tablePreRender')), '#tree' => TRUE, '#header' => array( t('Label'), @@ -242,25 +243,25 @@ public function buildForm(array $form, array &$form_state, $entity_type = NULL, // Additional row: add new field. $max_weight = $entity_form_display->getHighestWeight(); + + // Prepare the widget types to be display as options. $widget_options = $this->widgetManager->getWidgetOptions(); + $widget_type_options = array(); + foreach ($widget_options as $field_type => $widgets) { + $widget_type_options[$field_types[$field_type]['label']] = $widgets; + } // Gather valid field types. $field_type_options = array(); foreach ($field_types as $name => $field_type) { - // Skip field types which have no widget types, or should not be add via - // uesr interface. + // Skip field types which have no widget types, or should not be added via + // user interface. if (isset($widget_options[$name]) && empty($field_type['no_ui'])) { $field_type_options[$name] = $field_type['label']; } } asort($field_type_options); - // Prepare the widget types to be display as options. - $widget_type_options = array(); - foreach ($widget_options as $field_type => $widgets) { - $widget_type_options[$field_types[$field_type]['label']] = $widgets; - } - if ($field_type_options && $widget_type_options) { $name = '_add_new_field'; $table[$name] = array( @@ -316,7 +317,7 @@ public function buildForm(array $form, array &$form_state, $entity_type = NULL, '#prefix' => '