diff --git a/core/lib/Drupal/Core/Entity/Annotation/EntityType.php b/core/lib/Drupal/Core/Entity/Annotation/EntityType.php index 68f6a18..50b604c 100644 --- a/core/lib/Drupal/Core/Entity/Annotation/EntityType.php +++ b/core/lib/Drupal/Core/Entity/Annotation/EntityType.php @@ -194,25 +194,25 @@ class EntityType extends Plugin { public $bundle_keys; /** - * The base path for the entity type administration page. + * The base router path for the entity type's field administration page. * * If the entity type has a bundle, include {bundle} in the path. * * For example, the node entity type specifies - * "admin/structure/types/manage/{bundle}" as its base path. + * "admin/structure/types/manage/{bundle}" as its base field admin path. * - * @var string + * @var string (optional) */ - public $entity_menu_base_path; + public $route_base_path; /** - * The prefix for the bundles for this entity. + * The prefix for the bundles of this entity type. * * For example, the comment bundle is prefixed with 'comment_node_'. * - * @var string + * @var string (optional) */ - public $entity_bundle_prefix; + public $bundle_prefix; /** * The base menu router path to which the entity admin user interface responds. diff --git a/core/modules/block/custom_block/lib/Drupal/custom_block/Plugin/Core/Entity/CustomBlock.php b/core/modules/block/custom_block/lib/Drupal/custom_block/Plugin/Core/Entity/CustomBlock.php index 4d67f0a..f4ac93a 100644 --- a/core/modules/block/custom_block/lib/Drupal/custom_block/Plugin/Core/Entity/CustomBlock.php +++ b/core/modules/block/custom_block/lib/Drupal/custom_block/Plugin/Core/Entity/CustomBlock.php @@ -31,7 +31,7 @@ * }, * base_table = "custom_block", * revision_table = "custom_block_revision", - * entity_menu_base_path = "admin/structure/custom-blocks/manage/{bundle}", + * route_base_path = "admin/structure/custom-blocks/manage/{bundle}", * menu_base_path = "block/%custom_block", * fieldable = TRUE, * translatable = TRUE, diff --git a/core/modules/comment/lib/Drupal/comment/Plugin/Core/Entity/Comment.php b/core/modules/comment/lib/Drupal/comment/Plugin/Core/Entity/Comment.php index 643c081..a45eb3f 100644 --- a/core/modules/comment/lib/Drupal/comment/Plugin/Core/Entity/Comment.php +++ b/core/modules/comment/lib/Drupal/comment/Plugin/Core/Entity/Comment.php @@ -34,8 +34,8 @@ * fieldable = TRUE, * translatable = TRUE, * static_cache = FALSE, - * entity_menu_base_path = "admin/structure/types/manage/{bundle}/comment", - * entity_bundle_prefix = "comment_node_", + * route_base_path = "admin/structure/types/manage/{bundle}/comment", + * bundle_prefix = "comment_node_", * entity_keys = { * "id" = "cid", * "bundle" = "node_type", diff --git a/core/modules/field_ui/field_ui.admin.inc b/core/modules/field_ui/field_ui.admin.inc index 510ff0b..eda59c8 100644 --- a/core/modules/field_ui/field_ui.admin.inc +++ b/core/modules/field_ui/field_ui.admin.inc @@ -5,10 +5,6 @@ * Administrative interface for custom field type creation. */ -use Drupal\field\Plugin\Core\Entity\FieldInstance; -use Drupal\field_ui\FieldOverview; -use Drupal\field_ui\DisplayOverview; - /** * Page callback: Lists all defined fields for quick reference. * diff --git a/core/modules/field_ui/field_ui.module b/core/modules/field_ui/field_ui.module index 3cd76d4..c8943c9 100644 --- a/core/modules/field_ui/field_ui.module +++ b/core/modules/field_ui/field_ui.module @@ -65,9 +65,9 @@ function field_ui_menu() { // Create tabs for all possible bundles. foreach (entity_get_info() as $entity_type => $entity_info) { - if ($entity_info['fieldable'] && isset($entity_info['entity_menu_base_path'])) { + if ($entity_info['fieldable'] && isset($entity_info['route_base_path'])) { // Extract path information from the entity type. - $path = $entity_info['entity_menu_base_path']; + $path = $entity_info['route_base_path']; $default_path = preg_replace('/{' . DRUPAL_PHP_FUNCTION_PATTERN . '}/', '%', $path); // This is the position of the %field_ui_instance placeholder in the // items below. 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 5347b20..7710699 100644 --- a/core/modules/field_ui/lib/Drupal/field_ui/FieldOverview.php +++ b/core/modules/field_ui/lib/Drupal/field_ui/FieldOverview.php @@ -563,8 +563,8 @@ public function submitForm(array &$form, array &$form_state) { // Create the field and instance. try { - field_create_field($field); - $new_instance = field_create_instance($instance); + $this->entityManager->getStorageController('field_entity')->create($field)->save(); + $new_instance = $this->entityManager->getStorageController('field_instance')->create($instance)->save(); // Make sure the field is displayed in the 'default' view mode (using // default formatter and settings). It stays hidden for other view @@ -606,7 +606,7 @@ public function submitForm(array &$form, array &$form_state) { ); try { - $new_instance = field_create_instance($instance); + $new_instance = $this->entityManager->getStorageController('field_instance')->create($instance)->save(); // Make sure the field is displayed in the 'default' view mode (using // default formatter and settings). It stays hidden for other view 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 index 265142b..6b20911 100644 --- a/core/modules/field_ui/lib/Drupal/field_ui/Form/FieldDeleteForm.php +++ b/core/modules/field_ui/lib/Drupal/field_ui/Form/FieldDeleteForm.php @@ -70,7 +70,7 @@ public function submitForm(array &$form, array &$form_state) { $bundle_label = $bundles[$this->instance->entity_type][$this->instance->bundle]['label']; if ($field && !$field['locked']) { - field_delete_instance($this->instance); + $this->instance->delete(TRUE); drupal_set_message(t('The field %field has been deleted from the %type content type.', array('%field' => $this->instance->label(), '%type' => $bundle_label))); } else { diff --git a/core/modules/field_ui/lib/Drupal/field_ui/Form/FieldInstanceEditForm.php b/core/modules/field_ui/lib/Drupal/field_ui/Form/FieldInstanceEditForm.php index 4c12e50..f922875 100644 --- a/core/modules/field_ui/lib/Drupal/field_ui/Form/FieldInstanceEditForm.php +++ b/core/modules/field_ui/lib/Drupal/field_ui/Form/FieldInstanceEditForm.php @@ -8,12 +8,16 @@ namespace Drupal\field_ui\Form; use Drupal\Core\Form\FormInterface; +use Drupal\Core\ControllerInterface; use Drupal\field\Plugin\Core\Entity\FieldInstance; +use Drupal\field\Plugin\Type\Widget\WidgetPluginManager; +use Drupal\field\Field; +use Symfony\Component\DependencyInjection\ContainerInterface; /** * Provides a form for the field instance settings form. */ -class FieldInstanceEditForm implements FormInterface { +class FieldInstanceEditForm implements FormInterface, ControllerInterface { /** * The field instance being edited. @@ -23,6 +27,32 @@ class FieldInstanceEditForm implements FormInterface { protected $instance; /** + * The field widget plugin manager. + * + * @var \Drupal\field\Plugin\Type\Widget\WidgetPluginManager + */ + protected $widgetManager; + + /** + * Constructs a new FieldInstanceEditForm object. + * + * @param \Drupal\field\Plugin\Type\Widget\WidgetPluginManager $widget_manager + * The field widget plugin manager. + */ + public function __construct(WidgetPluginManager $widget_manager) { + $this->widgetManager = $widget_manager; + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container) { + return new static( + $container->get('plugin.manager.field.widget') + ); + } + + /** * {@inheritdoc} */ public function getFormID() { @@ -37,7 +67,7 @@ public function buildForm(array $form, array &$form_state, FieldInstance $field_ $bundle = $this->instance['bundle']; $entity_type = $this->instance['entity_type']; - $field = field_info_field($this->instance['field_name']); + $field = Field::fieldInfo()->getField($this->instance['field_name']); $bundles = entity_get_bundles(); drupal_set_title(t('%instance settings for %bundle', array( @@ -58,7 +88,7 @@ public function buildForm(array $form, array &$form_state, FieldInstance $field_ return $form; } - $widget_type = field_info_widget_types($this->instance['widget']['type']); + $widget_type = $this->widgetManager->getDefinition($this->instance['widget']['type']); // Create a form structure for the instance values. $form['instance'] = array( @@ -115,7 +145,7 @@ public function buildForm(array $form, array &$form_state, FieldInstance $field_ ); // Add additional field instance settings from the field module. - $additions = module_invoke($field['module'], 'field_instance_settings_form', $field, $this->instance, $form_state); + $additions = \Drupal::moduleHandler->invoke($field['module'], 'field_instance_settings_form', array($field, $this->instance, $form_state)); if (is_array($additions)) { $form['instance']['settings'] = $additions; $form['instance']['settings']['#weight'] = 10; @@ -150,7 +180,6 @@ public function buildForm(array $form, array &$form_state, FieldInstance $field_ 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']; @@ -207,7 +236,7 @@ public function submitForm(array &$form, array &$form_state) { foreach ($form_state['values']['instance'] as $key => $value) { $this->instance[$key] = $value; } - field_update_instance($this->instance); + $this->instance->save(); drupal_set_message(t('Saved %label configuration.', array('%label' => $this->instance->label()))); @@ -257,7 +286,7 @@ protected function getDefaultValueWidget($field, array &$form, &$form_state) { // instead of the hidden widget. if ($this->instance['widget']['type'] == 'field_hidden') { $field_type = field_info_field_types($field['type']); - $default_widget = field_info_widget_types($field_type['default_widget']); + $default_widget = $this->widgetManager->getDefinition($field_type['default_widget']); $this->instance['widget'] = array( 'type' => $default_widget['id'], 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 index 7e87f35..c3f575d 100644 --- a/core/modules/field_ui/lib/Drupal/field_ui/Form/FieldSettingsForm.php +++ b/core/modules/field_ui/lib/Drupal/field_ui/Form/FieldSettingsForm.php @@ -9,6 +9,7 @@ use Drupal\Core\Form\FormInterface; use Drupal\field\Plugin\Core\Entity\FieldInstance; +use Drupal\field\Field; /** * Provides a form for the field settings edit page. @@ -101,7 +102,7 @@ public function buildForm(array $form, array &$form_state, FieldInstance $field_ $form['field']['settings'] = array( '#weight' => 10, ); - $additions = module_invoke($field['module'], 'field_settings_form', $field, $this->instance, $has_data); + $additions = \Drupal::moduleHandler->invoke($field['module'], 'field_settings_form', array($field, $this->instance, $has_data)); if (is_array($additions)) { $form['field']['settings'] += $additions; } @@ -142,14 +143,14 @@ public function submitForm(array &$form, array &$form_state) { unset($field_values['container']); // Merge incoming form values into the existing field. - $field = field_info_field($field_values['field_name']); + $field = Field::fieldInfo()->getField($field_values['field_name']); foreach ($field_values as $key => $value) { $field[$key] = $value; } // Update the field. try { - field_update_field($field); + $field->save(); 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); } 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 index c461543..06de12d 100644 --- a/core/modules/field_ui/lib/Drupal/field_ui/Form/FieldWidgetTypeForm.php +++ b/core/modules/field_ui/lib/Drupal/field_ui/Form/FieldWidgetTypeForm.php @@ -8,12 +8,16 @@ namespace Drupal\field_ui\Form; use Drupal\Core\Form\FormInterface; +use Drupal\Core\ControllerInterface; use Drupal\field\Plugin\Core\Entity\FieldInstance; +use Drupal\field\Plugin\Type\Widget\WidgetPluginManager; +use Drupal\field\Field; +use Symfony\Component\DependencyInjection\ContainerInterface; /** * Provides a form for the widget selection form. */ -class FieldWidgetTypeForm implements FormInterface { +class FieldWidgetTypeForm implements FormInterface, ControllerInterface { /** * The field instance being edited. @@ -23,6 +27,32 @@ class FieldWidgetTypeForm implements FormInterface { protected $instance; /** + * The field widget plugin manager. + * + * @var \Drupal\field\Plugin\Type\Widget\WidgetPluginManager + */ + protected $widgetManager; + + /** + * Constructs a new FieldWidgetTypeForm object. + * + * @param \Drupal\field\Plugin\Type\Widget\WidgetPluginManager $widget_manager + * The field widget plugin manager. + */ + public function __construct(WidgetPluginManager $widget_manager) { + $this->widgetManager = $widget_manager; + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container) { + return new static( + $container->get('plugin.manager.field.widget') + ); + } + + /** * {@inheritdoc} */ public function getFormID() { @@ -41,7 +71,7 @@ public function buildForm(array $form, array &$form_state, FieldInstance $field_ $entity_type = $this->instance['entity_type']; $field_name = $this->instance['field_name']; - $field = field_info_field($field_name); + $field = Field::fieldInfo()->getField($field_name); $bundles = entity_get_bundles(); $bundle_label = $bundles[$entity_type][$bundle]['label']; @@ -85,14 +115,14 @@ public function submitForm(array &$form, array &$form_state) { $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_type = $this->widgetManager->getDefinition($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); + $instance->save(); 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') { 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 164570d..8973d95 100644 --- a/core/modules/field_ui/lib/Drupal/field_ui/OverviewBase.php +++ b/core/modules/field_ui/lib/Drupal/field_ui/OverviewBase.php @@ -76,8 +76,8 @@ public static function create(ContainerInterface $container) { */ public function buildForm(array $form, array &$form_state, $entity_type = NULL, $bundle = NULL) { $entity_info = $this->entityManager->getDefinition($entity_type); - if (!empty($entity_info['entity_bundle_prefix'])) { - $bundle = $entity_info['entity_bundle_prefix'] . $bundle; + if (!empty($entity_info['bundle_prefix'])) { + $bundle = $entity_info['bundle_prefix'] . $bundle; } form_load_include($form_state, 'inc', 'field_ui', 'field_ui.admin'); 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 index 617db6d..94e7b09 100644 --- a/core/modules/field_ui/lib/Drupal/field_ui/Routing/RouteSubscriber.php +++ b/core/modules/field_ui/lib/Drupal/field_ui/Routing/RouteSubscriber.php @@ -49,8 +49,8 @@ public static function getSubscribedEvents() { public function routes(RouteBuildEvent $event) { $collection = $event->getRouteCollection(); foreach ($this->manager->getDefinitions() as $entity_type => $entity_info) { - if ($entity_info['fieldable'] && isset($entity_info['entity_menu_base_path'])) { - $path = $entity_info['entity_menu_base_path']; + if ($entity_info['fieldable'] && isset($entity_info['route_base_path'])) { + $path = $entity_info['route_base_path']; $route = new Route( "$path/fields/{field_instance}", diff --git a/core/modules/node/lib/Drupal/node/Plugin/Core/Entity/Node.php b/core/modules/node/lib/Drupal/node/Plugin/Core/Entity/Node.php index 32cfdca..68befd4 100644 --- a/core/modules/node/lib/Drupal/node/Plugin/Core/Entity/Node.php +++ b/core/modules/node/lib/Drupal/node/Plugin/Core/Entity/Node.php @@ -44,7 +44,7 @@ * bundle_keys = { * "bundle" = "type" * }, - * entity_menu_base_path = "admin/structure/types/manage/{bundle}", + * route_base_path = "admin/structure/types/manage/{bundle}", * permission_granularity = "bundle" * ) */ diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/Core/Entity/Term.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/Core/Entity/Term.php index b5954e3..2daaebb 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/Core/Entity/Term.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/Core/Entity/Term.php @@ -43,7 +43,7 @@ * "bundle" = "vid" * }, * menu_base_path = "taxonomy/term/%taxonomy_term", - * entity_menu_base_path = "admin/structure/taxonomy/{bundle}", + * route_base_path = "admin/structure/taxonomy/{bundle}", * permission_granularity = "bundle" * ) */ diff --git a/core/modules/user/lib/Drupal/user/Plugin/Core/Entity/User.php b/core/modules/user/lib/Drupal/user/Plugin/Core/Entity/User.php index 845134d..c609450 100644 --- a/core/modules/user/lib/Drupal/user/Plugin/Core/Entity/User.php +++ b/core/modules/user/lib/Drupal/user/Plugin/Core/Entity/User.php @@ -31,7 +31,7 @@ * default_operation = "profile", * base_table = "users", * uri_callback = "user_uri", - * entity_menu_base_path = "admin/config/people/accounts", + * route_base_path = "admin/config/people/accounts", * label_callback = "user_label", * fieldable = TRUE, * translatable = TRUE,