diff --git a/core/modules/field_ui/field_ui.admin.inc b/core/modules/field_ui/field_ui.admin.inc
index d73ffac..a9a61d1 100644
--- a/core/modules/field_ui/field_ui.admin.inc
+++ b/core/modules/field_ui/field_ui.admin.inc
@@ -292,31 +292,6 @@ function theme_field_ui_table($variables) {
}
/**
- * Returns the built and processed 'Manage fields' form of a bundle.
- *
- * The resulting form allows fields and pseudo-fields to be re-ordered.
- *
- * @param string $entity_type
- * The entity type for the fieldable entity.
- * @param string $bundle
- * The bundle for the fieldable entity.
- *
- * @return
- * The processed form for the given entity type and bundle.
- *
- * @see field_ui_menu()
- * @see Drupal\field_ui\FieldOverview::validate()
- * @see Drupal\field_ui\FieldOverview::submit()
- * @ingroup forms
- */
-function field_ui_field_overview($entity_type, $bundle) {
- $bundle = field_extract_bundle($entity_type, $bundle);
- field_ui_inactive_message($entity_type, $bundle);
-
- return drupal_get_form(new FieldOverview($entity_type, $bundle));
-}
-
-/**
* Render API callback: Checks if a field machine name is taken.
*
* @param $value
@@ -335,33 +310,6 @@ function _field_ui_field_name_exists($value) {
}
/**
- * Returns the built and processed 'Manage display' form of a bundle.
- *
- * The resulting form allows fields and pseudo-fields to be re-ordered.
- *
- * @param string $entity_type
- * The entity type for the fieldable entity.
- * @param string $bundle
- * The bundle for the fieldable entity.
- * @param string $view_mode
- * The view mode for the fieldable entity.
- *
- * @return
- * The processed form for the given entity type and bundle.
- *
- * @see field_ui_menu()
- * @see field_ui_display_overview_multistep_submit()
- * @see Drupal\field_ui\DisplayOverview::submit()
- * @ingroup forms
- */
-function field_ui_display_overview($entity_type, $bundle, $view_mode) {
- $bundle = field_extract_bundle($entity_type, $bundle);
- field_ui_inactive_message($entity_type, $bundle);
-
- return drupal_get_form(new DisplayOverview($entity_type, $bundle, $view_mode));
-}
-
-/**
* Returns an array of field_type options.
*/
function field_ui_field_type_options() {
@@ -488,427 +436,6 @@ function field_ui_existing_field_options($entity_type, $bundle) {
}
/**
- * Form constructor for the field settings edit page.
- *
- * @see field_ui_menu()
- * @see field_ui_field_settings_form_submit()
- * @ingroup forms
- */
-function field_ui_field_settings_form($form, &$form_state, $instance) {
- $bundle = $instance['bundle'];
- $entity_type = $instance['entity_type'];
- $field = field_info_field($instance['field_name']);
- $form['#field'] = $field;
- $form['#entity_type'] = $entity_type;
- $form['#bundle'] = $bundle;
-
- drupal_set_title($instance['label']);
-
- $description = '
' . t('These settings apply to the %field field everywhere it is used. These settings impact the way that data is stored in the database and cannot be changed once data has been created.', array('%field' => $instance['label'])) . '
';
-
- // Create a form structure for the field values.
- $form['field'] = array(
- '#prefix' => $description,
- '#tree' => TRUE,
- );
-
- // See if data already exists for this field.
- // If so, prevent changes to the field settings.
- $has_data = field_has_data($field);
- if ($has_data) {
- $form['field']['#prefix'] = '' . t('There is data for this field in the database. The field settings can no longer be changed.') . '
' . $form['field']['#prefix'];
- }
-
- // Build the configurable field values.
- $cardinality = $field['cardinality'];
- $form['field']['container'] = array(
- // We can't use the container element because it doesn't support the title
- // or description properties.
- '#type' => 'item',
- '#field_prefix' => '',
- '#field_suffix' => '
',
- '#title' => t('Maximum number of values users can enter'),
- );
- $form['field']['container']['cardinality'] = array(
- '#type' => 'select',
- '#options' => drupal_map_assoc(range(1, 5)) + array(FIELD_CARDINALITY_UNLIMITED => t('Unlimited')) + array('other' => t('More')),
- '#default_value' => ($cardinality < 6) ? $cardinality : 'other',
- );
- // @todo Convert when http://drupal.org/node/1207060 gets in.
- $form['field']['container']['cardinality_other'] = array(
- '#type' => 'number',
- '#default_value' => $cardinality > 5 ? $cardinality : 6,
- '#min' => 1,
- '#title' => t('Custom value'),
- '#title_display' => 'invisible',
- '#states' => array(
- 'visible' => array(
- ':input[name="field[container][cardinality]"]' => array('value' => 'other'),
- ),
- ),
- );
- if (field_behaviors_widget('multiple values', $instance) == FIELD_BEHAVIOR_DEFAULT) {
- $form['field']['container']['#description'] = t('%unlimited will provide an %add-more button so users can add as many values as they like.', array(
- '%unlimited' => t('Unlimited'),
- '%add-more' => t('Add another item'),
- ));
- }
-
- // Build the non-configurable field values.
- $form['field']['field_name'] = array('#type' => 'value', '#value' => $field['field_name']);
- $form['field']['type'] = array('#type' => 'value', '#value' => $field['type']);
- $form['field']['module'] = array('#type' => 'value', '#value' => $field['module']);
- $form['field']['active'] = array('#type' => 'value', '#value' => $field['active']);
-
- // Add settings provided by the field module. The field module is
- // responsible for not returning settings that cannot be changed if
- // the field already has data.
- $form['field']['settings'] = array(
- '#weight' => 10,
- );
- $additions = module_invoke($field['module'], 'field_settings_form', $field, $instance, $has_data);
- if (is_array($additions)) {
- $form['field']['settings'] += $additions;
- }
-
- $form['actions'] = array('#type' => 'actions');
- $form['actions']['submit'] = array('#type' => 'submit', '#value' => t('Save field settings'));
- return $form;
-}
-
-/**
- * Form validation handler for field_ui_field_edit_form().
- *
- * @see field_ui_field_settings_form_submit().
- */
-function field_ui_field_settings_form_validate($form, &$form_state) {
- // Validate field cardinality.
- $cardinality = $form_state['values']['field']['container']['cardinality'];
- $cardinality_other = $form_state['values']['field']['container']['cardinality_other'];
- if ($cardinality == 'other' && empty($cardinality_other)) {
- form_error($form['field']['container']['cardinality_other'], t('Number of values is required.'));
- }
-}
-
-/**
- * Form submission handler for field_ui_field_settings_form().
- */
-function field_ui_field_settings_form_submit($form, &$form_state) {
- $form_values = $form_state['values'];
- $field_values = $form_values['field'];
-
- // Save field cardinality.
- $cardinality = $field_values['container']['cardinality'];
- $cardinality_other = $field_values['container']['cardinality_other'];
- $cardinality_other = $form_state['values']['field']['container']['cardinality_other'];
- if ($cardinality == 'other') {
- $cardinality = $cardinality_other;
- }
- $field_values['cardinality'] = $cardinality;
- unset($field_values['container']);
-
- // Merge incoming form values into the existing field.
- $field = field_info_field($field_values['field_name']);
- foreach ($field_values as $key => $value) {
- $field[$key] = $value;
- }
-
- $entity_type = $form['#entity_type'];
- $bundle = $form['#bundle'];
- $instance = field_info_instance($entity_type, $field['field_name'], $bundle);
-
- // Update the field.
- try {
- field_update_field($field);
- drupal_set_message(t('Updated field %label field settings.', array('%label' => $instance['label'])));
- $form_state['redirect'] = field_ui_next_destination($entity_type, $bundle);
- }
- catch (Exception $e) {
- drupal_set_message(t('Attempt to update field %label failed: %message.', array('%label' => $instance['label'], '%message' => $e->getMessage())), 'error');
- }
-}
-
-/**
- * Form constructor for the widget selection form.
- *
- * @see field_ui_menu()
- * @see field_ui_widget_type_form_submit()
- * @ingroup forms
- */
-function field_ui_widget_type_form($form, &$form_state, FieldInstance $instance) {
- drupal_set_title($instance['label']);
-
- $bundle = $instance['bundle'];
- $entity_type = $instance['entity_type'];
- $field_name = $instance['field_name'];
-
- $field = field_info_field($field_name);
- $bundles = entity_get_bundles();
- $bundle_label = $bundles[$entity_type][$bundle]['label'];
-
- $form = array(
- '#bundle' => $bundle,
- '#entity_type' => $entity_type,
- '#field_name' => $field_name,
- );
-
- $form['widget_type'] = array(
- '#type' => 'select',
- '#title' => t('Widget type'),
- '#required' => TRUE,
- '#options' => field_ui_widget_type_options($field['type']),
- '#default_value' => $instance->getWidget()->getPluginId(),
- '#description' => t('The type of form element you would like to present to the user when creating this field in the %type type.', array('%type' => $bundle_label)),
- );
-
- $form['actions'] = array('#type' => 'actions');
- $form['actions']['submit'] = array('#type' => 'submit', '#value' => t('Continue'));
-
- $form['#validate'] = array();
- $form['#submit'] = array('field_ui_widget_type_form_submit');
-
- return $form;
-}
-
-/**
- * Form submission handler for field_ui_widget_type_form().
- */
-function field_ui_widget_type_form_submit($form, &$form_state) {
- $form_values = $form_state['values'];
- $bundle = $form['#bundle'];
- $entity_type = $form['#entity_type'];
- $field_name = $form['#field_name'];
-
- // Retrieve the stored instance settings to merge with the incoming values.
- $instance = field_read_instance($entity_type, $field_name, $bundle);
-
- // Set the right module information.
- $widget_type = field_info_widget_types($form_values['widget_type']);
- $widget_module = $widget_type['module'];
-
- $instance['widget']['type'] = $form_values['widget_type'];
- $instance['widget']['module'] = $widget_module;
-
- try {
- field_update_instance($instance);
- drupal_set_message(t('Changed the widget for field %label.', array('%label' => $instance['label'])));
-
- if ($instance['required'] && empty($instance['default_value']) && empty($instance['default_value_function']) && $instance['widget']['type'] == 'field_hidden') {
- drupal_set_message(t('Field %label is required and uses the "hidden" widget. You might want to configure a default value.', array('%label' => $instance['label'])), 'warning');
- }
- }
- catch (Exception $e) {
- drupal_set_message(t('There was a problem changing the widget for field %label.', array('%label' => $instance['label'])), 'error');
- }
-
- $form_state['redirect'] = field_ui_next_destination($entity_type, $bundle);
-}
-
-/**
- * Form constructor for removing a field instance from a bundle.
- *
- * @see field_ui_menu()
- * @see field_ui_field_delete_form_submit()
- * @ingroup forms
- */
-function field_ui_field_delete_form($form, &$form_state, $instance) {
- $bundle = $instance['bundle'];
- $entity_type = $instance['entity_type'];
- $field = field_info_field($instance['field_name']);
-
- $admin_path = field_ui_bundle_admin_path($entity_type, $bundle);
-
- $form['entity_type'] = array('#type' => 'value', '#value' => $entity_type);
- $form['bundle'] = array('#type' => 'value', '#value' => $bundle);
- $form['field_name'] = array('#type' => 'value', '#value' => $field['field_name']);
-
- $output = confirm_form($form,
- t('Are you sure you want to delete the field %field?', array('%field' => $instance['label'])),
- $admin_path . '/fields',
- t('If you have any content left in this field, it will be lost. This action cannot be undone.'),
- t('Delete'), t('Cancel'),
- 'confirm'
- );
-
- if ($field['locked']) {
- unset($output['actions']['submit']);
- $output['description']['#markup'] = t('This field is locked and cannot be deleted.');
- }
-
- return $output;
-}
-
-/**
- * Form submission handler for field_ui_field_delete_form().
- *
- * Removes a field instance from a bundle. If the field has no more instances,
- * it will be marked as deleted too.
- */
-function field_ui_field_delete_form_submit($form, &$form_state) {
- $form_values = $form_state['values'];
- $field_name = $form_values['field_name'];
- $bundle = $form_values['bundle'];
- $entity_type = $form_values['entity_type'];
-
- $field = field_info_field($field_name);
- $instance = field_info_instance($entity_type, $field_name, $bundle);
- $bundles = entity_get_bundles();
- $bundle_label = $bundles[$entity_type][$bundle]['label'];
-
- if (!empty($bundle) && $field && !$field['locked'] && $form_values['confirm']) {
- field_delete_instance($instance);
- drupal_set_message(t('The field %field has been deleted from the %type content type.', array('%field' => $instance['label'], '%type' => $bundle_label)));
- }
- else {
- drupal_set_message(t('There was a problem removing the %field from the %type content type.', array('%field' => $instance['label'], '%type' => $bundle_label)), 'error');
- }
-
- $admin_path = field_ui_bundle_admin_path($entity_type, $bundle);
- $form_state['redirect'] = field_ui_get_destinations(array($admin_path . '/fields'));
-
- // Fields are purged on cron. However field module prevents disabling modules
- // when field types they provided are used in a field until it is fully
- // purged. In the case that a field has minimal or no content, a single call
- // to field_purge_batch() will remove it from the system. Call this with a
- // low batch limit to avoid administrators having to wait for cron runs when
- // removing instances that meet this criteria.
- field_purge_batch(10);
-}
-
-/**
- * Form constructor for the field instance settings form.
- *
- * @see field_ui_menu()
- * @see field_ui_field_edit_form_validate()
- * @see field_ui_field_edit_form_submit()
- * @see field_ui_field_edit_form_delete_submit()
- * @ingroup forms
- */
-function field_ui_field_edit_form($form, &$form_state, $instance) {
- $bundle = $instance['bundle'];
- $entity_type = $instance['entity_type'];
- $field = field_info_field($instance['field_name']);
- $bundles = entity_get_bundles();
-
- drupal_set_title(t('%instance settings for %bundle', array(
- '%instance' => $instance['label'],
- '%bundle' => $bundles[$entity_type][$bundle]['label'],
- )), PASS_THROUGH);
-
- $form['#field'] = $field;
- $form['#instance'] = $instance;
- // Create an arbitrary entity object (used by the 'default value' widget).
- $ids = (object) array('entity_type' => $instance['entity_type'], 'bundle' => $instance['bundle'], 'entity_id' => NULL);
- $form['#entity'] = _field_create_entity_from_ids($ids);
- $form['#entity']->field_ui_default_value = TRUE;
-
- if (!empty($field['locked'])) {
- $form['locked'] = array(
- '#markup' => t('The field %field is locked and cannot be edited.', array('%field' => $instance['label'])),
- );
- return $form;
- }
-
- $widget_type = field_info_widget_types($instance['widget']['type']);
-
- // Create a form structure for the instance values.
- $form['instance'] = array(
- '#tree' => TRUE,
- );
-
- // Build the non-configurable instance values.
- $form['instance']['field_name'] = array(
- '#type' => 'value',
- '#value' => $instance['field_name'],
- );
- $form['instance']['entity_type'] = array(
- '#type' => 'value',
- '#value' => $entity_type,
- );
- $form['instance']['bundle'] = array(
- '#type' => 'value',
- '#value' => $bundle,
- );
- $form['instance']['widget']['weight'] = array(
- '#type' => 'value',
- '#value' => !empty($instance['widget']['weight']) ? $instance['widget']['weight'] : 0,
- );
-
- // Build the configurable instance values.
- $form['instance']['label'] = array(
- '#type' => 'textfield',
- '#title' => t('Label'),
- '#default_value' => !empty($instance['label']) ? $instance['label'] : $field['field_name'],
- '#required' => TRUE,
- '#weight' => -20,
- );
-
- $form['instance']['description'] = array(
- '#type' => 'textarea',
- '#title' => t('Help text'),
- '#default_value' => !empty($instance['description']) ? $instance['description'] : '',
- '#rows' => 5,
- '#description' => t('Instructions to present to the user below this field on the editing form.
Allowed HTML tags: @tags', array('@tags' => _field_filter_xss_display_allowed_tags())) . '
' . t('This field supports tokens.'),
- '#weight' => -10,
- );
-
- $form['instance']['required'] = array(
- '#type' => 'checkbox',
- '#title' => t('Required field'),
- '#default_value' => !empty($instance['required']),
- '#weight' => -5,
- );
-
- // Build the widget component of the instance.
- $form['instance']['widget']['type'] = array(
- '#type' => 'value',
- '#value' => $instance['widget']['type'],
- );
-
- // Add additional field instance settings from the field module.
- $additions = module_invoke($field['module'], 'field_instance_settings_form', $field, $instance, $form_state);
- if (is_array($additions)) {
- $form['instance']['settings'] = $additions;
- $form['instance']['settings']['#weight'] = 10;
- }
-
- // Add widget settings for the widget type.
- $additions = $instance->getWidget()->settingsForm($form, $form_state);
- $form['instance']['widget']['settings'] = $additions ? $additions : array('#type' => 'value', '#value' => array());
- $form['instance']['widget']['#weight'] = 20;
-
- // Add handling for default value if not provided by any other module.
- if (field_behaviors_widget('default_value', $instance) == FIELD_BEHAVIOR_DEFAULT && empty($instance['default_value_function'])) {
- $form['instance']['default_value_widget'] = field_ui_default_value_widget($field, $instance, $form, $form_state);
- }
-
- $form['actions'] = array('#type' => 'actions');
- $form['actions']['submit'] = array(
- '#type' => 'submit',
- '#value' => t('Save settings')
- );
- $form['actions']['delete'] = array(
- '#type' => 'submit',
- '#value' => t('Delete field'),
- '#submit' => array('field_ui_field_edit_form_delete_submit'),
- );
- return $form;
-}
-
-/**
- * Form submission handler for 'Delete' button in field_ui_field_edit_form().
- */
-function field_ui_field_edit_form_delete_submit($form, &$form_state) {
- $destination = array();
- if (isset($_GET['destination'])) {
- $destination = drupal_get_destination();
- unset($_GET['destination']);
- }
- $instance = $form['#instance'];
- $form_state['redirect'] = array('admin/structure/types/manage/' . $instance['bundle'] . '/fields/' . $instance['field_name'] . '/delete', array('query' => $destination));
-}
-
-/**
* Builds the default value widget for a given field instance.
*/
function field_ui_default_value_widget($field, $instance, &$form, &$form_state) {
@@ -956,84 +483,6 @@ function field_ui_default_value_widget($field, $instance, &$form, &$form_state)
}
/**
- * Form validation handler for field_ui_field_edit_form().
- *
- * @see field_ui_field_edit_form_submit().
- */
-function field_ui_field_edit_form_validate($form, &$form_state) {
- // Take the incoming values as the $instance definition, so that the 'default
- // value' gets validated using the instance settings being submitted.
- $instance = $form['#instance'];
- $field_name = $instance['field_name'];
- $entity = $form['#entity'];
-
- if (isset($form['instance']['default_value_widget'])) {
- $element = $form['instance']['default_value_widget'];
-
- // Extract the 'default value'.
- $items = array();
- $instance->getWidget()->extractFormValues($entity, LANGUAGE_NOT_SPECIFIED, $items, $element, $form_state);
-
- // Grab the field definition from $form_state.
- $field_state = field_form_get_state($element['#parents'], $field_name, LANGUAGE_NOT_SPECIFIED, $form_state);
- $field = $field_state['field'];
-
- // Validate the value.
- $errors = array();
- $function = $field['module'] . '_field_validate';
- if (function_exists($function)) {
- $function(NULL, $field, $instance, LANGUAGE_NOT_SPECIFIED, $items, $errors);
- }
-
- // Report errors.
- if (isset($errors[$field_name][LANGUAGE_NOT_SPECIFIED])) {
- // Store reported errors in $form_state.
- $field_state['errors'] = $errors[$field_name][LANGUAGE_NOT_SPECIFIED];
- field_form_set_state($element['#parents'], $field_name, LANGUAGE_NOT_SPECIFIED, $form_state, $field_state);
-
- // Assign reported errors to the correct form element.
- $instance->getWidget()->flagErrors($entity, LANGUAGE_NOT_SPECIFIED, $items, $element, $form_state);
- }
- }
-}
-
-/**
- * Form submission handler for field_ui_field_edit_form().
- *
- * @see field_ui_field_edit_form_validate().
- */
-function field_ui_field_edit_form_submit($form, &$form_state) {
- $instance = $form['#instance'];
- $field = $form['#field'];
- $entity = $form['#entity'];
-
- // Handle the default value.
- if (isset($form['instance']['default_value_widget'])) {
- $element = $form['instance']['default_value_widget'];
-
- // Extract field values.
- $items = array();
- $instance->getWidget()->extractFormValues($entity, LANGUAGE_NOT_SPECIFIED, $items, $element, $form_state);
-
- $instance['default_value'] = $items ? $items : NULL;
- }
-
- // Merge incoming values into the instance.
- foreach ($form_state['values']['instance'] as $key => $value) {
- $instance[$key] = $value;
- }
- field_update_instance($instance);
-
- drupal_set_message(t('Saved %label configuration.', array('%label' => $instance['label'])));
-
- if ($instance['required'] && empty($instance['default_value']) && empty($instance['default_value_function']) && $instance['widget']['type'] == 'field_hidden') {
- drupal_set_message(t('Field %label is required and uses the "hidden" widget. You might want to configure a default value.', array('%label' => $instance['label'])), 'warning');
- }
-
- $form_state['redirect'] = field_ui_next_destination($instance['entity_type'], $instance['bundle']);
-}
-
-/**
* Extracts next redirect path from an array of multiple destinations.
*
* @see field_ui_next_destination()
diff --git a/core/modules/field_ui/field_ui.module b/core/modules/field_ui/field_ui.module
index a0f29e3..a7aeb9d 100644
--- a/core/modules/field_ui/field_ui.module
+++ b/core/modules/field_ui/field_ui.module
@@ -89,76 +89,44 @@ function field_ui_menu() {
// items below.
$field_position = count(explode('/', $path)) + 1;
- // User access check to be done against the permission to edit
- // fields or the display per entity type.
- $access_fields = array(
- 'access callback' => 'user_access',
- 'access arguments' => array('administer ' . $entity_type . ' fields'),
- );
- $access_display = array(
- 'access callback' => 'user_access',
- 'access arguments' => array('administer ' . $entity_type . ' display'),
- );
-
$items["$path/fields"] = array(
'title' => 'Manage fields',
- 'page callback' => 'field_ui_field_overview',
- 'page arguments' => array($entity_type, $bundle_arg),
'type' => MENU_LOCAL_TASK,
+ 'route_name' => "field_ui.overview.$entity_type.$bundle_name",
'weight' => 1,
- 'file' => 'field_ui.admin.inc',
- ) + $access_fields;
- $items["$path/fields/%field_ui_instance"] = array(
- 'load arguments' => array($entity_type, $bundle_arg, $bundle_pos, '%map'),
+ );
+ $items["$path/fields/%"] = array(
'title callback' => 'field_ui_instance_title',
'title arguments' => array($field_position),
- 'page callback' => 'drupal_get_form',
- 'page arguments' => array('field_ui_field_edit_form', $field_position),
- 'file' => 'field_ui.admin.inc',
- ) + $access_fields;
- $items["$path/fields/%field_ui_instance/edit"] = array(
- 'load arguments' => array($entity_type, $bundle_arg, $bundle_pos, '%map'),
+ 'route_name' => "field_ui.edit.$entity_type.$bundle_name",
+ );
+ $items["$path/fields/%/edit"] = array(
'title' => 'Edit',
- 'page callback' => 'drupal_get_form',
- 'page arguments' => array('field_ui_field_edit_form', $field_position),
'type' => MENU_DEFAULT_LOCAL_TASK,
- 'file' => 'field_ui.admin.inc',
- ) + $access_fields;
- $items["$path/fields/%field_ui_instance/field-settings"] = array(
- 'load arguments' => array($entity_type, $bundle_arg, $bundle_pos, '%map'),
+ );
+ $items["$path/fields/%/field-settings"] = array(
'title' => 'Field settings',
- 'page callback' => 'drupal_get_form',
- 'page arguments' => array('field_ui_field_settings_form', $field_position),
'type' => MENU_LOCAL_TASK,
- 'file' => 'field_ui.admin.inc',
- ) + $access_fields;
- $items["$path/fields/%field_ui_instance/widget-type"] = array(
- 'load arguments' => array($entity_type, $bundle_arg, $bundle_pos, '%map'),
+ 'route_name' => "field_ui.settings.$entity_type.$bundle_name",
+ );
+ $items["$path/fields/%/widget-type"] = array(
'title' => 'Widget type',
- 'page callback' => 'drupal_get_form',
- 'page arguments' => array('field_ui_widget_type_form', $field_position),
'type' => MENU_LOCAL_TASK,
- 'file' => 'field_ui.admin.inc',
- ) + $access_fields;
- $items["$path/fields/%field_ui_instance/delete"] = array(
- 'load arguments' => array($entity_type, $bundle_arg, $bundle_pos, '%map'),
+ 'route_name' => "field_ui.widget.$entity_type.$bundle_name",
+ );
+ $items["$path/fields/%/delete"] = array(
'title' => 'Delete',
- 'page callback' => 'drupal_get_form',
- 'page arguments' => array('field_ui_field_delete_form', $field_position),
'type' => MENU_VISIBLE_IN_BREADCRUMB,
+ 'route_name' => "field_ui.delete.$entity_type.$bundle_name",
'weight' => 10,
- 'file' => 'field_ui.admin.inc',
- ) + $access_fields;
+ );
// 'Manage display' tab.
$items["$path/display"] = array(
'title' => 'Manage display',
- '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',
- ) + $access_display;
+ 'route_name' => "field_ui.display_overview.$entity_type.$bundle_name",
+ );
// View modes secondary tabs.
// The same base $path for the menu item (with a placeholder) can be
@@ -172,17 +140,10 @@ 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 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.
- 'access callback' => '_field_ui_view_mode_menu_access',
- 'access arguments' => array($entity_type, $bundle_arg, $view_mode, $access_display['access arguments'][0]),
'type' => ($view_mode == 'default' ? MENU_DEFAULT_LOCAL_TASK : MENU_LOCAL_TASK),
- 'file' => 'field_ui.admin.inc',
);
if ($view_mode != 'default') {
+ $items["$path/display/$view_mode"]['route_name'] = "field_ui.display_overview.$entity_type.$bundle_name";
$items["$path/display/$view_mode"]['weight'] = $weight++;
}
}
@@ -271,24 +232,6 @@ function field_ui_instance_title($instance) {
}
/**
- * Access callback: Checks access for the 'view mode display settings' pages.
- *
- * @see field_ui_menu()
- */
-function _field_ui_view_mode_menu_access($entity_type, $bundle, $view_mode, $permission) {
- // First, determine visibility according to the 'use custom display'
- // setting for the view mode.
- $bundle = field_extract_bundle($entity_type, $bundle);
- $view_mode_settings = field_view_mode_settings($entity_type, $bundle);
- $visibility = ($view_mode == 'default') || !empty($view_mode_settings[$view_mode]['custom_settings']);
-
- // Then, determine access according to the $permission parameter.
- if ($visibility) {
- return user_access($permission);
- }
-}
-
-/**
* Implements hook_theme().
*/
function field_ui_theme() {
diff --git a/core/modules/field_ui/field_ui.services.yml b/core/modules/field_ui/field_ui.services.yml
new file mode 100644
index 0000000..5c72aff
--- /dev/null
+++ b/core/modules/field_ui/field_ui.services.yml
@@ -0,0 +1,9 @@
+services:
+ field_ui.subscriber:
+ class: Drupal\field_ui\Routing\RouteSubscriber
+ tags:
+ - { name: event_subscriber }
+ access_check.field_ui.view_mode:
+ class: Drupal\field_ui\Access\ViewModeAccessCheck
+ tags:
+ - { name: access_check }
diff --git a/core/modules/field_ui/lib/Drupal/field_ui/Access/ViewModeAccessCheck.php b/core/modules/field_ui/lib/Drupal/field_ui/Access/ViewModeAccessCheck.php
new file mode 100644
index 0000000..640ae84
--- /dev/null
+++ b/core/modules/field_ui/lib/Drupal/field_ui/Access/ViewModeAccessCheck.php
@@ -0,0 +1,43 @@
+getRequirements());
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function access(Route $route, Request $request) {
+ if ($entity_type = $request->attributes->get('entity_type')) {
+ $bundle = $request->attributes->get('bundle');
+ $view_mode = $request->attributes->get('view_mode');
+
+ $view_mode_settings = field_view_mode_settings($entity_type, $bundle);
+ $visibility = ($view_mode == 'default') || !empty($view_mode_settings[$view_mode]['custom_settings']);
+ if ($visibility) {
+ $permission = $route->getRequirement('_field_ui_view_mode_access');
+ return user_access($permission);
+ }
+ }
+ }
+
+}
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 7ee40f4..3a38b03 100644
--- a/core/modules/field_ui/lib/Drupal/field_ui/DisplayOverview.php
+++ b/core/modules/field_ui/lib/Drupal/field_ui/DisplayOverview.php
@@ -41,7 +41,12 @@ public function getFormID() {
/**
* Implements \Drupal\Core\Form\FormInterface::buildForm().
*/
- public function buildForm(array $form, array &$form_state) {
+ public function buildForm(array $form, array &$form_state, $entity_type = NULL, $bundle = NULL, $view_mode = NULL) {
+ form_load_include($form_state, 'inc', 'field_ui', 'field_ui.admin');
+ $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);
// Gather type information.
$instances = field_info_instances($this->entity_type, $this->bundle);
$field_types = field_info_field_types();
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 925caef..8b6902f 100644
--- a/core/modules/field_ui/lib/Drupal/field_ui/FieldOverview.php
+++ b/core/modules/field_ui/lib/Drupal/field_ui/FieldOverview.php
@@ -15,16 +15,6 @@
class FieldOverview extends OverviewBase {
/**
- * Overrides Drupal\field_ui\OverviewBase::__construct().
- */
- public function __construct($entity_type, $bundle, $view_mode = NULL) {
- $this->entity_type = $entity_type;
- $this->bundle = $bundle;
- $this->view_mode = 'form';
- $this->adminPath = field_ui_bundle_admin_path($this->entity_type, $this->bundle);
- }
-
- /**
* Implements Drupal\field_ui\OverviewBase::getRegions().
*/
public function getRegions() {
@@ -52,7 +42,12 @@ public function getFormID() {
/**
* Implements \Drupal\Core\Form\FormInterface::buildForm().
*/
- public function buildForm(array $form, array &$form_state) {
+ public function buildForm(array $form, array &$form_state, $entity_type = NULL, $bundle = NULL) {
+ form_load_include($form_state, 'inc', 'field_ui', 'field_ui.admin');
+ $this->entity_type = $entity_type;
+ $this->bundle = $bundle;
+ $this->view_mode = 'form';
+ $this->adminPath = field_ui_bundle_admin_path($this->entity_type, $this->bundle);
// When displaying the form, make sure the list of fields is up-to-date.
if (empty($form_state['post'])) {
field_info_cache_clear();
@@ -94,7 +89,7 @@ public function buildForm(array $form, array &$form_state) {
// Fields.
foreach ($instances as $name => $instance) {
$field = field_info_field($instance['field_name']);
- $admin_field_path = $this->adminPath . '/fields/' . $instance['field_name'];
+ $admin_field_path = $this->adminPath . '/fields/' . $instance->id();
$table[$name] = array(
'#attributes' => array('class' => array('draggable', 'tabledrag-leaf')),
'#row_type' => 'field',
@@ -151,7 +146,7 @@ public function buildForm(array $form, array &$form_state) {
);
$links['delete'] = array(
'title' => t('Delete'),
- 'href' => "$admin_field_path/delete",
+ 'href' => $admin_field_path . '/delete',
'attributes' => array('title' => t('Delete instance.')),
);
$table[$name]['operations']['data'] = array(
diff --git a/core/modules/field_ui/lib/Drupal/field_ui/Form/FieldDeleteForm.php b/core/modules/field_ui/lib/Drupal/field_ui/Form/FieldDeleteForm.php
new file mode 100644
index 0000000..c9ffa19
--- /dev/null
+++ b/core/modules/field_ui/lib/Drupal/field_ui/Form/FieldDeleteForm.php
@@ -0,0 +1,85 @@
+ $this->instance->label()));
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function getCancelPath() {
+ return field_ui_bundle_admin_path($this->instance->entity_type, $this->instance->bundle) . '/fields';
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function buildForm(array $form, array &$form_state, FieldInstance $field_instance = NULL) {
+ $this->instance = $form_state['instance'] = $field_instance;
+
+ return parent::buildForm($form, $form_state);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function submitForm(array &$form, array &$form_state) {
+ form_load_include($form_state, 'inc', 'field_ui', 'field_ui.admin');
+
+ $field = field_info_field($this->instance->field_name);
+ $bundles = entity_get_bundles();
+ $bundle_label = $bundles[$this->instance->entity_type][$this->instance->bundle]['label'];
+
+ if ($field && !$field['locked']) {
+ field_delete_instance($this->instance);
+ drupal_set_message(t('The field %field has been deleted from the %type content type.', array('%field' => $this->instance->label(), '%type' => $bundle_label)));
+ }
+ else {
+ drupal_set_message(t('There was a problem removing the %field from the %type content type.', array('%field' => $this->instance->label(), '%type' => $bundle_label)), 'error');
+ }
+
+ $admin_path = field_ui_bundle_admin_path($this->instance->entity_type, $this->instance->bundle);
+ $form_state['redirect'] = field_ui_get_destinations(array($admin_path . '/fields'));
+
+ // Fields are purged on cron. However field module prevents disabling modules
+ // when field types they provided are used in a field until it is fully
+ // purged. In the case that a field has minimal or no content, a single call
+ // to field_purge_batch() will remove it from the system. Call this with a
+ // low batch limit to avoid administrators having to wait for cron runs when
+ // removing instances that meet this criteria.
+ field_purge_batch(10);
+ }
+
+}
diff --git a/core/modules/field_ui/lib/Drupal/field_ui/Form/FieldEditForm.php b/core/modules/field_ui/lib/Drupal/field_ui/Form/FieldEditForm.php
new file mode 100644
index 0000000..bdf9967
--- /dev/null
+++ b/core/modules/field_ui/lib/Drupal/field_ui/Form/FieldEditForm.php
@@ -0,0 +1,233 @@
+instance = $form_state['instance'] = $field_instance;
+
+ $bundle = $this->instance['bundle'];
+ $entity_type = $this->instance['entity_type'];
+ $field = field_info_field($this->instance['field_name']);
+ $bundles = entity_get_bundles();
+
+ drupal_set_title(t('%instance settings for %bundle', array(
+ '%instance' => $this->instance->label(),
+ '%bundle' => $bundles[$entity_type][$bundle]['label'],
+ )), PASS_THROUGH);
+
+ $form['#field'] = $field;
+ // Create an arbitrary entity object (used by the 'default value' widget).
+ $ids = (object) array('entity_type' => $this->instance['entity_type'], 'bundle' => $this->instance['bundle'], 'entity_id' => NULL);
+ $form['#entity'] = _field_create_entity_from_ids($ids);
+ $form['#entity']->field_ui_default_value = TRUE;
+
+ if (!empty($field['locked'])) {
+ $form['locked'] = array(
+ '#markup' => t('The field %field is locked and cannot be edited.', array('%field' => $this->instance->label())),
+ );
+ return $form;
+ }
+
+ $widget_type = field_info_widget_types($this->instance['widget']['type']);
+
+ // Create a form structure for the instance values.
+ $form['instance'] = array(
+ '#tree' => TRUE,
+ );
+
+ // Build the non-configurable instance values.
+ $form['instance']['field_name'] = array(
+ '#type' => 'value',
+ '#value' => $this->instance['field_name'],
+ );
+ $form['instance']['entity_type'] = array(
+ '#type' => 'value',
+ '#value' => $entity_type,
+ );
+ $form['instance']['bundle'] = array(
+ '#type' => 'value',
+ '#value' => $bundle,
+ );
+ $form['instance']['widget']['weight'] = array(
+ '#type' => 'value',
+ '#value' => !empty($this->instance['widget']['weight']) ? $this->instance['widget']['weight'] : 0,
+ );
+
+ // Build the configurable instance values.
+ $form['instance']['label'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Label'),
+ '#default_value' => $this->instance->label() ?: $field['field_name'],
+ '#required' => TRUE,
+ '#weight' => -20,
+ );
+
+ $form['instance']['description'] = array(
+ '#type' => 'textarea',
+ '#title' => t('Help text'),
+ '#default_value' => !empty($this->instance['description']) ? $this->instance['description'] : '',
+ '#rows' => 5,
+ '#description' => t('Instructions to present to the user below this field on the editing form.
Allowed HTML tags: @tags', array('@tags' => _field_filter_xss_display_allowed_tags())) . '
' . t('This field supports tokens.'),
+ '#weight' => -10,
+ );
+
+ $form['instance']['required'] = array(
+ '#type' => 'checkbox',
+ '#title' => t('Required field'),
+ '#default_value' => !empty($this->instance['required']),
+ '#weight' => -5,
+ );
+
+ // Build the widget component of the instance.
+ $form['instance']['widget']['type'] = array(
+ '#type' => 'value',
+ '#value' => $this->instance['widget']['type'],
+ );
+
+ // Add additional field instance settings from the field module.
+ $additions = module_invoke($field['module'], 'field_instance_settings_form', $field, $this->instance, $form_state);
+ if (is_array($additions)) {
+ $form['instance']['settings'] = $additions;
+ $form['instance']['settings']['#weight'] = 10;
+ }
+
+ // Add widget settings for the widget type.
+ $additions = $this->instance->getWidget()->settingsForm($form, $form_state);
+ $form['instance']['widget']['settings'] = $additions ?: array('#type' => 'value', '#value' => array());
+ $form['instance']['widget']['#weight'] = 20;
+
+ // Add handling for default value if not provided by any other module.
+ if (field_behaviors_widget('default_value', $this->instance) == FIELD_BEHAVIOR_DEFAULT && empty($this->instance['default_value_function'])) {
+ $form['instance']['default_value_widget'] = field_ui_default_value_widget($field, $this->instance, $form, $form_state);
+ }
+
+ $form['actions'] = array('#type' => 'actions');
+ $form['actions']['submit'] = array(
+ '#type' => 'submit',
+ '#value' => t('Save settings')
+ );
+ $form['actions']['delete'] = array(
+ '#type' => 'submit',
+ '#value' => t('Delete field'),
+ '#submit' => array(array($this, 'delete')),
+ );
+ return $form;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function validateForm(array &$form, array &$form_state) {
+ // Take the incoming values as the $this->instance definition, so that the 'default
+ // value' gets validated using the instance settings being submitted.
+ $this->instance = $this->instance;
+ $field_name = $this->instance['field_name'];
+ $entity = $form['#entity'];
+
+ if (isset($form['instance']['default_value_widget'])) {
+ $element = $form['instance']['default_value_widget'];
+
+ // Extract the 'default value'.
+ $items = array();
+ $this->instance->getWidget()->extractFormValues($entity, LANGUAGE_NOT_SPECIFIED, $items, $element, $form_state);
+
+ // Grab the field definition from $form_state.
+ $field_state = field_form_get_state($element['#parents'], $field_name, LANGUAGE_NOT_SPECIFIED, $form_state);
+ $field = $field_state['field'];
+
+ // Validate the value.
+ $errors = array();
+ $function = $field['module'] . '_field_validate';
+ if (function_exists($function)) {
+ $function(NULL, $field, $this->instance, LANGUAGE_NOT_SPECIFIED, $items, $errors);
+ }
+
+ // Report errors.
+ if (isset($errors[$field_name][LANGUAGE_NOT_SPECIFIED])) {
+ // Store reported errors in $form_state.
+ $field_state['errors'] = $errors[$field_name][LANGUAGE_NOT_SPECIFIED];
+ field_form_set_state($element['#parents'], $field_name, LANGUAGE_NOT_SPECIFIED, $form_state, $field_state);
+
+ // Assign reported errors to the correct form element.
+ $this->instance->getWidget()->flagErrors($entity, LANGUAGE_NOT_SPECIFIED, $items, $element, $form_state);
+ }
+ }
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function submitForm(array &$form, array &$form_state) {
+ form_load_include($form_state, 'inc', 'field_ui', 'field_ui.admin');
+ $field = $form['#field'];
+ $entity = $form['#entity'];
+
+ // Handle the default value.
+ if (isset($form['instance']['default_value_widget'])) {
+ $element = $form['instance']['default_value_widget'];
+
+ // Extract field values.
+ $items = array();
+ $this->instance->getWidget()->extractFormValues($entity, LANGUAGE_NOT_SPECIFIED, $items, $element, $form_state);
+
+ $this->instance['default_value'] = $items ? $items : NULL;
+ }
+
+ // Merge incoming values into the instance.
+ foreach ($form_state['values']['instance'] as $key => $value) {
+ $this->instance[$key] = $value;
+ }
+ field_update_instance($this->instance);
+
+ drupal_set_message(t('Saved %label configuration.', array('%label' => $this->instance->label())));
+
+ if ($this->instance['required'] && empty($this->instance['default_value']) && empty($this->instance['default_value_function']) && $this->instance['widget']['type'] == 'field_hidden') {
+ drupal_set_message(t('Field %label is required and uses the "hidden" widget. You might want to configure a default value.', array('%label' => $this->instance['label'])), 'warning');
+ }
+
+ $form_state['redirect'] = field_ui_next_destination($this->instance['entity_type'], $this->instance['bundle']);
+ }
+
+ /**
+ * @todo.
+ */
+ public function delete(array &$form, array &$form_state) {
+ $destination = array();
+ if (isset($_GET['destination'])) {
+ $destination = drupal_get_destination();
+ unset($_GET['destination']);
+ }
+ $form_state['redirect'] = array('admin/structure/types/manage/' . $this->instance['bundle'] . '/fields/' . $this->instance->id() . '/delete', array('query' => $destination));
+ }
+
+}
diff --git a/core/modules/field_ui/lib/Drupal/field_ui/Form/FieldSettingsForm.php b/core/modules/field_ui/lib/Drupal/field_ui/Form/FieldSettingsForm.php
new file mode 100644
index 0000000..3749649
--- /dev/null
+++ b/core/modules/field_ui/lib/Drupal/field_ui/Form/FieldSettingsForm.php
@@ -0,0 +1,161 @@
+instance = $form_state['instance'] = $field_instance;
+ $field = field_info_field($this->instance->field_name);
+ $form['#field'] = $field;
+
+ drupal_set_title($this->instance->label());
+
+ $description = '' . t('These settings apply to the %field field everywhere it is used. These settings impact the way that data is stored in the database and cannot be changed once data has been created.', array('%field' => $this->instance->label())) . '
';
+
+ // Create a form structure for the field values.
+ $form['field'] = array(
+ '#prefix' => $description,
+ '#tree' => TRUE,
+ );
+
+ // See if data already exists for this field.
+ // If so, prevent changes to the field settings.
+ $has_data = field_has_data($field);
+ if ($has_data) {
+ $form['field']['#prefix'] = '' . t('There is data for this field in the database. The field settings can no longer be changed.') . '
' . $form['field']['#prefix'];
+ }
+
+ // Build the configurable field values.
+ $cardinality = $field['cardinality'];
+ $form['field']['container'] = array(
+ // We can't use the container element because it doesn't support the title
+ // or description properties.
+ '#type' => 'item',
+ '#field_prefix' => '',
+ '#field_suffix' => '
',
+ '#title' => t('Maximum number of values users can enter'),
+ );
+ $form['field']['container']['cardinality'] = array(
+ '#type' => 'select',
+ '#options' => drupal_map_assoc(range(1, 5)) + array(FIELD_CARDINALITY_UNLIMITED => t('Unlimited')) + array('other' => t('More')),
+ '#default_value' => ($cardinality < 6) ? $cardinality : 'other',
+ );
+ // @todo Convert when http://drupal.org/node/1207060 gets in.
+ $form['field']['container']['cardinality_other'] = array(
+ '#type' => 'number',
+ '#default_value' => $cardinality > 5 ? $cardinality : 6,
+ '#min' => 1,
+ '#title' => t('Custom value'),
+ '#title_display' => 'invisible',
+ '#states' => array(
+ 'visible' => array(
+ ':input[name="field[container][cardinality]"]' => array('value' => 'other'),
+ ),
+ ),
+ );
+ if (field_behaviors_widget('multiple values', $this->instance) == FIELD_BEHAVIOR_DEFAULT) {
+ $form['field']['container']['#description'] = t('%unlimited will provide an %add-more button so users can add as many values as they like.', array(
+ '%unlimited' => t('Unlimited'),
+ '%add-more' => t('Add another item'),
+ ));
+ }
+
+ // Build the non-configurable field values.
+ $form['field']['field_name'] = array('#type' => 'value', '#value' => $field['field_name']);
+ $form['field']['type'] = array('#type' => 'value', '#value' => $field['type']);
+ $form['field']['module'] = array('#type' => 'value', '#value' => $field['module']);
+ $form['field']['active'] = array('#type' => 'value', '#value' => $field['active']);
+
+ // Add settings provided by the field module. The field module is
+ // responsible for not returning settings that cannot be changed if
+ // the field already has data.
+ $form['field']['settings'] = array(
+ '#weight' => 10,
+ );
+ $additions = module_invoke($field['module'], 'field_settings_form', $field, $this->instance, $has_data);
+ if (is_array($additions)) {
+ $form['field']['settings'] += $additions;
+ }
+
+ $form['actions'] = array('#type' => 'actions');
+ $form['actions']['submit'] = array('#type' => 'submit', '#value' => t('Save field settings'));
+ return $form;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function validateForm(array &$form, array &$form_state) {
+ // Validate field cardinality.
+ $cardinality = $form_state['values']['field']['container']['cardinality'];
+ $cardinality_other = $form_state['values']['field']['container']['cardinality_other'];
+ if ($cardinality == 'other' && empty($cardinality_other)) {
+ form_error($form['field']['container']['cardinality_other'], t('Number of values is required.'));
+ }
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function submitForm(array &$form, array &$form_state) {
+ form_load_include($form_state, 'inc', 'field_ui', 'field_ui.admin');
+ $form_values = $form_state['values'];
+ $field_values = $form_values['field'];
+
+ // Save field cardinality.
+ $cardinality = $field_values['container']['cardinality'];
+ $cardinality_other = $field_values['container']['cardinality_other'];
+ $cardinality_other = $form_state['values']['field']['container']['cardinality_other'];
+ if ($cardinality == 'other') {
+ $cardinality = $cardinality_other;
+ }
+ $field_values['cardinality'] = $cardinality;
+ unset($field_values['container']);
+
+ // Merge incoming form values into the existing field.
+ $field = field_info_field($field_values['field_name']);
+ foreach ($field_values as $key => $value) {
+ $field[$key] = $value;
+ }
+
+ // Update the field.
+ try {
+ field_update_field($field);
+ drupal_set_message(t('Updated field %label field settings.', array('%label' => $this->instance->label())));
+ $form_state['redirect'] = field_ui_next_destination($this->instance->entity_type, $this->instance->bundle);
+ }
+ catch (Exception $e) {
+ drupal_set_message(t('Attempt to update field %label failed: %message.', array('%label' => $this->instance->label(), '%message' => $e->getMessage())), 'error');
+ }
+ }
+
+}
diff --git a/core/modules/field_ui/lib/Drupal/field_ui/Form/FieldWidgetTypeForm.php b/core/modules/field_ui/lib/Drupal/field_ui/Form/FieldWidgetTypeForm.php
new file mode 100644
index 0000000..5af64ec
--- /dev/null
+++ b/core/modules/field_ui/lib/Drupal/field_ui/Form/FieldWidgetTypeForm.php
@@ -0,0 +1,112 @@
+instance = $form_state['instance'] = $field_instance;
+ form_load_include($form_state, 'inc', 'field_ui', 'field_ui.admin');
+ drupal_set_title($this->instance['label']);
+
+ $bundle = $this->instance['bundle'];
+ $entity_type = $this->instance['entity_type'];
+ $field_name = $this->instance['field_name'];
+
+ $field = field_info_field($field_name);
+ $bundles = entity_get_bundles();
+ $bundle_label = $bundles[$entity_type][$bundle]['label'];
+
+ $form = array(
+ '#bundle' => $bundle,
+ '#entity_type' => $entity_type,
+ '#field_name' => $field_name,
+ );
+
+ $form['widget_type'] = array(
+ '#type' => 'select',
+ '#title' => t('Widget type'),
+ '#required' => TRUE,
+ '#options' => field_ui_widget_type_options($field['type']),
+ '#default_value' => $this->instance->getWidget()->getPluginId(),
+ '#description' => t('The type of form element you would like to present to the user when creating this field in the %type type.', array('%type' => $bundle_label)),
+ );
+
+ $form['actions'] = array('#type' => 'actions');
+ $form['actions']['submit'] = array('#type' => 'submit', '#value' => t('Continue'));
+
+ $form['#validate'] = array();
+ $form['#submit'] = array('field_ui_widget_type_form_submit');
+
+ return $form;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function validateForm(array &$form, array &$form_state) {
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function submitForm(array &$form, array &$form_state) {
+ $form_values = $form_state['values'];
+ $bundle = $form['#bundle'];
+ $entity_type = $form['#entity_type'];
+ $field_name = $form['#field_name'];
+
+ // Retrieve the stored instance settings to merge with the incoming values.
+ $instance = field_read_instance($entity_type, $field_name, $bundle);
+
+ // Set the right module information.
+ $widget_type = field_info_widget_types($form_values['widget_type']);
+ $widget_module = $widget_type['module'];
+
+ $instance['widget']['type'] = $form_values['widget_type'];
+ $instance['widget']['module'] = $widget_module;
+
+ try {
+ field_update_instance($instance);
+ drupal_set_message(t('Changed the widget for field %label.', array('%label' => $instance['label'])));
+
+ if ($instance['required'] && empty($instance['default_value']) && empty($instance['default_value_function']) && $instance['widget']['type'] == 'field_hidden') {
+ drupal_set_message(t('Field %label is required and uses the "hidden" widget. You might want to configure a default value.', array('%label' => $instance['label'])), 'warning');
+ }
+ }
+ catch (Exception $e) {
+ drupal_set_message(t('There was a problem changing the widget for field %label.', array('%label' => $instance['label'])), 'error');
+ }
+
+ $form_state['redirect'] = field_ui_next_destination($entity_type, $bundle);
+ }
+
+}
diff --git a/core/modules/field_ui/lib/Drupal/field_ui/OverviewBase.php b/core/modules/field_ui/lib/Drupal/field_ui/OverviewBase.php
index 5a76dc1..1e6dfb2 100644
--- a/core/modules/field_ui/lib/Drupal/field_ui/OverviewBase.php
+++ b/core/modules/field_ui/lib/Drupal/field_ui/OverviewBase.php
@@ -43,24 +43,6 @@
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);
- }
-
- /**
* Implements \Drupal\Core\Form\FormInterface::validateForm().
*/
public function validateForm(array &$form, array &$form_state) {
diff --git a/core/modules/field_ui/lib/Drupal/field_ui/Routing/RouteSubscriber.php b/core/modules/field_ui/lib/Drupal/field_ui/Routing/RouteSubscriber.php
new file mode 100644
index 0000000..dd00bf8
--- /dev/null
+++ b/core/modules/field_ui/lib/Drupal/field_ui/Routing/RouteSubscriber.php
@@ -0,0 +1,92 @@
+getRouteCollection();
+ foreach (entity_get_info() as $entity_type => $entity_info) {
+ if ($entity_info['fieldable']) {
+ foreach (entity_get_bundles($entity_type) as $bundle_name => $bundle_info) {
+ if (isset($bundle_info['admin'])) {
+ // @todo Convert the bundle admin path to use {slug} instead of %.
+ $path_parts = explode('/', $bundle_info['admin']['path']);
+ foreach ($path_parts as &$part) {
+ if (strpos($part, '%') === 0) {
+ $part = str_replace('%', '{', $part) . '}';
+ }
+ }
+ $path = implode('/', $path_parts);
+
+ $route = new Route("$path/fields/{field_instance}/delete", array(
+ '_form' => '\Drupal\field_ui\Form\FieldDeleteForm'), array(
+ '_permission' => 'administer ' . $entity_type . ' fields',
+ ));
+ $collection->add("field_ui.delete.$entity_type.$bundle_name", $route);
+
+ $route = new Route("$path/fields/{field_instance}", array(
+ '_form' => '\Drupal\field_ui\Form\FieldEditForm'), array(
+ '_permission' => 'administer ' . $entity_type . ' fields',
+ ));
+ $collection->add("field_ui.edit.$entity_type.$bundle_name", $route);
+
+ $route = new Route("$path/fields/{field_instance}/widget-type", array(
+ '_form' => '\Drupal\field_ui\Form\FieldWidgetTypeForm'), array(
+ '_permission' => 'administer ' . $entity_type . ' fields',
+ ));
+ $collection->add("field_ui.widget_type.$entity_type.$bundle_name", $route);
+
+ $route = new Route("$path/fields/{field_instance}/field-settings", array(
+ '_form' => '\Drupal\field_ui\Form\FieldSettingsForm'), array(
+ '_permission' => 'administer ' . $entity_type . ' fields',
+ ));
+ $collection->add("field_ui.settings.$entity_type.$bundle_name", $route);
+
+ $route = new Route("$path/fields", array(
+ '_form' => '\Drupal\field_ui\FieldOverview',
+ 'bundle' => $bundle_name,
+ 'entity_type' => $entity_type), array(
+ '_permission' => 'administer ' . $entity_type . ' fields',
+ ));
+ $collection->add("field_ui.overview.$entity_type.$bundle_name", $route);
+
+ $route = new Route("$path/display/{view_mode}", array(
+ '_form' => '\Drupal\field_ui\DisplayOverview',
+ 'bundle' => $bundle_name,
+ 'entity_type' => $entity_type,
+ 'view_mode' => 'default'), array(
+ '_field_ui_view_mode_access' => 'administer ' . $entity_type . ' fields',
+ ));
+ $collection->add("field_ui.display_overview.$entity_type.$bundle_name", $route);
+ }
+ }
+ }
+ }
+ }
+
+}
diff --git a/core/modules/user/user.module b/core/modules/user/user.module
index d41206f..c73f2de 100644
--- a/core/modules/user/user.module
+++ b/core/modules/user/user.module
@@ -2531,7 +2531,7 @@ function user_block_user_action(&$entity, $context = array()) {
* field instance' form.
*/
function user_form_field_ui_field_edit_form_alter(&$form, &$form_state, $form_id) {
- $instance = $form['#instance'];
+ $instance = $form_state['instance'];
if ($instance['entity_type'] == 'user') {
$form['instance']['settings']['user_register_form'] = array(