Issue #3442361 by catch, smustgrave: Remove deprecated code from field_ui

merge-requests/6215/merge
Alex Pott 2024-04-23 00:27:34 +01:00
parent fb96c6ed34
commit 6d733889cc
No known key found for this signature in database
GPG Key ID: BDA67E7EE836E5CE
6 changed files with 10 additions and 164 deletions

View File

@ -7,12 +7,10 @@
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Form\SubformState;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Entity\EntityViewModeInterface;
use Drupal\Core\Entity\EntityFormModeInterface;
use Drupal\Core\Url;
use Drupal\field\FieldConfigInterface;
use Drupal\field_ui\FieldUI;
use Drupal\field_ui\Form\FieldConfigEditForm;
use Drupal\field_ui\Form\FieldStorageConfigEditForm;
@ -283,21 +281,3 @@ function field_ui_form_manage_field_form_submit($form, FormStateInterface $form_
$form_state->setRedirectUrl($route_info);
}
}
/**
* Implements hook_form_FORM_ID_alter() for field_config_edit_form.
*/
function field_ui_form_field_config_edit_form_alter(&$form, FormStateInterface $form_state) {
$field_config = $form_state->getFormObject()->getEntity();
assert($field_config instanceof FieldConfigInterface);
$form_id = 'field_storage_config_edit_form';
$hook = 'form_' . $form_id;
$field_storage_form = \Drupal::entityTypeManager()->getFormObject('field_storage_config', $form_state->getFormObject()->getOperation());
$field_storage_form->setEntity($field_config->getFieldStorageDefinition());
$subform_state = SubformState::createForSubform($form['field_storage']['subform'], $form, $form_state, $field_storage_form);
\Drupal::moduleHandler()->alterDeprecated('Use hook_form_field_config_edit_form_alter() instead. See https://www.drupal.org/node/3386675.', $hook, $form['field_storage']['subform'], $subform_state, $form_id);
\Drupal::theme()->alter($hook, $form['field_storage']['subform'], $subform_state, $form_id);
}

View File

@ -18,28 +18,8 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
*/
class FieldConfigDeleteForm extends EntityDeleteForm {
/**
* The entity type bundle info service.
*
* @var \Drupal\Core\Entity\EntityTypeBundleInfoInterface
*/
protected $entityTypeBundleInfo;
/**
* Constructs a new FieldConfigDeleteForm object.
*
* @param \Drupal\Core\Entity\EntityTypeBundleInfoInterface $entity_type_bundle_info
* The entity type bundle info service.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface|null $entity_type_manager
* The entity type manager service.
*/
public function __construct(EntityTypeBundleInfoInterface $entity_type_bundle_info, ?EntityTypeManagerInterface $entity_type_manager = NULL) {
$this->entityTypeBundleInfo = $entity_type_bundle_info;
if (!$entity_type_manager) {
@trigger_error('Calling ' . __METHOD__ . '() without the $entity_type_manager argument is deprecated in drupal:10.2.0 and is removed from drupal:11.0.0. See https://www.drupal.org/node/3396525', E_USER_DEPRECATED);
$entity_type_manager = \Drupal::service('entity_type.manager');
}
$this->entityTypeManager = $entity_type_manager;
public function __construct(protected EntityTypeBundleInfoInterface $entityTypeBundleInfo, EntityTypeManagerInterface $entityTypeManager) {
$this->entityTypeManager = $entityTypeManager;
}
/**

View File

@ -38,13 +38,6 @@ class FieldConfigEditForm extends EntityForm {
*/
protected $entity;
/**
* The entity type bundle info service.
*
* @var \Drupal\Core\Entity\EntityTypeBundleInfoInterface
*/
protected $entityTypeBundleInfo;
/**
* The name of the entity type.
*
@ -59,41 +52,13 @@ class FieldConfigEditForm extends EntityForm {
*/
protected string $bundle;
/**
* Constructs a new FieldConfigDeleteForm object.
*
* @param \Drupal\Core\Entity\EntityTypeBundleInfoInterface $entity_type_bundle_info
* The entity type bundle info service.
* @param \Drupal\Core\TypedData\TypedDataManagerInterface $typedDataManager
* The type data manger.
* @param \Drupal\Core\Entity\EntityDisplayRepositoryInterface|null $entityDisplayRepository
* The entity display repository.
* @param \Drupal\Core\TempStore\PrivateTempStore|null $tempStore
* The private tempstore.
* @param \Drupal\Core\Render\ElementInfoManagerInterface|null $elementInfo
* The element info manager.
*/
public function __construct(
EntityTypeBundleInfoInterface $entity_type_bundle_info,
protected EntityTypeBundleInfoInterface $entityTypeBundleInfo,
protected TypedDataManagerInterface $typedDataManager,
protected ?EntityDisplayRepositoryInterface $entityDisplayRepository = NULL,
protected ?PrivateTempStore $tempStore = NULL,
protected ?ElementInfoManagerInterface $elementInfo = NULL,
) {
$this->entityTypeBundleInfo = $entity_type_bundle_info;
if ($this->entityDisplayRepository === NULL) {
@trigger_error('Calling FieldConfigEditForm::__construct() without the $entityDisplayRepository argument is deprecated in drupal:10.2.0 and will be required in drupal:11.0.0. See https://www.drupal.org/node/3383771', E_USER_DEPRECATED);
$this->entityDisplayRepository = \Drupal::service('entity_display.repository');
}
if ($this->tempStore === NULL) {
@trigger_error('Calling FieldConfigEditForm::__construct() without the $tempStore argument is deprecated in drupal:10.2.0 and will be required in drupal:11.0.0. See https://www.drupal.org/node/3383771', E_USER_DEPRECATED);
$this->tempStore = \Drupal::service('tempstore.private')->get('field_ui');
}
if ($this->elementInfo === NULL) {
@trigger_error('Calling FieldConfigEditForm::__construct() without the $elementInfo argument is deprecated in drupal:10.2.0 and will be required in drupal:11.0.0. See https://www.drupal.org/node/3383771', E_USER_DEPRECATED);
$this->elementInfo = \Drupal::service('plugin.manager.element_info');
}
}
protected EntityDisplayRepositoryInterface $entityDisplayRepository,
protected PrivateTempStore $tempStore,
protected ElementInfoManagerInterface $elementInfo,
) {}
/**
* {@inheritdoc}

View File

@ -38,63 +38,8 @@ class FieldStorageAddForm extends FormBase {
*/
protected $bundle;
/**
* The entity type manager.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* The entity field manager.
*
* @var \Drupal\Core\Entity\EntityFieldManagerInterface
*/
protected $entityFieldManager;
/**
* The field type plugin manager.
*
* @var \Drupal\Core\Field\FieldTypePluginManagerInterface
*/
protected $fieldTypePluginManager;
/**
* The configuration factory.
*
* @var \Drupal\Core\Config\ConfigFactoryInterface
*/
protected $configFactory;
/**
* Constructs a new FieldStorageAddForm object.
*
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager.
* @param \Drupal\Core\Field\FieldTypePluginManagerInterface $field_type_plugin_manager
* The field type plugin manager.
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* The configuration factory.
* @param \Drupal\Core\Entity\EntityFieldManagerInterface $entity_field_manager
* (optional) The entity field manager.
* @param \Drupal\Core\TempStore\PrivateTempStore|null $tempStore
* The private tempstore.
* @param \Drupal\Core\Field\FieldTypeCategoryManagerInterface|null $fieldTypeCategoryManager
* The field type category plugin manager.
*/
public function __construct(EntityTypeManagerInterface $entity_type_manager, FieldTypePluginManagerInterface $field_type_plugin_manager, ConfigFactoryInterface $config_factory, EntityFieldManagerInterface $entity_field_manager, protected ?PrivateTempStore $tempStore = NULL, protected ?FieldTypeCategoryManagerInterface $fieldTypeCategoryManager = NULL) {
$this->entityTypeManager = $entity_type_manager;
$this->fieldTypePluginManager = $field_type_plugin_manager;
$this->configFactory = $config_factory;
$this->entityFieldManager = $entity_field_manager;
if ($this->tempStore === NULL) {
@trigger_error('Calling FieldStorageAddForm::__construct() without the $tempStore argument is deprecated in drupal:10.2.0 and will be required in drupal:11.0.0. See https://www.drupal.org/node/3383719', E_USER_DEPRECATED);
$this->tempStore = \Drupal::service('tempstore.private')->get('field_ui');
}
if ($this->fieldTypeCategoryManager === NULL) {
@trigger_error('Calling FieldStorageAddForm::__construct() without the $fieldTypeCategoryManager argument is deprecated in drupal:10.2.0 and will be required in drupal:11.0.0. See https://www.drupal.org/node/3375740', E_USER_DEPRECATED);
$this->fieldTypeCategoryManager = \Drupal::service('plugin.manager.field.field_type_category');
}
public function __construct(protected EntityTypeManagerInterface $entityTypeManager, protected FieldTypePluginManagerInterface $fieldTypePluginManager, ConfigFactoryInterface $configFactory, protected EntityFieldManagerInterface $entityFieldManager, protected PrivateTempStore $tempStore, protected FieldTypeCategoryManagerInterface $fieldTypeCategoryManager) {
$this->setConfigFactory($configFactory);
}
/**

View File

@ -6,7 +6,6 @@ use Drupal\Core\Entity\EntityForm;
use Drupal\Core\Entity\Plugin\DataType\EntityAdapter;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Form\SubformStateInterface;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\TypedData\TypedDataManagerInterface;
use Drupal\field\Entity\FieldConfig;
@ -193,14 +192,7 @@ class FieldStorageConfigEditForm extends EntityForm {
* {@inheritdoc}
*/
protected function actions(array $form, FormStateInterface $form_state) {
if ($form_state instanceof SubformStateInterface) {
return [];
}
$elements = parent::actions($form, $form_state);
$elements['submit']['#value'] = $this->entity->isNew() ? $this->t('Continue') : $this->t('Save');
@trigger_error('Rendering ' . __CLASS__ . ' outside of a subform is deprecated in drupal:10.2.0 and is removed in drupal:11.0.0. See https://www.drupal.org/node/3391538', E_USER_DEPRECATED);
return $elements;
return [];
}
/**

View File

@ -324,22 +324,6 @@ class ManageFieldsTest extends BrowserTestBase {
$this->assertEquals([['target_id' => $this->adminUser->id()]], $field->getDefaultValue(User::create(['name' => '1337'])));
}
/**
* Tests hook_form_field_storage_config_form_edit_alter().
*
* @group legacy
*/
public function testFieldStorageFormAlter() {
$this->container->get('module_installer')->install(['field_ui_test_deprecated']);
$this->rebuildContainer();
$node_type = $this->drupalCreateContentType();
$bundle = $node_type->id();
$this->expectDeprecation('The deprecated alter hook hook_form_field_storage_config_edit_form_alter() is implemented in these functions: field_ui_test_deprecated_form_field_storage_config_edit_form_alter. Use hook_form_field_config_edit_form_alter() instead. See https://www.drupal.org/node/3386675.');
$this->drupalGet("/admin/structure/types/manage/$bundle/fields/node.$bundle.body");
$this->assertSession()->elementTextContains('css', '#edit-field-storage', 'Greetings from the field_storage_config_edit_form() alter.');
}
/**
* Tests hook_form_field_storage_config_form_edit_alter().
*